diff options
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.h | 2 | ||||
-rw-r--r-- | chrome/browser/net/dns_global.cc | 19 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 10 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 | ||||
-rw-r--r-- | net/base/fixed_host_resolver.cc | 52 | ||||
-rw-r--r-- | net/base/fixed_host_resolver.h | 42 | ||||
-rw-r--r-- | net/base/host_resolver.h | 12 | ||||
-rw-r--r-- | net/net.gyp | 2 |
8 files changed, 130 insertions, 10 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 8bbfabe..5935297 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -33,7 +33,7 @@ class ChromeURLRequestContextFactory; // Most methods are expected to be called on the UI thread, except for // the destructor and GetURLRequestContext(). class ChromeURLRequestContextGetter : public URLRequestContextGetter, - public NotificationObserver { + public NotificationObserver { public: // Constructs a ChromeURLRequestContextGetter that will use |factory| to // create the ChromeURLRequestContext. If |profile| is non-NULL, then the diff --git a/chrome/browser/net/dns_global.cc b/chrome/browser/net/dns_global.cc index d70a3a0..7caef17 100644 --- a/chrome/browser/net/dns_global.cc +++ b/chrome/browser/net/dns_global.cc @@ -7,6 +7,7 @@ #include <map> #include <string> +#include "base/command_line.h" #include "base/singleton.h" #include "base/stats_counters.h" #include "base/string_util.h" @@ -22,6 +23,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/chrome_switches.h" +#include "net/base/fixed_host_resolver.h" #include "net/base/host_resolver.h" #include "net/base/host_resolver_impl.h" @@ -476,12 +478,21 @@ static void DiscardAllPrefetchState() { net::HostResolver* GetGlobalHostResolver() { // Called from UI thread. if (!global_host_resolver) { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + + // The FixedHostResolver allows us to send all network requests through + // a designated test server. + if (command_line.HasSwitch(switches::kFixedServer)) { + std::string host_and_port = + WideToASCII(command_line.GetSwitchValue(switches::kFixedServer)); + global_host_resolver = new net::FixedHostResolver(host_and_port); + return global_host_resolver; + } + global_host_resolver = net::CreateSystemHostResolver(); - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableIPv6)) { - global_host_resolver->SetDefaultAddressFamily( - net::ADDRESS_FAMILY_IPV4); - } + if (command_line.HasSwitch(switches::kDisableIPv6)) + global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); } return global_host_resolver; } diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 1099dd55..a1d66b9 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -566,6 +566,16 @@ const char kUninstall[] = "uninstall"; // This is a temporary testing flag. const char kUseFlip[] = "use-flip"; +// Force all requests to go to this server. This commandline is provided +// for testing purposes only, and will likely be removed soon. It can also +// hurt startup performance as it does a synchronous name resolution on the +// UI thread. The port is not optional. +// The host resolution using this scheme is done exactly once at startup. +// From that point on, it is completely a static configuration. +// TODO(mbelshe): Remove this flag when testing is complete. +// --testing-fixed-server=myserver:1000 +const char kFixedServer[] = "testing-fixed-server"; + // Use the low fragmentation heap for the CRT. const char kUseLowFragHeapCrt[] = "use-lf-heap"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 3c37ea9..e649ec4 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -161,6 +161,7 @@ extern const char kTrustedPlugins[]; extern const char kTryChromeAgain[]; extern const char kUninstall[]; extern const char kUseFlip[]; +extern const char kFixedServer[]; extern const char kUseLowFragHeapCrt[]; extern const char kUserAgent[]; extern const char kUserDataDir[]; diff --git a/net/base/fixed_host_resolver.cc b/net/base/fixed_host_resolver.cc new file mode 100644 index 0000000..54e48a9 --- /dev/null +++ b/net/base/fixed_host_resolver.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/base/fixed_host_resolver.h" + +#include "net/base/net_errors.h" +#include "net/base/net_util.h" +#include "net/base/host_resolver_impl.h" + +namespace net { + +FixedHostResolver::FixedHostResolver(const std::string& host_and_port) + : initialized_(false) { + std::string host; + int port = 0; + if (!ParseHostAndPort(host_and_port, &host, &port)) { + LOG(ERROR) << "Invalid FixedHostResolver information: " << host_and_port; + return; + } + + int rv = SystemHostResolverProc(host, net::ADDRESS_FAMILY_UNSPECIFIED, + &address_); + if (rv != OK) { + LOG(ERROR) << "Could not resolve fixed host: " << host; + return; + } + + if (port <= 0) { + LOG(ERROR) << "FixedHostResolver must contain a port number"; + return; + } + + address_.SetPort(port); + initialized_ = true; +} + +int FixedHostResolver::Resolve(const RequestInfo& info, + AddressList* addresses, + CompletionCallback* callback, + RequestHandle* out_req, + LoadLog* load_log) { + if (!initialized_) + return ERR_NAME_NOT_RESOLVED; + + DCHECK(addresses); + *addresses = address_; + return OK; +} + +} // namespace net + diff --git a/net/base/fixed_host_resolver.h b/net/base/fixed_host_resolver.h new file mode 100644 index 0000000..cf1bd74 --- /dev/null +++ b/net/base/fixed_host_resolver.h @@ -0,0 +1,42 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_BASE_FIXED_HOST_RESOLVER_H_ +#define NET_BASE_FIXED_HOST_RESOLVER_H_ + +#include <string> + +#include "net/base/address_list.h" +#include "net/base/host_resolver.h" + +namespace net { + +// A FixedHostResolver resolves all addresses to a single address. +class FixedHostResolver : public HostResolver { + public: + // |host_and_port| is a string representing the resolution. + // example: foo.myproxy.com:1234 + explicit FixedHostResolver(const std::string& host_and_port); + + // HostResolver methods: + virtual int Resolve(const RequestInfo& info, + AddressList* addresses, + CompletionCallback* callback, + RequestHandle* out_req, + LoadLog* load_log); + virtual void CancelRequest(RequestHandle req) {} + virtual void AddObserver(Observer* observer) {} + virtual void RemoveObserver(Observer* observer) {} + virtual HostCache* GetHostCache() { return NULL; } + virtual void Shutdown() {} + + private: + AddressList address_; + bool initialized_; +}; + +} // namespace net + +#endif // NET_BASE_MOCK_HOST_RESOLVER_H_ + diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h index 998de32..9534e03 100644 --- a/net/base/host_resolver.h +++ b/net/base/host_resolver.h @@ -116,11 +116,13 @@ class HostResolver : public base::RefCountedThreadSafe<HostResolver> { // // When callback is null, the operation completes synchronously. // - // When callback is non-null, the operation will be performed asynchronously. - // ERR_IO_PENDING is returned if it has been scheduled successfully. Real - // result code will be passed to the completion callback. If |req| is - // non-NULL, then |*req| will be filled with a handle to the async request. - // This handle is not valid after the request has completed. + // When callback is non-null, the operation may be performed asynchronously. + // If the operation cannnot be completed synchronously, ERR_IO_PENDING will + // be returned and the real result code will be passed to the completion + // callback. Otherwise the result code is returned immediately from this + // call. + // If |req| is non-NULL, then |*req| will be filled with a handle to the + // async request. This handle is not valid after the request has completed. // // Profiling information for the request is saved to |load_log| if non-NULL. virtual int Resolve(const RequestInfo& info, diff --git a/net/net.gyp b/net/net.gyp index d83f545..23154cb 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -66,6 +66,8 @@ 'base/file_stream_win.cc', 'base/filter.cc', 'base/filter.h', + 'base/fixed_host_resolver.cc', + 'base/fixed_host_resolver.h', 'base/gzip_filter.cc', 'base/gzip_filter.h', 'base/gzip_header.cc', |