]> khamidou — GitHub mirrors - electron.git/commitdiff
get jsprotocolhandler in IO thread
authorRobo <hop2deep@gmail.com>
Wed, 22 Jul 2015 16:24:12 +0000 (21:54 +0530)
committerRobo <hop2deep@gmail.com>
Wed, 22 Jul 2015 16:24:12 +0000 (21:54 +0530)
atom/browser/api/atom_api_protocol.cc
atom/browser/net/adapter_request_job.cc
atom/browser/net/adapter_request_job.h

index d7af58802792b2d26551aa9602f8fa99dcb93da2..53aef95b765780adebc97de13eadb827021f35b0 100644 (file)
@@ -80,16 +80,13 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
         registry_(registry) {
   }
 
-  // AdapterRequestJob:
-  void GetJobTypeInUI() override {
+  void GetJobTypeInUI(const Protocol::JsProtocolHandler& callback) {
     DCHECK_CURRENTLY_ON(BrowserThread::UI);
 
     v8::Locker locker(registry_->isolate());
     v8::HandleScope handle_scope(registry_->isolate());
 
     // Call the JS handler.
-    Protocol::JsProtocolHandler callback =
-        registry_->GetProtocolHandler(request()->url().scheme());
     v8::Local<v8::Value> result = callback.Run(request());
 
     // Determine the type of the job we are going to create.
@@ -172,6 +169,14 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
                    GetWeakPtr(), net::ERR_NOT_IMPLEMENTED));
   }
 
+  // AdapterRequestJob:
+  void GetJobType() override {
+    BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+        base::Bind(&CustomProtocolRequestJob::GetJobTypeInUI,
+                   base::Unretained(this),
+                   registry_->GetProtocolHandler(request()->url().scheme())));
+  }
+
  private:
   Protocol* registry_;  // Weak, the Protocol class is expected to live forever.
 };
index 2be25b65751375a1d8ea6ac952f28e95c272ac5a..5c41c6f65aacfe5020028cfe5a23c71cc92aa689 100644 (file)
@@ -27,11 +27,7 @@ AdapterRequestJob::AdapterRequestJob(ProtocolHandler* protocol_handler,
 
 void AdapterRequestJob::Start() {
   DCHECK(!real_job_.get());
-  content::BrowserThread::PostTask(
-      content::BrowserThread::UI,
-      FROM_HERE,
-      base::Bind(&AdapterRequestJob::GetJobTypeInUI,
-                 weak_factory_.GetWeakPtr()));
+  GetJobType();
 }
 
 void AdapterRequestJob::Kill() {
index bca549a2eef2a22be977b32338d842cd637ec9bb..b1d28b1446c18038effd5d46514bd6c85379c53e 100644 (file)
@@ -54,7 +54,7 @@ class AdapterRequestJob : public net::URLRequestJob {
   ProtocolHandler* default_protocol_handler() { return protocol_handler_; }
 
   // Override this function to determine which job should be started.
-  virtual void GetJobTypeInUI() = 0;
+  virtual void GetJobType() = 0;
 
   void CreateErrorJobAndStart(int error_code);
   void CreateStringJobAndStart(const std::string& mime_type,