| Index: chrome/browser/io_thread.cc
|
| diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
|
| index 16eec12acf16f964ed46ef42437dda50c64e1be5..756f59befc791a19a122a7110cff5fb1a5e9b8dd 100644
|
| --- a/chrome/browser/io_thread.cc
|
| +++ b/chrome/browser/io_thread.cc
|
| @@ -23,6 +23,7 @@
|
| #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/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"
|
| @@ -36,6 +37,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"
|
| @@ -196,8 +198,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);
|
| @@ -244,6 +302,12 @@ ChromeNetLog* IOThread::net_log() {
|
| return net_log_;
|
| }
|
|
|
| +void IOThread::SetSystemProxyConfigService(
|
| + net::ProxyConfigService* system_proxy_config_service) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + system_proxy_config_service_.reset(system_proxy_config_service);
|
| +}
|
| +
|
| void IOThread::InitNetworkPredictor(
|
| bool prefetching_enabled,
|
| base::TimeDelta max_dns_queue_delay,
|
| @@ -295,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_) {
|
| + // We DCHECK only the first time this function is called as the
|
| + // SystemURLRequestContextGetter will consume the stored value and reset
|
| + // the pointer to NULL.
|
| + DCHECK(system_proxy_config_service_.get());
|
| + system_url_request_context_getter_ =
|
| + new SystemURLRequestContextGetter(this);
|
| + }
|
| + return system_url_request_context_getter_;
|
| +}
|
| +
|
| void IOThread::Init() {
|
| // Though this thread is called the "IO" thread, it actually just routes
|
| // messages around; it shouldn't be allowed to perform any blocking disk I/O.
|
| @@ -381,6 +459,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.
|
|
|
| @@ -407,6 +487,8 @@ void IOThread::CleanUp() {
|
| globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown();
|
| }
|
|
|
| + system_proxy_config_service_.reset();
|
| +
|
| delete globals_;
|
| globals_ = NULL;
|
|
|
| @@ -424,6 +506,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
|
| @@ -519,3 +603,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_);
|
| +}
|
|
|