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/chrome_net_log.h" | 25 #include "chrome/browser/net/chrome_net_log.h" |
25 #include "chrome/browser/net/chrome_network_delegate.h" | 26 #include "chrome/browser/net/chrome_network_delegate.h" |
26 #include "chrome/browser/net/chrome_url_request_context.h" | 27 #include "chrome/browser/net/chrome_url_request_context.h" |
27 #include "chrome/browser/net/connect_interceptor.h" | 28 #include "chrome/browser/net/connect_interceptor.h" |
28 #include "chrome/browser/net/http_pipelining_compatibility_client.h" | 29 #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
29 #include "chrome/browser/net/load_time_stats.h" | 30 #include "chrome/browser/net/load_time_stats.h" |
30 #include "chrome/browser/net/pref_proxy_config_tracker.h" | 31 #include "chrome/browser/net/pref_proxy_config_tracker.h" |
31 #include "chrome/browser/net/proxy_service_factory.h" | 32 #include "chrome/browser/net/proxy_service_factory.h" |
32 #include "chrome/browser/net/sdch_dictionary_fetcher.h" | 33 #include "chrome/browser/net/sdch_dictionary_fetcher.h" |
33 #include "chrome/browser/prefs/pref_service.h" | 34 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 virtual ~SystemURLRequestContext() { | 103 virtual ~SystemURLRequestContext() { |
103 #if defined(USE_NSS) | 104 #if defined(USE_NSS) |
104 net::SetURLRequestContextForNSSHttpIO(NULL); | 105 net::SetURLRequestContextForNSSHttpIO(NULL); |
105 #endif // defined(USE_NSS) | 106 #endif // defined(USE_NSS) |
106 } | 107 } |
107 }; | 108 }; |
108 | 109 |
109 net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { | 110 net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { |
110 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 111 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
111 | 112 |
| 113 bool allow_async_dns_field_trial = true; |
| 114 |
112 size_t parallelism = net::HostResolver::kDefaultParallelism; | 115 size_t parallelism = net::HostResolver::kDefaultParallelism; |
113 | 116 |
114 // Use the concurrency override from the command-line, if any. | 117 // Use the concurrency override from the command-line, if any. |
115 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { | 118 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { |
| 119 allow_async_dns_field_trial = false; |
116 std::string s = | 120 std::string s = |
117 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); | 121 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); |
118 | 122 |
119 // Parse the switch (it should be a positive integer formatted as decimal). | 123 // Parse the switch (it should be a positive integer formatted as decimal). |
120 int n; | 124 int n; |
121 if (base::StringToInt(s, &n) && n > 0) { | 125 if (base::StringToInt(s, &n) && n > 0) { |
122 parallelism = static_cast<size_t>(n); | 126 parallelism = static_cast<size_t>(n); |
123 } else { | 127 } else { |
124 LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s; | 128 LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s; |
125 } | 129 } |
126 } | 130 } |
127 | 131 |
128 size_t retry_attempts = net::HostResolver::kDefaultRetryAttempts; | 132 size_t retry_attempts = net::HostResolver::kDefaultRetryAttempts; |
129 | 133 |
130 // Use the retry attempts override from the command-line, if any. | 134 // Use the retry attempts override from the command-line, if any. |
131 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) { | 135 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) { |
| 136 allow_async_dns_field_trial = false; |
132 std::string s = | 137 std::string s = |
133 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts); | 138 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts); |
134 // Parse the switch (it should be a non-negative integer). | 139 // Parse the switch (it should be a non-negative integer). |
135 int n; | 140 int n; |
136 if (base::StringToInt(s, &n) && n >= 0) { | 141 if (base::StringToInt(s, &n) && n >= 0) { |
137 retry_attempts = static_cast<size_t>(n); | 142 retry_attempts = static_cast<size_t>(n); |
138 } else { | 143 } else { |
139 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; | 144 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; |
140 } | 145 } |
141 } | 146 } |
142 | 147 |
143 net::HostResolver* global_host_resolver = NULL; | 148 net::HostResolver* global_host_resolver = NULL; |
| 149 bool use_async = false; |
144 if (command_line.HasSwitch(switches::kEnableAsyncDns)) { | 150 if (command_line.HasSwitch(switches::kEnableAsyncDns)) { |
| 151 allow_async_dns_field_trial = false; |
| 152 use_async = true; |
| 153 } else if (command_line.HasSwitch(switches::kDisableAsyncDns)) { |
| 154 allow_async_dns_field_trial = false; |
| 155 use_async = false; |
| 156 } |
| 157 |
| 158 if (allow_async_dns_field_trial) |
| 159 use_async = chrome_browser_net::ConfigureAsyncDnsFieldTrial(); |
| 160 |
| 161 if (use_async) { |
145 global_host_resolver = | 162 global_host_resolver = |
146 net::CreateAsyncHostResolver(parallelism, retry_attempts, net_log); | 163 net::CreateAsyncHostResolver(parallelism, retry_attempts, net_log); |
147 } | 164 } else { |
148 | |
149 if (!global_host_resolver) { | |
150 global_host_resolver = | 165 global_host_resolver = |
151 net::CreateSystemHostResolver(parallelism, retry_attempts, net_log); | 166 net::CreateSystemHostResolver(parallelism, retry_attempts, net_log); |
152 } | 167 } |
153 | 168 |
154 // Determine if we should disable IPv6 support. | 169 // Determine if we should disable IPv6 support. |
155 if (!command_line.HasSwitch(switches::kEnableIPv6)) { | 170 if (!command_line.HasSwitch(switches::kEnableIPv6)) { |
156 if (command_line.HasSwitch(switches::kDisableIPv6)) { | 171 if (command_line.HasSwitch(switches::kDisableIPv6)) { |
157 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); | 172 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); |
158 } else { | 173 } else { |
159 global_host_resolver->ProbeIPv6Support(); | 174 global_host_resolver->ProbeIPv6Support(); |
160 } | 175 } |
161 } | 176 } |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 new net::HttpNetworkLayer( | 646 new net::HttpNetworkLayer( |
632 new net::HttpNetworkSession(system_params))); | 647 new net::HttpNetworkSession(system_params))); |
633 globals_->system_ftp_transaction_factory.reset( | 648 globals_->system_ftp_transaction_factory.reset( |
634 new net::FtpNetworkLayer(globals_->host_resolver.get())); | 649 new net::FtpNetworkLayer(globals_->host_resolver.get())); |
635 globals_->system_request_context.reset( | 650 globals_->system_request_context.reset( |
636 ConstructSystemRequestContext(globals_, net_log_)); | 651 ConstructSystemRequestContext(globals_, net_log_)); |
637 | 652 |
638 sdch_manager_->set_sdch_fetcher( | 653 sdch_manager_->set_sdch_fetcher( |
639 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); | 654 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); |
640 } | 655 } |
OLD | NEW |