From dcaaeacfe385b3fce0c7a37413b19cc98feea5ab Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 23 Aug 2013 08:19:37 -0400 Subject: [PATCH] Fix assertions in Debug builds about using NetworkDelegate on the wrong thread We have to create it on the IO thread. --- brightray/browser/browser_context.cc | 2 +- brightray/browser/url_request_context_getter.cc | 5 +++-- brightray/browser/url_request_context_getter.h | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 20b70470552..230a8243386 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -106,7 +106,7 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( GetPath(), io_loop, file_loop, - CreateNetworkDelegate().Pass(), + base::Bind(&BrowserContext::CreateNetworkDelegate, base::Unretained(this)), protocol_handlers); resource_context_->set_url_request_context_getter(url_request_getter_.get()); return url_request_getter_.get(); diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index b5596b8e05a..4324a931165 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -40,12 +40,12 @@ URLRequestContextGetter::URLRequestContextGetter( const base::FilePath& base_path, base::MessageLoop* io_loop, base::MessageLoop* file_loop, - scoped_ptr network_delegate, + base::Callback(void)> network_delegate_factory, content::ProtocolHandlerMap* protocol_handlers) : base_path_(base_path), io_loop_(io_loop), file_loop_(file_loop), - network_delegate_(network_delegate.Pass()) { + network_delegate_factory_(network_delegate_factory) { // Must first be created on the UI thread. DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); @@ -67,6 +67,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { if (!url_request_context_.get()) { url_request_context_.reset(new net::URLRequestContext()); + network_delegate_ = network_delegate_factory_.Run().Pass(); url_request_context_->set_network_delegate(network_delegate_.get()); storage_.reset( new net::URLRequestContextStorage(url_request_context_.get())); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index c9700250aad..7d3e174cd40 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -5,6 +5,7 @@ #ifndef BRIGHTRAY_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_ #define BRIGHTRAY_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_ +#include "base/callback.h" #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/content_browser_client.h" @@ -30,7 +31,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { const base::FilePath& base_path, base::MessageLoop* io_loop, base::MessageLoop* file_loop, - scoped_ptr, + base::Callback(void)>, content::ProtocolHandlerMap*); virtual ~URLRequestContextGetter(); @@ -45,6 +46,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { base::MessageLoop* io_loop_; base::MessageLoop* file_loop_; + base::Callback(void)> network_delegate_factory_; + scoped_ptr proxy_config_service_; scoped_ptr network_delegate_; scoped_ptr storage_;