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