Chromium Code Reviews| 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" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 } | 109 } |
| 110 | 110 |
| 111 private: | 111 private: |
| 112 virtual ~SystemURLRequestContext() { | 112 virtual ~SystemURLRequestContext() { |
| 113 #if defined(USE_NSS) | 113 #if defined(USE_NSS) |
| 114 net::SetURLRequestContextForNSSHttpIO(NULL); | 114 net::SetURLRequestContextForNSSHttpIO(NULL); |
| 115 #endif // defined(USE_NSS) | 115 #endif // defined(USE_NSS) |
| 116 } | 116 } |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { | 119 scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) { |
| 120 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 120 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 121 | 121 |
| 122 bool allow_async_dns_field_trial = true; | 122 bool allow_async_dns_field_trial = true; |
| 123 | 123 |
| 124 size_t parallelism = net::HostResolver::kDefaultParallelism; | 124 net::HostResolver::Options options; |
| 125 options.enable_caching = true; | |
| 126 options.max_concurrent_resolves = net::HostResolver::kDefaultParallelism; | |
|
darin (slow to review)
2012/10/22 17:27:17
nit: Shouldn't the Options struct have a construct
szym
2012/10/22 17:48:43
It already does have a default constructor which d
| |
| 125 | 127 |
| 126 // Use the concurrency override from the command-line, if any. | 128 // Use the concurrency override from the command-line, if any. |
| 127 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { | 129 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { |
| 128 allow_async_dns_field_trial = false; | 130 allow_async_dns_field_trial = false; |
| 129 std::string s = | 131 std::string s = |
| 130 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); | 132 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); |
| 131 | 133 |
| 132 // Parse the switch (it should be a positive integer formatted as decimal). | 134 // Parse the switch (it should be a positive integer formatted as decimal). |
| 133 int n; | 135 int n; |
| 134 if (base::StringToInt(s, &n) && n > 0) { | 136 if (base::StringToInt(s, &n) && n > 0) { |
| 135 parallelism = static_cast<size_t>(n); | 137 options.max_concurrent_resolves = static_cast<size_t>(n); |
| 136 } else { | 138 } else { |
| 137 LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s; | 139 LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s; |
| 138 } | 140 } |
| 139 } | 141 } |
| 140 | 142 |
| 141 size_t retry_attempts = net::HostResolver::kDefaultRetryAttempts; | 143 options.max_retry_attempts = net::HostResolver::kDefaultRetryAttempts; |
|
darin (slow to review)
2012/10/22 17:27:17
ditto. seems like Options constructor should init
| |
| 142 | 144 |
| 143 // Use the retry attempts override from the command-line, if any. | 145 // Use the retry attempts override from the command-line, if any. |
| 144 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) { | 146 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) { |
| 145 allow_async_dns_field_trial = false; | 147 allow_async_dns_field_trial = false; |
| 146 std::string s = | 148 std::string s = |
| 147 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts); | 149 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts); |
| 148 // Parse the switch (it should be a non-negative integer). | 150 // Parse the switch (it should be a non-negative integer). |
| 149 int n; | 151 int n; |
| 150 if (base::StringToInt(s, &n) && n >= 0) { | 152 if (base::StringToInt(s, &n) && n >= 0) { |
| 151 retry_attempts = static_cast<size_t>(n); | 153 options.max_retry_attempts = static_cast<size_t>(n); |
| 152 } else { | 154 } else { |
| 153 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; | 155 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; |
| 154 } | 156 } |
| 155 } | 157 } |
| 156 | 158 |
| 157 net::HostResolver* global_host_resolver = NULL; | 159 options.enable_async = false; |
| 158 bool use_async = false; | |
| 159 if (command_line.HasSwitch(switches::kEnableAsyncDns)) { | 160 if (command_line.HasSwitch(switches::kEnableAsyncDns)) { |
| 160 allow_async_dns_field_trial = false; | 161 allow_async_dns_field_trial = false; |
| 161 use_async = true; | 162 options.enable_async = true; |
| 162 } else if (command_line.HasSwitch(switches::kDisableAsyncDns)) { | 163 } else if (command_line.HasSwitch(switches::kDisableAsyncDns)) { |
| 163 allow_async_dns_field_trial = false; | 164 allow_async_dns_field_trial = false; |
| 164 use_async = false; | 165 options.enable_async = false; |
| 165 } | 166 } |
| 166 | 167 |
| 167 if (allow_async_dns_field_trial) | 168 if (allow_async_dns_field_trial) |
| 168 use_async = chrome_browser_net::ConfigureAsyncDnsFieldTrial(); | 169 options.enable_async = chrome_browser_net::ConfigureAsyncDnsFieldTrial(); |
| 169 | 170 |
| 170 if (use_async) { | 171 scoped_ptr<net::HostResolver> global_host_resolver( |
| 171 global_host_resolver = | 172 net::HostResolver::CreateSystemResolver(options, net_log)); |
| 172 net::CreateAsyncHostResolver(parallelism, retry_attempts, net_log); | |
| 173 } else { | |
| 174 global_host_resolver = | |
| 175 net::CreateSystemHostResolver(parallelism, retry_attempts, net_log); | |
| 176 } | |
| 177 | 173 |
| 178 // Determine if we should disable IPv6 support. | 174 // Determine if we should disable IPv6 support. |
| 179 if (!command_line.HasSwitch(switches::kEnableIPv6)) { | 175 if (!command_line.HasSwitch(switches::kEnableIPv6)) { |
| 180 if (command_line.HasSwitch(switches::kDisableIPv6)) { | 176 if (command_line.HasSwitch(switches::kDisableIPv6)) { |
| 181 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); | 177 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); |
| 182 } else { | 178 } else { |
| 183 global_host_resolver->ProbeIPv6Support(); | 179 global_host_resolver->ProbeIPv6Support(); |
| 184 } | 180 } |
| 185 } | 181 } |
| 186 | 182 |
| 187 // If hostname remappings were specified on the command-line, layer these | 183 // If hostname remappings were specified on the command-line, layer these |
| 188 // rules on top of the real host resolver. This allows forwarding all requests | 184 // rules on top of the real host resolver. This allows forwarding all requests |
| 189 // through a designated test server. | 185 // through a designated test server. |
| 190 if (!command_line.HasSwitch(switches::kHostResolverRules)) | 186 if (!command_line.HasSwitch(switches::kHostResolverRules)) |
| 191 return global_host_resolver; | 187 return global_host_resolver.PassAs<net::HostResolver>(); |
| 192 | 188 |
| 193 net::MappedHostResolver* remapped_resolver = | 189 scoped_ptr<net::MappedHostResolver> remapped_resolver( |
| 194 new net::MappedHostResolver(global_host_resolver); | 190 new net::MappedHostResolver(global_host_resolver.Pass())); |
| 195 remapped_resolver->SetRulesFromString( | 191 remapped_resolver->SetRulesFromString( |
| 196 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); | 192 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
| 197 return remapped_resolver; | 193 return remapped_resolver.PassAs<net::HostResolver>(); |
| 198 } | 194 } |
| 199 | 195 |
| 200 // TODO(willchan): Remove proxy script fetcher context since it's not necessary | 196 // TODO(willchan): Remove proxy script fetcher context since it's not necessary |
| 201 // now that I got rid of refcounting URLRequestContexts. | 197 // now that I got rid of refcounting URLRequestContexts. |
| 202 // See IOThread::Globals for details. | 198 // See IOThread::Globals for details. |
| 203 net::URLRequestContext* | 199 net::URLRequestContext* |
| 204 ConstructProxyScriptFetcherContext(IOThread::Globals* globals, | 200 ConstructProxyScriptFetcherContext(IOThread::Globals* globals, |
| 205 net::NetLog* net_log) { | 201 net::NetLog* net_log) { |
| 206 net::URLRequestContext* context = new URLRequestContextWithUserAgent; | 202 net::URLRequestContext* context = new URLRequestContextWithUserAgent; |
| 207 context->set_net_log(net_log); | 203 context->set_net_log(net_log); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 NULL, | 435 NULL, |
| 440 NULL, | 436 NULL, |
| 441 NULL, | 437 NULL, |
| 442 NULL, | 438 NULL, |
| 443 &system_enable_referrers_, | 439 &system_enable_referrers_, |
| 444 NULL, | 440 NULL, |
| 445 NULL); | 441 NULL); |
| 446 if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling)) | 442 if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling)) |
| 447 network_delegate->NeverThrottleRequests(); | 443 network_delegate->NeverThrottleRequests(); |
| 448 globals_->system_network_delegate.reset(network_delegate); | 444 globals_->system_network_delegate.reset(network_delegate); |
| 449 globals_->host_resolver.reset( | 445 globals_->host_resolver = CreateGlobalHostResolver(net_log_); |
| 450 CreateGlobalHostResolver(net_log_)); | |
| 451 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault()); | 446 globals_->cert_verifier.reset(net::CertVerifier::CreateDefault()); |
| 452 globals_->transport_security_state.reset(new net::TransportSecurityState()); | 447 globals_->transport_security_state.reset(new net::TransportSecurityState()); |
| 453 globals_->ssl_config_service = GetSSLConfigService(); | 448 globals_->ssl_config_service = GetSSLConfigService(); |
| 454 if (command_line.HasSwitch(switches::kSpdyProxyOrigin)) { | 449 if (command_line.HasSwitch(switches::kSpdyProxyOrigin)) { |
| 455 spdyproxy_origin_ = | 450 spdyproxy_origin_ = |
| 456 command_line.GetSwitchValueASCII(switches::kSpdyProxyOrigin); | 451 command_line.GetSwitchValueASCII(switches::kSpdyProxyOrigin); |
| 457 } | 452 } |
| 458 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( | 453 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
| 459 globals_->host_resolver.get())); | 454 globals_->host_resolver.get())); |
| 460 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl); | 455 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 new net::HttpNetworkLayer( | 725 new net::HttpNetworkLayer( |
| 731 new net::HttpNetworkSession(system_params))); | 726 new net::HttpNetworkSession(system_params))); |
| 732 globals_->system_ftp_transaction_factory.reset( | 727 globals_->system_ftp_transaction_factory.reset( |
| 733 new net::FtpNetworkLayer(globals_->host_resolver.get())); | 728 new net::FtpNetworkLayer(globals_->host_resolver.get())); |
| 734 globals_->system_request_context.reset( | 729 globals_->system_request_context.reset( |
| 735 ConstructSystemRequestContext(globals_, net_log_)); | 730 ConstructSystemRequestContext(globals_, net_log_)); |
| 736 | 731 |
| 737 sdch_manager_->set_sdch_fetcher( | 732 sdch_manager_->set_sdch_fetcher( |
| 738 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); | 733 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); |
| 739 } | 734 } |
| OLD | NEW |