Chromium Code Reviews| Index: chrome/browser/io_thread.cc |
| diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc |
| index 2a854b89d9e15bd05265b73f35d250107a327ecd..93c87f6aef6035085c3b7d52c23241cf4b9eabc7 100644 |
| --- a/chrome/browser/io_thread.cc |
| +++ b/chrome/browser/io_thread.cc |
| @@ -24,6 +24,8 @@ |
| #include "chrome/browser/net/connect_interceptor.h" |
| #include "chrome/browser/net/passive_log_collector.h" |
| #include "chrome/browser/net/predictor_api.h" |
| +#include "chrome/browser/net/pref_proxy_config_service.h" |
| +#include "chrome/browser/net/proxy_service_factory.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/net/raw_host_resolver_proc.h" |
| @@ -37,6 +39,7 @@ |
| #include "net/base/host_resolver_impl.h" |
| #include "net/base/mapped_host_resolver.h" |
| #include "net/base/net_util.h" |
| +#include "net/proxy/proxy_config_service.h" |
| #include "net/http/http_auth_filter.h" |
| #include "net/http/http_auth_handler_factory.h" |
| #include "net/http/http_network_layer.h" |
| @@ -197,8 +200,64 @@ ConstructProxyScriptFetcherContext(IOThread::Globals* globals, |
| return context; |
| } |
| +scoped_refptr<net::URLRequestContext> |
| +ConstructSystemRequestContext(IOThread::Globals* globals, |
| + net::NetLog* net_log) { |
| + scoped_refptr<net::URLRequestContext> context(new net::URLRequestContext); |
| + context->set_net_log(net_log); |
| + context->set_host_resolver(globals->host_resolver.get()); |
| + context->set_cert_verifier(globals->cert_verifier.get()); |
| + context->set_dnsrr_resolver(globals->dnsrr_resolver.get()); |
| + context->set_http_auth_handler_factory( |
| + globals->http_auth_handler_factory.get()); |
| + context->set_proxy_service(globals->system_proxy_service.get()); |
| + context->set_http_transaction_factory( |
| + globals->system_http_transaction_factory.get()); |
| + // In-memory cookie store. |
| + context->set_cookie_store(new net::CookieMonster(NULL, NULL)); |
| + return context; |
| +} |
| + |
| } // namespace |
| +class SystemURLRequestContextGetter : public URLRequestContextGetter { |
| + public: |
| + explicit SystemURLRequestContextGetter(IOThread* io_thread); |
| + virtual ~SystemURLRequestContextGetter(); |
| + |
| + // Implementation for UrlRequestContextGetter. |
| + virtual net::URLRequestContext* GetURLRequestContext(); |
| + virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const; |
| + |
| + private: |
| + IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. |
| + scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
| + |
| + base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; |
| +}; |
| + |
| +SystemURLRequestContextGetter::SystemURLRequestContextGetter( |
| + IOThread* io_thread) |
| + : io_thread_(io_thread), |
| + io_message_loop_proxy_(io_thread->message_loop_proxy()) { |
| +} |
| + |
| +SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} |
| + |
| +net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + |
| + if (!io_thread_->globals()->system_request_context) |
| + io_thread_->InitSystemRequestContext(); |
| + |
| + return io_thread_->globals()->system_request_context; |
| +} |
| + |
| +scoped_refptr<base::MessageLoopProxy> |
| +SystemURLRequestContextGetter::GetIOMessageLoopProxy() const { |
| + return io_message_loop_proxy_; |
| +} |
| + |
| // The IOThread object must outlive any tasks posted to the IO thread before the |
| // Quit task. |
| DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); |
| @@ -214,7 +273,9 @@ IOThread::IOThread(PrefService* local_state, ChromeNetLog* net_log) |
| net_log_(net_log), |
| globals_(NULL), |
| speculative_interceptor_(NULL), |
| - predictor_(NULL) { |
| + predictor_(NULL), |
| + pref_proxy_config_tracker_(NULL), |
| + local_state_(local_state) { |
| // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make |
| // sure that everything is initialized in the right order. |
| RegisterPrefs(local_state); |
| @@ -230,6 +291,8 @@ IOThread::IOThread(PrefService* local_state, ChromeNetLog* net_log) |
| } |
| IOThread::~IOThread() { |
| + if (pref_proxy_config_tracker_) |
| + pref_proxy_config_tracker_->DetachFromPrefService(); |
| // We cannot rely on our base class to stop the thread since we want our |
| // CleanUp function to run. |
| Stop(); |
| @@ -296,6 +359,20 @@ void IOThread::ChangedToOnTheRecord() { |
| &IOThread::ChangedToOnTheRecordOnIOThread)); |
| } |
| +scoped_refptr<URLRequestContextGetter> |
| +IOThread::system_url_request_context_getter() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + if (!system_url_request_context_getter_) { |
| + pref_proxy_config_tracker_ = new PrefProxyConfigTracker(local_state_); |
|
Mattias Nissler (ping if slow)
2011/02/22 09:58:05
why don't you just construct the PrefProxyConfigTr
battre
2011/03/08 17:38:58
The idea was to have true lazy initialization but
|
| + system_proxy_config_service_.reset( |
| + ProxyServiceFactory::CreateProxyConfigService( |
| + pref_proxy_config_tracker_)); |
| + system_url_request_context_getter_ = |
| + new SystemURLRequestContextGetter(this); |
| + } |
| + return system_url_request_context_getter_; |
| +} |
| + |
| void IOThread::ClearNetworkingHistory() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| ClearHostCache(); |
| @@ -391,6 +468,8 @@ void IOThread::CleanUp() { |
| getter->ReleaseURLRequestContext(); |
| } |
| + system_url_request_context_getter_ = NULL; |
| + |
| // Step 2: Release objects that the net::URLRequestContext could have been |
| // pointing to. |
| @@ -417,6 +496,8 @@ void IOThread::CleanUp() { |
| globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); |
| } |
| + system_proxy_config_service_.reset(); |
| + |
| delete globals_; |
| globals_ = NULL; |
| @@ -434,6 +515,8 @@ void IOThread::CleanUpAfterMessageLoopDestruction() { |
| // MessageLoop::DestructionObserver this check has to happen after CleanUp |
| // (which runs before DestructionObservers). |
| base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); |
| + |
| + base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
| } |
| // static |
| @@ -530,3 +613,34 @@ void IOThread::ClearHostCache() { |
| host_cache->clear(); |
| } |
| } |
| + |
| +void IOThread::InitSystemRequestContext() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + DCHECK(!globals_->system_proxy_service); |
| + DCHECK(system_proxy_config_service_.get()); |
| + |
| + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| + globals_->system_proxy_service = |
| + ProxyServiceFactory::CreateProxyService( |
| + net_log_, |
| + globals_->proxy_script_fetcher_context, |
| + system_proxy_config_service_.release(), |
| + command_line); |
| + net::HttpNetworkSession::Params system_params; |
| + system_params.host_resolver = globals_->host_resolver.get(); |
| + system_params.cert_verifier = globals_->cert_verifier.get(); |
| + system_params.dnsrr_resolver = globals_->dnsrr_resolver.get(); |
| + system_params.dns_cert_checker = NULL; |
| + system_params.ssl_host_info_factory = NULL; |
| + system_params.proxy_service = globals_->system_proxy_service.get(); |
| + system_params.ssl_config_service = globals_->ssl_config_service.get(); |
| + system_params.http_auth_handler_factory = |
| + globals_->http_auth_handler_factory.get(); |
| + system_params.network_delegate = &globals_->network_delegate; |
| + system_params.net_log = net_log_; |
| + globals_->system_http_transaction_factory.reset( |
| + new net::HttpNetworkLayer( |
| + new net::HttpNetworkSession(system_params))); |
| + globals_->system_request_context = |
| + ConstructSystemRequestContext(globals_, net_log_); |
| +} |