Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: chrome/browser/io_thread.cc

Issue 10918279: Provide mutable members of UrlRequestContext via pure-virtual interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add TODO Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/io_thread.h" 5 #include "chrome/browser/io_thread.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/debug/leak_tracker.h" 13 #include "base/debug/leak_tracker.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/string_split.h" 17 #include "base/string_split.h"
18 #include "base/string_util.h" 18 #include "base/string_util.h"
19 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
20 #include "base/threading/worker_pool.h" 20 #include "base/threading/worker_pool.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/extensions/event_router_forwarder.h" 23 #include "chrome/browser/extensions/event_router_forwarder.h"
24 #include "chrome/browser/net/async_dns_field_trial.h" 24 #include "chrome/browser/net/async_dns_field_trial.h"
25 #include "chrome/browser/net/basic_http_user_agent_settings.h"
25 #include "chrome/browser/net/chrome_net_log.h" 26 #include "chrome/browser/net/chrome_net_log.h"
26 #include "chrome/browser/net/chrome_network_delegate.h" 27 #include "chrome/browser/net/chrome_network_delegate.h"
27 #include "chrome/browser/net/chrome_url_request_context.h" 28 #include "chrome/browser/net/chrome_url_request_context.h"
28 #include "chrome/browser/net/connect_interceptor.h" 29 #include "chrome/browser/net/connect_interceptor.h"
29 #include "chrome/browser/net/http_pipelining_compatibility_client.h" 30 #include "chrome/browser/net/http_pipelining_compatibility_client.h"
30 #include "chrome/browser/net/load_time_stats.h" 31 #include "chrome/browser/net/load_time_stats.h"
31 #include "chrome/browser/net/pref_proxy_config_tracker.h" 32 #include "chrome/browser/net/pref_proxy_config_tracker.h"
32 #include "chrome/browser/net/proxy_service_factory.h" 33 #include "chrome/browser/net/proxy_service_factory.h"
33 #include "chrome/browser/net/sdch_dictionary_fetcher.h" 34 #include "chrome/browser/net/sdch_dictionary_fetcher.h"
34 #include "chrome/browser/net/spdyproxy/http_auth_handler_spdyproxy.h" 35 #include "chrome/browser/net/spdyproxy/http_auth_handler_spdyproxy.h"
35 #include "chrome/browser/prefs/pref_service.h" 36 #include "chrome/browser/prefs/pref_service.h"
36 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
37 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
38 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
39 #include "content/public/common/content_client.h"
40 #include "net/base/cert_verifier.h" 40 #include "net/base/cert_verifier.h"
41 #include "net/base/default_server_bound_cert_store.h" 41 #include "net/base/default_server_bound_cert_store.h"
42 #include "net/base/host_cache.h" 42 #include "net/base/host_cache.h"
43 #include "net/base/host_mapping_rules.h" 43 #include "net/base/host_mapping_rules.h"
44 #include "net/base/host_resolver.h" 44 #include "net/base/host_resolver.h"
45 #include "net/base/mapped_host_resolver.h" 45 #include "net/base/mapped_host_resolver.h"
46 #include "net/base/net_util.h" 46 #include "net/base/net_util.h"
47 #include "net/base/sdch_manager.h" 47 #include "net/base/sdch_manager.h"
48 #include "net/base/server_bound_cert_service.h" 48 #include "net/base/server_bound_cert_service.h"
49 #include "net/cookies/cookie_monster.h" 49 #include "net/cookies/cookie_monster.h"
(...skipping 26 matching lines...) Expand all
76 76
77 namespace { 77 namespace {
78 78
79 #if defined(OS_MACOSX) && !defined(OS_IOS) 79 #if defined(OS_MACOSX) && !defined(OS_IOS)
80 void ObserveKeychainEvents() { 80 void ObserveKeychainEvents() {
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
82 net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents(); 82 net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents();
83 } 83 }
84 #endif 84 #endif
85 85
86 // Custom URLRequestContext used by requests which aren't associated with a 86 // Used for the "system" URLRequestContext.
87 // particular profile. We need to use a subclass of URLRequestContext in order 87 class SystemURLRequestContext : public net::URLRequestContext {
88 // to provide the correct User-Agent.
89 class URLRequestContextWithUserAgent : public net::URLRequestContext {
90 public:
91 virtual const std::string& GetUserAgent(
92 const GURL& url) const OVERRIDE {
93 return content::GetUserAgent(url);
94 }
95
96 protected:
97 virtual ~URLRequestContextWithUserAgent() {}
98 };
99
100 // Used for the "system" URLRequestContext. If this grows more complicated, then
101 // consider inheriting directly from URLRequestContext rather than using
102 // implementation inheritance.
103 class SystemURLRequestContext : public URLRequestContextWithUserAgent {
104 public: 88 public:
105 SystemURLRequestContext() { 89 SystemURLRequestContext() {
106 #if defined(USE_NSS) 90 #if defined(USE_NSS)
107 net::SetURLRequestContextForNSSHttpIO(this); 91 net::SetURLRequestContextForNSSHttpIO(this);
108 #endif // defined(USE_NSS) 92 #endif // defined(USE_NSS)
109 } 93 }
110 94
111 private: 95 private:
112 virtual ~SystemURLRequestContext() { 96 virtual ~SystemURLRequestContext() {
113 #if defined(USE_NSS) 97 #if defined(USE_NSS)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); 171 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
188 return remapped_resolver.PassAs<net::HostResolver>(); 172 return remapped_resolver.PassAs<net::HostResolver>();
189 } 173 }
190 174
191 // TODO(willchan): Remove proxy script fetcher context since it's not necessary 175 // TODO(willchan): Remove proxy script fetcher context since it's not necessary
192 // now that I got rid of refcounting URLRequestContexts. 176 // now that I got rid of refcounting URLRequestContexts.
193 // See IOThread::Globals for details. 177 // See IOThread::Globals for details.
194 net::URLRequestContext* 178 net::URLRequestContext*
195 ConstructProxyScriptFetcherContext(IOThread::Globals* globals, 179 ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
196 net::NetLog* net_log) { 180 net::NetLog* net_log) {
197 net::URLRequestContext* context = new URLRequestContextWithUserAgent; 181 net::URLRequestContext* context = new net::URLRequestContext;
198 context->set_net_log(net_log); 182 context->set_net_log(net_log);
199 context->set_host_resolver(globals->host_resolver.get()); 183 context->set_host_resolver(globals->host_resolver.get());
200 context->set_cert_verifier(globals->cert_verifier.get()); 184 context->set_cert_verifier(globals->cert_verifier.get());
201 context->set_transport_security_state( 185 context->set_transport_security_state(
202 globals->transport_security_state.get()); 186 globals->transport_security_state.get());
203 context->set_http_auth_handler_factory( 187 context->set_http_auth_handler_factory(
204 globals->http_auth_handler_factory.get()); 188 globals->http_auth_handler_factory.get());
205 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); 189 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
206 context->set_http_transaction_factory( 190 context->set_http_transaction_factory(
207 globals->proxy_script_fetcher_http_transaction_factory.get()); 191 globals->proxy_script_fetcher_http_transaction_factory.get());
208 context->set_ftp_transaction_factory( 192 context->set_ftp_transaction_factory(
209 globals->proxy_script_fetcher_ftp_transaction_factory.get()); 193 globals->proxy_script_fetcher_ftp_transaction_factory.get());
210 context->set_cookie_store(globals->system_cookie_store.get()); 194 context->set_cookie_store(globals->system_cookie_store.get());
211 context->set_server_bound_cert_service( 195 context->set_server_bound_cert_service(
212 globals->system_server_bound_cert_service.get()); 196 globals->system_server_bound_cert_service.get());
213 context->set_network_delegate(globals->system_network_delegate.get()); 197 context->set_network_delegate(globals->system_network_delegate.get());
198 context->set_http_user_agent_settings(
199 globals->basic_http_user_agent_settings.get());
214 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the 200 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
215 // system URLRequestContext too. There's no reason this should be tied to a 201 // system URLRequestContext too. There's no reason this should be tied to a
216 // profile. 202 // profile.
217 return context; 203 return context;
218 } 204 }
219 205
220 net::URLRequestContext* 206 net::URLRequestContext*
221 ConstructSystemRequestContext(IOThread::Globals* globals, 207 ConstructSystemRequestContext(IOThread::Globals* globals,
222 net::NetLog* net_log) { 208 net::NetLog* net_log) {
223 net::URLRequestContext* context = new SystemURLRequestContext; 209 net::URLRequestContext* context = new SystemURLRequestContext;
224 context->set_net_log(net_log); 210 context->set_net_log(net_log);
225 context->set_host_resolver(globals->host_resolver.get()); 211 context->set_host_resolver(globals->host_resolver.get());
226 context->set_cert_verifier(globals->cert_verifier.get()); 212 context->set_cert_verifier(globals->cert_verifier.get());
227 context->set_transport_security_state( 213 context->set_transport_security_state(
228 globals->transport_security_state.get()); 214 globals->transport_security_state.get());
229 context->set_http_auth_handler_factory( 215 context->set_http_auth_handler_factory(
230 globals->http_auth_handler_factory.get()); 216 globals->http_auth_handler_factory.get());
231 context->set_proxy_service(globals->system_proxy_service.get()); 217 context->set_proxy_service(globals->system_proxy_service.get());
232 context->set_http_transaction_factory( 218 context->set_http_transaction_factory(
233 globals->system_http_transaction_factory.get()); 219 globals->system_http_transaction_factory.get());
234 context->set_ftp_transaction_factory( 220 context->set_ftp_transaction_factory(
235 globals->system_ftp_transaction_factory.get()); 221 globals->system_ftp_transaction_factory.get());
236 context->set_cookie_store(globals->system_cookie_store.get()); 222 context->set_cookie_store(globals->system_cookie_store.get());
237 context->set_server_bound_cert_service( 223 context->set_server_bound_cert_service(
238 globals->system_server_bound_cert_service.get()); 224 globals->system_server_bound_cert_service.get());
239 context->set_throttler_manager(globals->throttler_manager.get()); 225 context->set_throttler_manager(globals->throttler_manager.get());
240 context->set_network_delegate(globals->system_network_delegate.get()); 226 context->set_network_delegate(globals->system_network_delegate.get());
227 context->set_http_user_agent_settings(
228 globals->basic_http_user_agent_settings.get());
241 return context; 229 return context;
242 } 230 }
243 231
244 } // namespace 232 } // namespace
245 233
246 class IOThread::LoggingNetworkChangeObserver 234 class IOThread::LoggingNetworkChangeObserver
247 : public net::NetworkChangeNotifier::IPAddressObserver { 235 : public net::NetworkChangeNotifier::IPAddressObserver {
248 public: 236 public:
249 // |net_log| must remain valid throughout our lifetime. 237 // |net_log| must remain valid throughout our lifetime.
250 explicit LoggingNetworkChangeObserver(net::NetLog* net_log) 238 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 net::ProxyService::CreateDirectWithNetLog(net_log_)); 441 net::ProxyService::CreateDirectWithNetLog(net_log_));
454 // In-memory cookie store. 442 // In-memory cookie store.
455 globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); 443 globals_->system_cookie_store = new net::CookieMonster(NULL, NULL);
456 // In-memory server bound cert store. 444 // In-memory server bound cert store.
457 globals_->system_server_bound_cert_service.reset( 445 globals_->system_server_bound_cert_service.reset(
458 new net::ServerBoundCertService( 446 new net::ServerBoundCertService(
459 new net::DefaultServerBoundCertStore(NULL), 447 new net::DefaultServerBoundCertStore(NULL),
460 base::WorkerPool::GetTaskRunner(true))); 448 base::WorkerPool::GetTaskRunner(true)));
461 globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats()); 449 globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats());
462 globals_->host_mapping_rules.reset(new net::HostMappingRules()); 450 globals_->host_mapping_rules.reset(new net::HostMappingRules());
451 globals_->basic_http_user_agent_settings.reset(
452 new BasicHttpUserAgentSettings(EmptyString(), EmptyString()));
463 if (command_line.HasSwitch(switches::kHostRules)) { 453 if (command_line.HasSwitch(switches::kHostRules)) {
464 globals_->host_mapping_rules->SetRulesFromString( 454 globals_->host_mapping_rules->SetRulesFromString(
465 command_line.GetSwitchValueASCII(switches::kHostRules)); 455 command_line.GetSwitchValueASCII(switches::kHostRules));
466 } 456 }
467 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) 457 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
468 globals_->ignore_certificate_errors = true; 458 globals_->ignore_certificate_errors = true;
469 if (command_line.HasSwitch(switches::kEnableHttpPipelining)) 459 if (command_line.HasSwitch(switches::kEnableHttpPipelining))
470 globals_->http_pipelining_enabled = true; 460 globals_->http_pipelining_enabled = true;
471 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { 461 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
472 int value; 462 int value;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 new net::HttpNetworkLayer( 710 new net::HttpNetworkLayer(
721 new net::HttpNetworkSession(system_params))); 711 new net::HttpNetworkSession(system_params)));
722 globals_->system_ftp_transaction_factory.reset( 712 globals_->system_ftp_transaction_factory.reset(
723 new net::FtpNetworkLayer(globals_->host_resolver.get())); 713 new net::FtpNetworkLayer(globals_->host_resolver.get()));
724 globals_->system_request_context.reset( 714 globals_->system_request_context.reset(
725 ConstructSystemRequestContext(globals_, net_log_)); 715 ConstructSystemRequestContext(globals_, net_log_));
726 716
727 sdch_manager_->set_sdch_fetcher( 717 sdch_manager_->set_sdch_fetcher(
728 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); 718 new SdchDictionaryFetcher(system_url_request_context_getter_.get()));
729 } 719 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698