]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix race condition when initializing request context getter.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 20 Feb 2014 16:56:18 +0000 (00:56 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 20 Feb 2014 16:56:18 +0000 (00:56 +0800)
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.

browser/net/atom_url_request_context_getter.cc
browser/net/atom_url_request_context_getter.h

index 0c5a5c6ec04a6916f3431e47a61f159dcdc8bec7..bdc72028e6e522d6ce0e542a85fdafc1ac96a934 100644 (file)
@@ -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();
index f66be82e399bf4e2834a067503b30825e8bfade7..e2c5f365c2fb2ec13813a28757d014e274799a18 100644 (file)
@@ -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<scoped_ptr<brightray::NetworkDelegate>(void)>
       network_delegate_factory_;
 
+  base::Lock lock_;
+
   scoped_ptr<net::ProxyConfigService> proxy_config_service_;
   scoped_ptr<brightray::NetworkDelegate> network_delegate_;
   scoped_ptr<net::URLRequestContextStorage> storage_;