From 3576c6d2ffa5622d8d596caedd1805582966190a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 21 Feb 2014 00:56:18 +0800 Subject: [PATCH] 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. --- browser/net/atom_url_request_context_getter.cc | 1 + browser/net/atom_url_request_context_getter.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/browser/net/atom_url_request_context_getter.cc b/browser/net/atom_url_request_context_getter.cc index 0c5a5c6ec04..bdc72028e6e 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 f66be82e399..e2c5f365c2f 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_;