diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-18 08:03:38 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-18 08:03:38 +0000 |
commit | 9087aa3c473281af9c216d060d00baa4e1af4216 (patch) | |
tree | 11020a066a239d0042247611052c43f7fd0859ef /chrome/browser/io_thread.cc | |
parent | 3517fd50b20611670f08aedfff25451f6fe9e313 (diff) | |
download | chromium_src-9087aa3c473281af9c216d060d00baa4e1af4216.zip chromium_src-9087aa3c473281af9c216d060d00baa4e1af4216.tar.gz chromium_src-9087aa3c473281af9c216d060d00baa4e1af4216.tar.bz2 |
Add a command-line flag to remap hostnames based on patterns.
This is a generalization of the --testing-fixed-server flag.
BUG=36053
TEST=MappedHostResolverTest.*
Review URL: http://codereview.chromium.org/647001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39342 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/io_thread.cc')
-rw-r--r-- | chrome/browser/io_thread.cc | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 1b62f9c..1aafdf4 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -11,7 +11,7 @@ #include "chrome/browser/net/dns_global.h" #include "chrome/browser/net/url_fetcher.h" #include "chrome/common/chrome_switches.h" -#include "net/base/fixed_host_resolver.h" +#include "net/base/mapped_host_resolver.h" #include "net/base/host_cache.h" #include "net/base/host_resolver.h" #include "net/base/host_resolver_impl.h" @@ -28,34 +28,47 @@ net::HostResolver* CreateGlobalHostResolver( const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - // The FixedHostResolver allows us to send all network requests through - // a designated test server. + global_host_resolver = + net::CreateSystemHostResolver(network_change_notifier); + + if (!command_line.HasSwitch(switches::kEnableIPv6)) { + // Measure impact of allowing IPv6 support without probing. + const FieldTrial::Probability kDivisor = 100; + const FieldTrial::Probability kProbability = 50; // 50% probability. + FieldTrial* trial = new FieldTrial("IPv6_Probe", kDivisor); + int skip_group = trial->AppendGroup("_IPv6_probe_skipped", kProbability); + trial->AppendGroup("_IPv6_probe_done", + FieldTrial::kAllRemainingProbability); + bool use_ipv6_probe = (trial->group() != skip_group); + + // Perform probe, and then optionally use result to disable IPv6. + // Some users report confused OS handling of IPv6, leading to large + // latency. If we can show that IPv6 is not supported, then disabliing it + // will work around such problems. + if ((!net::IPv6Supported() && use_ipv6_probe) || + command_line.HasSwitch(switches::kDisableIPv6)) + global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); + } + + std::string hostname_remappings; + if (command_line.HasSwitch(switches::kFixedHost)) { std::string host = command_line.GetSwitchValueASCII(switches::kFixedHost); - global_host_resolver = new net::FixedHostResolver(host); - } else { - global_host_resolver = - net::CreateSystemHostResolver(network_change_notifier); - - if (!command_line.HasSwitch(switches::kEnableIPv6)) { - // Measure impact of allowing IPv6 support without probing. - const FieldTrial::Probability kDivisor = 100; - const FieldTrial::Probability kProbability = 50; // 50% probability. - FieldTrial* trial = new FieldTrial("IPv6_Probe", kDivisor); - int skip_group = trial->AppendGroup("_IPv6_probe_skipped", kProbability); - trial->AppendGroup("_IPv6_probe_done", - FieldTrial::kAllRemainingProbability); - bool use_ipv6_probe = (trial->group() != skip_group); - - // Perform probe, and then optionally use result to disable IPv6. - // Some users report confused OS handling of IPv6, leading to large - // latency. If we can show that IPv6 is not supported, then disabliing it - // will work around such problems. - if ((!net::IPv6Supported() && use_ipv6_probe) || - command_line.HasSwitch(switches::kDisableIPv6)) - global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); - } + hostname_remappings = StringPrintf("MAP * %s", host.c_str()); + } else if (command_line.HasSwitch(switches::kHostResolverRules)) { + hostname_remappings = + command_line.GetSwitchValueASCII(switches::kHostResolverRules); + } + + // If hostname remappings were specified on the command-line, layer these + // rules on top of the real host resolver. This allows forwarding all requests + // through a designated test server. + if (!hostname_remappings.empty()) { + net::MappedHostResolver* remapped_resolver = + new net::MappedHostResolver(global_host_resolver); + global_host_resolver = remapped_resolver; + remapped_resolver->SetRulesFromString(hostname_remappings); } return global_host_resolver; |