Initialize job factory as early as possible.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 15 Aug 2014 03:35:13 +0000 (11:35 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 15 Aug 2014 03:35:13 +0000 (11:35 +0800)
Fixes atom/atom#3255.

atom/browser/api/atom_api_protocol.cc
atom/browser/atom_browser_context.cc

index 9f29ecb..0cace29 100644 (file)
@@ -4,7 +4,6 @@
 
 #include "atom/browser/api/atom_api_protocol.h"
 
-#include "base/stl_util.h"
 #include "atom/browser/atom_browser_context.h"
 #include "atom/browser/net/adapter_request_job.h"
 #include "atom/browser/net/atom_url_request_job_factory.h"
@@ -153,6 +152,7 @@ class CustomProtocolHandler : public ProtocolHandler {
 
 Protocol::Protocol()
     : job_factory_(AtomBrowserContext::Get()->job_factory()) {
+  CHECK(job_factory_);
 }
 
 Protocol::JsProtocolHandler Protocol::GetProtocolHandler(
@@ -323,10 +323,6 @@ namespace {
 
 void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
                 v8::Handle<v8::Context> context, void* priv) {
-  // Make sure the job factory has been created.
-  atom::AtomBrowserContext::Get()->url_request_context_getter()->
-      GetURLRequestContext();
-
   v8::Isolate* isolate = context->GetIsolate();
   mate::Dictionary dict(isolate, exports);
   dict.Set("protocol", atom::api::Protocol::Create(isolate));
index 295bfa4..0fcdbad 100644 (file)
@@ -19,7 +19,7 @@ using content::BrowserThread;
 namespace atom {
 
 AtomBrowserContext::AtomBrowserContext()
-    : job_factory_(NULL) {
+    : job_factory_(new AtomURLRequestJobFactory) {
 }
 
 AtomBrowserContext::~AtomBrowserContext() {
@@ -29,7 +29,6 @@ scoped_ptr<net::URLRequestJobFactory>
 AtomBrowserContext::CreateURLRequestJobFactory(
     content::ProtocolHandlerMap* handlers,
     content::ProtocolHandlerScopedVector* interceptors) {
-  job_factory_ = new AtomURLRequestJobFactory;
   scoped_ptr<AtomURLRequestJobFactory> job_factory(job_factory_);
 
   for (content::ProtocolHandlerMap::iterator it = handlers->begin();