From: Cheng Zhao Date: Thu, 20 Feb 2014 16:56:18 +0000 (+0800) Subject: Fix race condition when initializing request context getter. X-Git-Tag: v0.10.0~6^2~7 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=3576c6d2ffa5622d8d596caedd1805582966190a;p=electron.git Fix race condition when initializing request context getter. Note that we are calling GetURLRequestContext() in the UI thread when using the protocol module, this should in fact not be allowed, but for now we just use the workaround of making sure the request context getter has been initialized before we use the protocol module. --- diff --git a/browser/net/atom_url_request_context_getter.cc b/browser/net/atom_url_request_context_getter.cc index 0c5a5c6e..bdc72028 100644 --- a/browser/net/atom_url_request_context_getter.cc +++ b/browser/net/atom_url_request_context_getter.cc @@ -66,6 +66,7 @@ AtomURLRequestContextGetter::~AtomURLRequestContextGetter() { net::URLRequestContext* AtomURLRequestContextGetter::GetURLRequestContext() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + base::AutoLock auto_lock(lock_); if (!url_request_context_.get()) { url_request_context_.reset(new net::URLRequestContext()); network_delegate_ = network_delegate_factory_.Run().Pass(); diff --git a/browser/net/atom_url_request_context_getter.h b/browser/net/atom_url_request_context_getter.h index f66be82e..e2c5f365 100644 --- a/browser/net/atom_url_request_context_getter.h +++ b/browser/net/atom_url_request_context_getter.h @@ -8,6 +8,7 @@ #include "base/callback.h" #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" +#include "base/synchronization/lock.h" #include "content/public/browser/content_browser_client.h" #include "net/url_request/url_request_context_getter.h" @@ -59,6 +60,8 @@ class AtomURLRequestContextGetter : public net::URLRequestContextGetter { base::Callback(void)> network_delegate_factory_; + base::Lock lock_; + scoped_ptr proxy_config_service_; scoped_ptr network_delegate_; scoped_ptr storage_;