| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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->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->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 net::NetworkChangeNotifier::ConnectionTypeObserver { | 236 public net::NetworkChangeNotifier::ConnectionTypeObserver { |
| 249 public: | 237 public: |
| 250 // |net_log| must remain valid throughout our lifetime. | 238 // |net_log| must remain valid throughout our lifetime. |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 net::ProxyService::CreateDirectWithNetLog(net_log_)); | 457 net::ProxyService::CreateDirectWithNetLog(net_log_)); |
| 470 // In-memory cookie store. | 458 // In-memory cookie store. |
| 471 globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); | 459 globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); |
| 472 // In-memory server bound cert store. | 460 // In-memory server bound cert store. |
| 473 globals_->system_server_bound_cert_service.reset( | 461 globals_->system_server_bound_cert_service.reset( |
| 474 new net::ServerBoundCertService( | 462 new net::ServerBoundCertService( |
| 475 new net::DefaultServerBoundCertStore(NULL), | 463 new net::DefaultServerBoundCertStore(NULL), |
| 476 base::WorkerPool::GetTaskRunner(true))); | 464 base::WorkerPool::GetTaskRunner(true))); |
| 477 globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats()); | 465 globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats()); |
| 478 globals_->host_mapping_rules.reset(new net::HostMappingRules()); | 466 globals_->host_mapping_rules.reset(new net::HostMappingRules()); |
| 467 globals_->http_user_agent_settings.reset( |
| 468 new BasicHttpUserAgentSettings(EmptyString(), EmptyString())); |
| 479 if (command_line.HasSwitch(switches::kHostRules)) { | 469 if (command_line.HasSwitch(switches::kHostRules)) { |
| 480 globals_->host_mapping_rules->SetRulesFromString( | 470 globals_->host_mapping_rules->SetRulesFromString( |
| 481 command_line.GetSwitchValueASCII(switches::kHostRules)); | 471 command_line.GetSwitchValueASCII(switches::kHostRules)); |
| 482 } | 472 } |
| 483 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) | 473 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) |
| 484 globals_->ignore_certificate_errors = true; | 474 globals_->ignore_certificate_errors = true; |
| 485 if (command_line.HasSwitch(switches::kEnableHttpPipelining)) | 475 if (command_line.HasSwitch(switches::kEnableHttpPipelining)) |
| 486 globals_->http_pipelining_enabled = true; | 476 globals_->http_pipelining_enabled = true; |
| 487 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { | 477 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { |
| 488 int value; | 478 int value; |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 new net::HttpNetworkLayer( | 728 new net::HttpNetworkLayer( |
| 739 new net::HttpNetworkSession(system_params))); | 729 new net::HttpNetworkSession(system_params))); |
| 740 globals_->system_ftp_transaction_factory.reset( | 730 globals_->system_ftp_transaction_factory.reset( |
| 741 new net::FtpNetworkLayer(globals_->host_resolver.get())); | 731 new net::FtpNetworkLayer(globals_->host_resolver.get())); |
| 742 globals_->system_request_context.reset( | 732 globals_->system_request_context.reset( |
| 743 ConstructSystemRequestContext(globals_, net_log_)); | 733 ConstructSystemRequestContext(globals_, net_log_)); |
| 744 | 734 |
| 745 sdch_manager_->set_sdch_fetcher( | 735 sdch_manager_->set_sdch_fetcher( |
| 746 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); | 736 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); |
| 747 } | 737 } |
| OLD | NEW |