Index: chrome/browser/io_thread.cc |
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc |
index c6b8c7b97efbda9f416161587ae26cd3ca8919c4..cc14a03303d9ea86d3676ef722dcabd90ef6fd1d 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" |
@@ -35,6 +36,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" |
@@ -195,8 +197,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); |
@@ -243,6 +301,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, |
@@ -294,6 +358,16 @@ void IOThread::ChangedToOnTheRecord() { |
&IOThread::ChangedToOnTheRecordOnIOThread)); |
} |
+scoped_refptr<URLRequestContextGetter> |
+IOThread::system_url_request_context_getter() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
willchan no longer on Chromium
2011/02/16 20:02:27
Add a assertion that system_proxy_config_service_
battre
2011/02/21 17:27:57
Done.
|
+ if (!system_url_request_context_getter_) { |
+ 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. |
@@ -380,6 +454,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. |
@@ -406,6 +482,8 @@ void IOThread::CleanUp() { |
globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); |
} |
+ system_proxy_config_service_.reset(); |
+ |
delete globals_; |
globals_ = NULL; |
@@ -423,6 +501,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 |
@@ -518,3 +598,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_); |
+} |