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 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/leak_tracker.h" | 7 #include "base/leak_tracker.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
11 #include "chrome/browser/net/dns_global.h" | 11 #include "chrome/browser/net/dns_global.h" |
12 #include "chrome/browser/net/url_fetcher.h" | 12 #include "chrome/browser/net/url_fetcher.h" |
13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "net/base/mapped_host_resolver.h" | 14 #include "net/base/mapped_host_resolver.h" |
15 #include "net/base/host_cache.h" | 15 #include "net/base/host_cache.h" |
16 #include "net/base/host_resolver.h" | 16 #include "net/base/host_resolver.h" |
17 #include "net/base/host_resolver_impl.h" | 17 #include "net/base/host_resolver_impl.h" |
18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
19 #include "net/base/network_change_notifier.h" | 19 #include "net/base/network_change_notifier.h" |
20 #include "net/http/http_auth_handler_factory.h" | 20 #include "net/http/http_auth_handler_factory.h" |
21 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 net::HostResolver* CreateGlobalHostResolver( | 25 net::HostResolver* CreateGlobalHostResolver( |
26 net::NetworkChangeNotifier* network_change_notifier) { | 26 net::NetworkChangeNotifier* network_change_notifier) { |
27 net::HostResolver* global_host_resolver = NULL; | |
28 | |
29 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 27 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
30 | 28 net::HostResolver* global_host_resolver = |
31 global_host_resolver = | |
32 net::CreateSystemHostResolver(network_change_notifier); | 29 net::CreateSystemHostResolver(network_change_notifier); |
33 | 30 |
| 31 // Determine if we should disable IPv6 support. |
34 if (!command_line.HasSwitch(switches::kEnableIPv6)) { | 32 if (!command_line.HasSwitch(switches::kEnableIPv6)) { |
35 // Measure impact of allowing IPv6 support without probing. | 33 if (command_line.HasSwitch(switches::kDisableIPv6)) { |
36 const FieldTrial::Probability kDivisor = 100; | 34 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); |
37 const FieldTrial::Probability kProbability = 50; // 50% probability. | 35 } else { |
38 FieldTrial* trial = new FieldTrial("IPv6_Probe", kDivisor); | 36 net::HostResolverImpl* host_resolver_impl = |
39 int skip_group = trial->AppendGroup("_IPv6_probe_skipped", kProbability); | 37 global_host_resolver->GetAsHostResolverImpl(); |
40 trial->AppendGroup("_IPv6_probe_done", | 38 if (host_resolver_impl != NULL) { |
41 FieldTrial::kAllRemainingProbability); | 39 // (optionally) Use probe to decide if support is warranted. |
42 bool use_ipv6_probe = (trial->group() != skip_group); | |
43 | 40 |
44 // Perform probe, and then optionally use result to disable IPv6. | 41 // Measure impact of probing to allow IPv6. |
45 // Some users report confused OS handling of IPv6, leading to large | 42 // Some users report confused OS handling of IPv6, leading to large |
46 // latency. If we can show that IPv6 is not supported, then disabliing it | 43 // latency. If we can show that IPv6 is not supported, then disabliing |
47 // will work around such problems. | 44 // it will work around such problems. |
48 if ((!net::IPv6Supported() && use_ipv6_probe) || | 45 const FieldTrial::Probability kDivisor = 100; |
49 command_line.HasSwitch(switches::kDisableIPv6)) | 46 const FieldTrial::Probability kProbability = 50; // 50% probability. |
50 global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); | 47 FieldTrial* trial = new FieldTrial("IPv6_Probe", kDivisor); |
| 48 int skip_group = trial->AppendGroup("_IPv6_probe_skipped", |
| 49 kProbability); |
| 50 trial->AppendGroup("_IPv6_probe_done", |
| 51 FieldTrial::kAllRemainingProbability); |
| 52 bool use_ipv6_probe = (trial->group() != skip_group); |
| 53 if (use_ipv6_probe) |
| 54 host_resolver_impl->ProbeIPv6Support(); |
| 55 } |
| 56 } |
51 } | 57 } |
52 | 58 |
53 // If hostname remappings were specified on the command-line, layer these | 59 // If hostname remappings were specified on the command-line, layer these |
54 // rules on top of the real host resolver. This allows forwarding all requests | 60 // rules on top of the real host resolver. This allows forwarding all requests |
55 // through a designated test server. | 61 // through a designated test server. |
56 if (command_line.HasSwitch(switches::kHostResolverRules)) { | 62 if (!command_line.HasSwitch(switches::kHostResolverRules)) |
57 net::MappedHostResolver* remapped_resolver = | 63 return global_host_resolver; |
58 new net::MappedHostResolver(global_host_resolver); | |
59 global_host_resolver = remapped_resolver; | |
60 remapped_resolver->SetRulesFromString( | |
61 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); | |
62 } | |
63 | 64 |
64 return global_host_resolver; | 65 net::MappedHostResolver* remapped_resolver = |
| 66 new net::MappedHostResolver(global_host_resolver); |
| 67 remapped_resolver->SetRulesFromString( |
| 68 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
| 69 return remapped_resolver; |
65 } | 70 } |
66 | 71 |
67 } // namespace | 72 } // namespace |
68 | 73 |
69 // The IOThread object must outlive any tasks posted to the IO thread before the | 74 // The IOThread object must outlive any tasks posted to the IO thread before the |
70 // Quit task. | 75 // Quit task. |
71 template <> | 76 template <> |
72 struct RunnableMethodTraits<IOThread> { | 77 struct RunnableMethodTraits<IOThread> { |
73 void RetainCallee(IOThread* /* io_thread */) {} | 78 void RetainCallee(IOThread* /* io_thread */) {} |
74 void ReleaseCallee(IOThread* /* io_thread */) {} | 79 void ReleaseCallee(IOThread* /* io_thread */) {} |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 214 |
210 // Clear the host cache to avoid showing entries from the OTR session | 215 // Clear the host cache to avoid showing entries from the OTR session |
211 // in about:net-internals. | 216 // in about:net-internals. |
212 if (globals_->host_resolver->GetAsHostResolverImpl()) { | 217 if (globals_->host_resolver->GetAsHostResolverImpl()) { |
213 net::HostCache* host_cache = | 218 net::HostCache* host_cache = |
214 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); | 219 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); |
215 if (host_cache) | 220 if (host_cache) |
216 host_cache->clear(); | 221 host_cache->clear(); |
217 } | 222 } |
218 } | 223 } |
OLD | NEW |