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

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: lint fixes Created 8 years, 3 months 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/prefs/pref_service.h" 35 #include "chrome/browser/prefs/pref_service.h"
35 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
36 #include "chrome/common/pref_names.h" 37 #include "chrome/common/pref_names.h"
37 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
38 #include "content/public/common/content_client.h" 39 #include "content/public/common/content_client.h"
erikwright (departed) 2012/09/25 21:06:38 no longer required?
39 #include "net/base/cert_verifier.h" 40 #include "net/base/cert_verifier.h"
40 #include "net/base/default_server_bound_cert_store.h" 41 #include "net/base/default_server_bound_cert_store.h"
41 #include "net/base/host_cache.h" 42 #include "net/base/host_cache.h"
42 #include "net/base/host_mapping_rules.h" 43 #include "net/base/host_mapping_rules.h"
43 #include "net/base/host_resolver.h" 44 #include "net/base/host_resolver.h"
44 #include "net/base/mapped_host_resolver.h" 45 #include "net/base/mapped_host_resolver.h"
45 #include "net/base/net_util.h" 46 #include "net/base/net_util.h"
46 #include "net/base/sdch_manager.h" 47 #include "net/base/sdch_manager.h"
47 #include "net/base/server_bound_cert_service.h" 48 #include "net/base/server_bound_cert_service.h"
48 #include "net/cookies/cookie_monster.h" 49 #include "net/cookies/cookie_monster.h"
(...skipping 19 matching lines...) Expand all
68 69
69 using content::BrowserThread; 70 using content::BrowserThread;
70 71
71 class SafeBrowsingURLRequestContext; 72 class SafeBrowsingURLRequestContext;
72 73
73 // The IOThread object must outlive any tasks posted to the IO thread before the 74 // The IOThread object must outlive any tasks posted to the IO thread before the
74 // Quit task, so base::Bind() calls are not refcounted. 75 // Quit task, so base::Bind() calls are not refcounted.
75 76
76 namespace { 77 namespace {
77 78
78 // Custom URLRequestContext used by requests which aren't associated with a
79 // particular profile. We need to use a subclass of URLRequestContext in order
80 // to provide the correct User-Agent.
81 class URLRequestContextWithUserAgent : public net::URLRequestContext {
82 public:
83 virtual const std::string& GetUserAgent(
84 const GURL& url) const OVERRIDE {
85 return content::GetUserAgent(url);
86 }
87
88 protected:
89 virtual ~URLRequestContextWithUserAgent() {}
90 };
91
92 // Used for the "system" URLRequestContext. If this grows more complicated, then 79 // Used for the "system" URLRequestContext. If this grows more complicated, then
erikwright (departed) 2012/09/25 21:06:38 Comment from "If this grows..." is no longer relev
93 // consider inheriting directly from URLRequestContext rather than using 80 // consider inheriting directly from URLRequestContext rather than using
94 // implementation inheritance. 81 // implementation inheritance.
95 class SystemURLRequestContext : public URLRequestContextWithUserAgent { 82 class SystemURLRequestContext : public net::URLRequestContext {
96 public: 83 public:
97 SystemURLRequestContext() { 84 SystemURLRequestContext() {
98 #if defined(USE_NSS) 85 #if defined(USE_NSS)
99 net::SetURLRequestContextForNSSHttpIO(this); 86 net::SetURLRequestContextForNSSHttpIO(this);
100 #endif // defined(USE_NSS) 87 #endif // defined(USE_NSS)
101 } 88 }
102 89
103 private: 90 private:
104 virtual ~SystemURLRequestContext() { 91 virtual ~SystemURLRequestContext() {
105 #if defined(USE_NSS) 92 #if defined(USE_NSS)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); 175 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
189 return remapped_resolver; 176 return remapped_resolver;
190 } 177 }
191 178
192 // TODO(willchan): Remove proxy script fetcher context since it's not necessary 179 // TODO(willchan): Remove proxy script fetcher context since it's not necessary
193 // now that I got rid of refcounting URLRequestContexts. 180 // now that I got rid of refcounting URLRequestContexts.
194 // See IOThread::Globals for details. 181 // See IOThread::Globals for details.
195 net::URLRequestContext* 182 net::URLRequestContext*
196 ConstructProxyScriptFetcherContext(IOThread::Globals* globals, 183 ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
197 net::NetLog* net_log) { 184 net::NetLog* net_log) {
198 net::URLRequestContext* context = new URLRequestContextWithUserAgent; 185 net::URLRequestContext* context = new net::URLRequestContext;
199 context->set_net_log(net_log); 186 context->set_net_log(net_log);
200 context->set_host_resolver(globals->host_resolver.get()); 187 context->set_host_resolver(globals->host_resolver.get());
201 context->set_cert_verifier(globals->cert_verifier.get()); 188 context->set_cert_verifier(globals->cert_verifier.get());
202 context->set_transport_security_state( 189 context->set_transport_security_state(
203 globals->transport_security_state.get()); 190 globals->transport_security_state.get());
204 context->set_http_auth_handler_factory( 191 context->set_http_auth_handler_factory(
205 globals->http_auth_handler_factory.get()); 192 globals->http_auth_handler_factory.get());
206 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); 193 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
207 context->set_http_transaction_factory( 194 context->set_http_transaction_factory(
208 globals->proxy_script_fetcher_http_transaction_factory.get()); 195 globals->proxy_script_fetcher_http_transaction_factory.get());
209 context->set_ftp_transaction_factory( 196 context->set_ftp_transaction_factory(
210 globals->proxy_script_fetcher_ftp_transaction_factory.get()); 197 globals->proxy_script_fetcher_ftp_transaction_factory.get());
211 context->set_cookie_store(globals->system_cookie_store.get()); 198 context->set_cookie_store(globals->system_cookie_store.get());
212 context->set_server_bound_cert_service( 199 context->set_server_bound_cert_service(
213 globals->system_server_bound_cert_service.get()); 200 globals->system_server_bound_cert_service.get());
214 context->set_network_delegate(globals->system_network_delegate.get()); 201 context->set_network_delegate(globals->system_network_delegate.get());
202 context->set_http_user_agent_settings(
203 globals->basic_http_user_agent_settings.get());
215 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the 204 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
216 // system URLRequestContext too. There's no reason this should be tied to a 205 // system URLRequestContext too. There's no reason this should be tied to a
217 // profile. 206 // profile.
218 return context; 207 return context;
219 } 208 }
220 209
221 net::URLRequestContext* 210 net::URLRequestContext*
222 ConstructSystemRequestContext(IOThread::Globals* globals, 211 ConstructSystemRequestContext(IOThread::Globals* globals,
223 net::NetLog* net_log) { 212 net::NetLog* net_log) {
224 net::URLRequestContext* context = new SystemURLRequestContext; 213 net::URLRequestContext* context = new SystemURLRequestContext;
225 context->set_net_log(net_log); 214 context->set_net_log(net_log);
226 context->set_host_resolver(globals->host_resolver.get()); 215 context->set_host_resolver(globals->host_resolver.get());
227 context->set_cert_verifier(globals->cert_verifier.get()); 216 context->set_cert_verifier(globals->cert_verifier.get());
228 context->set_transport_security_state( 217 context->set_transport_security_state(
229 globals->transport_security_state.get()); 218 globals->transport_security_state.get());
230 context->set_http_auth_handler_factory( 219 context->set_http_auth_handler_factory(
231 globals->http_auth_handler_factory.get()); 220 globals->http_auth_handler_factory.get());
232 context->set_proxy_service(globals->system_proxy_service.get()); 221 context->set_proxy_service(globals->system_proxy_service.get());
233 context->set_http_transaction_factory( 222 context->set_http_transaction_factory(
234 globals->system_http_transaction_factory.get()); 223 globals->system_http_transaction_factory.get());
235 context->set_ftp_transaction_factory( 224 context->set_ftp_transaction_factory(
236 globals->system_ftp_transaction_factory.get()); 225 globals->system_ftp_transaction_factory.get());
237 context->set_cookie_store(globals->system_cookie_store.get()); 226 context->set_cookie_store(globals->system_cookie_store.get());
238 context->set_server_bound_cert_service( 227 context->set_server_bound_cert_service(
239 globals->system_server_bound_cert_service.get()); 228 globals->system_server_bound_cert_service.get());
240 context->set_throttler_manager(globals->throttler_manager.get()); 229 context->set_throttler_manager(globals->throttler_manager.get());
241 context->set_network_delegate(globals->system_network_delegate.get()); 230 context->set_network_delegate(globals->system_network_delegate.get());
231 context->set_http_user_agent_settings(
232 globals->basic_http_user_agent_settings.get());
242 return context; 233 return context;
243 } 234 }
244 235
245 } // namespace 236 } // namespace
246 237
247 class IOThread::LoggingNetworkChangeObserver 238 class IOThread::LoggingNetworkChangeObserver
248 : public net::NetworkChangeNotifier::IPAddressObserver { 239 : public net::NetworkChangeNotifier::IPAddressObserver {
249 public: 240 public:
250 // |net_log| must remain valid throughout our lifetime. 241 // |net_log| must remain valid throughout our lifetime.
251 explicit LoggingNetworkChangeObserver(net::NetLog* net_log) 242 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 net::ProxyService::CreateDirectWithNetLog(net_log_)); 442 net::ProxyService::CreateDirectWithNetLog(net_log_));
452 // In-memory cookie store. 443 // In-memory cookie store.
453 globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); 444 globals_->system_cookie_store = new net::CookieMonster(NULL, NULL);
454 // In-memory server bound cert store. 445 // In-memory server bound cert store.
455 globals_->system_server_bound_cert_service.reset( 446 globals_->system_server_bound_cert_service.reset(
456 new net::ServerBoundCertService( 447 new net::ServerBoundCertService(
457 new net::DefaultServerBoundCertStore(NULL), 448 new net::DefaultServerBoundCertStore(NULL),
458 base::WorkerPool::GetTaskRunner(true))); 449 base::WorkerPool::GetTaskRunner(true)));
459 globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats()); 450 globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats());
460 globals_->host_mapping_rules.reset(new net::HostMappingRules()); 451 globals_->host_mapping_rules.reset(new net::HostMappingRules());
452 globals_->basic_http_user_agent_settings.reset(
453 new BasicHttpUserAgentSettings(EmptyString(), EmptyString()));
461 if (command_line.HasSwitch(switches::kHostRules)) { 454 if (command_line.HasSwitch(switches::kHostRules)) {
462 globals_->host_mapping_rules->SetRulesFromString( 455 globals_->host_mapping_rules->SetRulesFromString(
463 command_line.GetSwitchValueASCII(switches::kHostRules)); 456 command_line.GetSwitchValueASCII(switches::kHostRules));
464 } 457 }
465 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) 458 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
466 globals_->ignore_certificate_errors = true; 459 globals_->ignore_certificate_errors = true;
467 if (command_line.HasSwitch(switches::kEnableHttpPipelining)) 460 if (command_line.HasSwitch(switches::kEnableHttpPipelining))
468 globals_->http_pipelining_enabled = true; 461 globals_->http_pipelining_enabled = true;
469 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { 462 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
470 int value; 463 int value;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 new net::HttpNetworkLayer( 688 new net::HttpNetworkLayer(
696 new net::HttpNetworkSession(system_params))); 689 new net::HttpNetworkSession(system_params)));
697 globals_->system_ftp_transaction_factory.reset( 690 globals_->system_ftp_transaction_factory.reset(
698 new net::FtpNetworkLayer(globals_->host_resolver.get())); 691 new net::FtpNetworkLayer(globals_->host_resolver.get()));
699 globals_->system_request_context.reset( 692 globals_->system_request_context.reset(
700 ConstructSystemRequestContext(globals_, net_log_)); 693 ConstructSystemRequestContext(globals_, net_log_));
701 694
702 sdch_manager_->set_sdch_fetcher( 695 sdch_manager_->set_sdch_fetcher(
703 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); 696 new SdchDictionaryFetcher(system_url_request_context_getter_.get()));
704 } 697 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698