OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/leak_tracker.h" | 8 #include "base/leak_tracker.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chrome_thread.h" | 13 #include "chrome/browser/chrome_thread.h" |
14 #include "chrome/browser/gpu_process_host.h" | 14 #include "chrome/browser/gpu_process_host.h" |
15 #include "chrome/browser/net/chrome_net_log.h" | 15 #include "chrome/browser/net/chrome_net_log.h" |
16 #include "chrome/browser/net/predictor_api.h" | 16 #include "chrome/browser/net/predictor_api.h" |
17 #include "chrome/browser/net/passive_log_collector.h" | 17 #include "chrome/browser/net/passive_log_collector.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/net/url_fetcher.h" | 19 #include "chrome/common/net/url_fetcher.h" |
20 #include "net/base/mapped_host_resolver.h" | 20 #include "net/base/mapped_host_resolver.h" |
21 #include "net/base/host_cache.h" | 21 #include "net/base/host_cache.h" |
22 #include "net/base/host_resolver.h" | 22 #include "net/base/host_resolver.h" |
23 #include "net/base/host_resolver_impl.h" | 23 #include "net/base/host_resolver_impl.h" |
24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
25 #include "net/http/http_auth_filter.h" | 25 #include "net/http/http_auth_filter.h" |
26 #include "net/http/http_auth_handler_factory.h" | 26 #include "net/http/http_auth_handler_factory.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 net::HostResolver* CreateGlobalHostResolver() { | 30 net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { |
31 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 31 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
32 | 32 |
33 size_t parallelism = net::HostResolver::kDefaultParallelism; | 33 size_t parallelism = net::HostResolver::kDefaultParallelism; |
34 | 34 |
35 // Use the concurrency override from the command-line, if any. | 35 // Use the concurrency override from the command-line, if any. |
36 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { | 36 if (command_line.HasSwitch(switches::kHostResolverParallelism)) { |
37 std::string s = | 37 std::string s = |
38 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); | 38 command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); |
39 | 39 |
40 // Parse the switch (it should be a positive integer formatted as decimal). | 40 // Parse the switch (it should be a positive integer formatted as decimal). |
41 int n; | 41 int n; |
42 if (base::StringToInt(s, &n) && n > 0) { | 42 if (base::StringToInt(s, &n) && n > 0) { |
43 parallelism = static_cast<size_t>(n); | 43 parallelism = static_cast<size_t>(n); |
44 } else { | 44 } else { |
45 LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s; | 45 LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s; |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 net::HostResolver* global_host_resolver = | 49 net::HostResolver* global_host_resolver = |
50 net::CreateSystemHostResolver(parallelism); | 50 net::CreateSystemHostResolver(parallelism, net_log); |
51 | 51 |
52 // Determine if we should disable IPv6 support. | 52 // Determine if we should disable IPv6 support. |
53 if (!command_line.HasSwitch(switches::kEnableIPv6)) { | 53 if (!command_line.HasSwitch(switches::kEnableIPv6)) { |
54 if (command_line.HasSwitch(switches::kDisableIPv6)) { | 54 if (command_line.HasSwitch(switches::kDisableIPv6)) { |
55 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); | 55 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); |
56 } else { | 56 } else { |
57 net::HostResolverImpl* host_resolver_impl = | 57 net::HostResolverImpl* host_resolver_impl = |
58 global_host_resolver->GetAsHostResolverImpl(); | 58 global_host_resolver->GetAsHostResolverImpl(); |
59 if (host_resolver_impl != NULL) { | 59 if (host_resolver_impl != NULL) { |
60 // (optionally) Use probe to decide if support is warranted. | 60 // (optionally) Use probe to decide if support is warranted. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 globals_ = new Globals; | 179 globals_ = new Globals; |
180 | 180 |
181 globals_->net_log.reset(new ChromeNetLog()); | 181 globals_->net_log.reset(new ChromeNetLog()); |
182 | 182 |
183 // Add an observer that will emit network change events to the ChromeNetLog. | 183 // Add an observer that will emit network change events to the ChromeNetLog. |
184 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be | 184 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
185 // logging the network change before other IO thread consumers respond to it. | 185 // logging the network change before other IO thread consumers respond to it. |
186 network_change_observer_.reset( | 186 network_change_observer_.reset( |
187 new LoggingNetworkChangeObserver(globals_->net_log.get())); | 187 new LoggingNetworkChangeObserver(globals_->net_log.get())); |
188 | 188 |
189 globals_->host_resolver = CreateGlobalHostResolver(); | 189 globals_->host_resolver = CreateGlobalHostResolver(globals_->net_log.get()); |
190 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( | 190 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
191 globals_->host_resolver)); | 191 globals_->host_resolver)); |
192 } | 192 } |
193 | 193 |
194 void IOThread::CleanUp() { | 194 void IOThread::CleanUp() { |
195 // This must be reset before the ChromeNetLog is destroyed. | 195 // This must be reset before the ChromeNetLog is destroyed. |
196 network_change_observer_.reset(); | 196 network_change_observer_.reset(); |
197 | 197 |
198 // If any child processes are still running, terminate them and | 198 // If any child processes are still running, terminate them and |
199 // and delete the BrowserChildProcessHost instances to release whatever | 199 // and delete the BrowserChildProcessHost instances to release whatever |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 net::HostCache* host_cache = | 315 net::HostCache* host_cache = |
316 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); | 316 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); |
317 if (host_cache) | 317 if (host_cache) |
318 host_cache->clear(); | 318 host_cache->clear(); |
319 } | 319 } |
320 // Clear all of the passively logged data. | 320 // Clear all of the passively logged data. |
321 // TODO(eroman): this is a bit heavy handed, really all we need to do is | 321 // TODO(eroman): this is a bit heavy handed, really all we need to do is |
322 // clear the data pertaining to off the record context. | 322 // clear the data pertaining to off the record context. |
323 globals_->net_log->passive_collector()->Clear(); | 323 globals_->net_log->passive_collector()->Clear(); |
324 } | 324 } |
OLD | NEW |