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