diff options
author | agayev@chromium.org <agayev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-28 17:51:19 +0000 |
---|---|---|
committer | agayev@chromium.org <agayev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-28 17:51:19 +0000 |
commit | 2258c1c968ab008aa0bc75f2cbe56b2249194aff (patch) | |
tree | 72f799611e613f40c5e26bf8adb7622356edcbf9 | |
parent | d7b99393eb462ee93633028cfda04d33e8c37904 (diff) | |
download | chromium_src-2258c1c968ab008aa0bc75f2cbe56b2249194aff.zip chromium_src-2258c1c968ab008aa0bc75f2cbe56b2249194aff.tar.gz chromium_src-2258c1c968ab008aa0bc75f2cbe56b2249194aff.tar.bz2 |
Initial support for built-in DNS resolver/cache.
BUG=60149
TEST=None
Review URL: http://codereview.chromium.org/4216001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64271 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/io_thread.cc | 19 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 2 | ||||
-rw-r--r-- | chrome/common/net/raw_host_resolver_proc.cc | 28 | ||||
-rw-r--r-- | chrome/common/net/raw_host_resolver_proc.h | 40 | ||||
-rw-r--r-- | chrome/service/net/service_url_request_context.cc | 2 | ||||
-rw-r--r-- | chrome/test/plugin/plugin_test.cpp | 2 | ||||
-rw-r--r-- | chrome_frame/metrics_service.cc | 2 | ||||
-rw-r--r-- | chrome_frame/test/test_server_test.cc | 2 | ||||
-rw-r--r-- | jingle/notifier/listener/mediator_thread_impl.cc | 2 | ||||
-rw-r--r-- | net/base/host_resolver.h | 13 | ||||
-rw-r--r-- | net/base/host_resolver_impl.cc | 3 | ||||
-rw-r--r-- | net/proxy/proxy_script_fetcher_impl_unittest.cc | 2 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_unittest.cc | 2 | ||||
-rw-r--r-- | net/test/test_server.cc | 2 | ||||
-rw-r--r-- | net/tools/fetch/fetch_client.cc | 2 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.h | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_request_context.cc | 2 |
17 files changed, 109 insertions, 20 deletions
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index f4f92ba..f1cb24b 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -21,6 +21,7 @@ #include "chrome/browser/net/passive_log_collector.h" #include "chrome/browser/net/predictor_api.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/net/raw_host_resolver_proc.h" #include "chrome/common/net/url_fetcher.h" #include "net/base/dnsrr_resolver.h" #include "net/base/host_cache.h" @@ -87,8 +88,24 @@ net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { parallelism = 20; } + // Use the specified DNS server for doing raw resolutions if requested + // from the command-line. + scoped_refptr<net::HostResolverProc> resolver_proc; + if (command_line.HasSwitch(switches::kDnsServer)) { + std::string dns_ip_string = + command_line.GetSwitchValueASCII(switches::kDnsServer); + net::IPAddressNumber dns_ip_number; + if (net::ParseIPLiteralToNumber(dns_ip_string, &dns_ip_number)) { + resolver_proc = + new chrome_common_net::RawHostResolverProc(dns_ip_number, NULL); + } else { + LOG(ERROR) << "Invalid IP address specified for --dns-server: " + << dns_ip_string; + } + } + net::HostResolver* global_host_resolver = - net::CreateSystemHostResolver(parallelism, net_log); + net::CreateSystemHostResolver(parallelism, resolver_proc.get(), net_log); // Determine if we should disable IPv6 support. if (!command_line.HasSwitch(switches::kEnableIPv6)) { diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index e7970de..d4ca5b6 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -439,6 +439,8 @@ 'common/net/net_resource_provider.cc', 'common/net/net_resource_provider.h', 'common/net/predictor_common.h', + 'common/net/raw_host_resolver_proc.cc', + 'common/net/raw_host_resolver_proc.h', 'common/net/socket_stream.h', 'common/net/url_fetcher.cc', 'common/net/url_fetcher.h', diff --git a/chrome/common/net/raw_host_resolver_proc.cc b/chrome/common/net/raw_host_resolver_proc.cc new file mode 100644 index 0000000..474afa2 --- /dev/null +++ b/chrome/common/net/raw_host_resolver_proc.cc @@ -0,0 +1,28 @@ +// Copyright (c) 2010 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 "chrome/common/net/raw_host_resolver_proc.h" + +#include "base/logging.h" +#include "net/base/net_errors.h" + +namespace chrome_common_net { + +RawHostResolverProc::RawHostResolverProc(const net::IPAddressNumber& dns_server, + net::HostResolverProc* previous) + : HostResolverProc(previous), dns_server_(dns_server) {} + +int RawHostResolverProc::Resolve(const std::string& host, + net::AddressFamily address_family, + net::HostResolverFlags host_resolver_flags, + net::AddressList* addrlist, + int* os_error) { + // TODO(agayev): Implement raw DNS resolution. + LOG(INFO) << "trying to resolve " << host; + return net::ERR_NAME_NOT_RESOLVED; +} + +RawHostResolverProc::~RawHostResolverProc() {} + +} // namespace chrome_common_net diff --git a/chrome/common/net/raw_host_resolver_proc.h b/chrome/common/net/raw_host_resolver_proc.h new file mode 100644 index 0000000..7ec751a --- /dev/null +++ b/chrome/common/net/raw_host_resolver_proc.h @@ -0,0 +1,40 @@ +// Copyright (c) 2010 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 CHROME_COMMON_NET_RAW_HOST_RESOLVER_PROC_H_ +#define CHROME_COMMON_NET_RAW_HOST_RESOLVER_PROC_H_ +#pragma once + +// RawHostResolverProc will eventually be a getaddrinfo() replacement. It +// will construct and send DNS queries to the DNS server specified via +// --dns-server flag and will parse the responses and put it into a cache +// together with the TTL. Necessary amendments will be made to cache and +// HostResolverProc interface to accomodate these. + +#include <string> + +#include "net/base/host_resolver_proc.h" +#include "net/base/net_util.h" + +namespace chrome_common_net { + +class RawHostResolverProc : public net::HostResolverProc { + public: + RawHostResolverProc(const net::IPAddressNumber& dns_server, + net::HostResolverProc* previous); + + virtual int Resolve(const std::string& host, + net::AddressFamily address_family, + net::HostResolverFlags host_resolver_flags, + net::AddressList* addrlist, + int* os_error); + private: + virtual ~RawHostResolverProc(); + + net::IPAddressNumber dns_server_; +}; + +} // namespace chrome_common_net + +#endif // CHROME_COMMON_NET_RAW_HOST_RESOLVER_PROC_H_ diff --git a/chrome/service/net/service_url_request_context.cc b/chrome/service/net/service_url_request_context.cc index 8e5ae02..cd22539 100644 --- a/chrome/service/net/service_url_request_context.cc +++ b/chrome/service/net/service_url_request_context.cc @@ -20,7 +20,7 @@ ServiceURLRequestContext::ServiceURLRequestContext() { host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, - NULL); + NULL, NULL); DCHECK(g_service_process); // TODO(sanjeevr): Change CreateSystemProxyConfigService to accept a // MessageLoopProxy* instead of MessageLoop*. diff --git a/chrome/test/plugin/plugin_test.cpp b/chrome/test/plugin/plugin_test.cpp index c9b7027..c2f1ad4 100644 --- a/chrome/test/plugin/plugin_test.cpp +++ b/chrome/test/plugin/plugin_test.cpp @@ -263,7 +263,7 @@ class PluginInstallerDownloadTest void Initialize() { host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, - NULL); + NULL, NULL); net::ProxyConfigService* proxy_config_service = net::ProxyService::CreateSystemProxyConfigService(NULL, NULL); DCHECK(proxy_config_service); diff --git a/chrome_frame/metrics_service.cc b/chrome_frame/metrics_service.cc index cb30b94..6af2c0e 100644 --- a/chrome_frame/metrics_service.cc +++ b/chrome_frame/metrics_service.cc @@ -149,7 +149,7 @@ class ChromeFrameUploadRequestContext : public URLRequestContext { host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, - NULL); + NULL, NULL); net::ProxyConfigService* proxy_config_service = net::ProxyService::CreateSystemProxyConfigService(NULL, NULL); DCHECK(proxy_config_service); diff --git a/chrome_frame/test/test_server_test.cc b/chrome_frame/test/test_server_test.cc index edef592..fae70ae 100644 --- a/chrome_frame/test/test_server_test.cc +++ b/chrome_frame/test/test_server_test.cc @@ -63,7 +63,7 @@ class URLRequestTestContext : public URLRequestContext { URLRequestTestContext() { host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, - NULL); + NULL, NULL); proxy_service_ = net::ProxyService::CreateDirect(); ssl_config_service_ = new net::SSLConfigServiceDefaults; http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault( diff --git a/jingle/notifier/listener/mediator_thread_impl.cc b/jingle/notifier/listener/mediator_thread_impl.cc index 8a2877d..9782c55 100644 --- a/jingle/notifier/listener/mediator_thread_impl.cc +++ b/jingle/notifier/listener/mediator_thread_impl.cc @@ -125,7 +125,7 @@ void MediatorThreadImpl::DoLogin( // the IOThread one). host_resolver_.reset( net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, - NULL)); + NULL, NULL)); notifier::ServerInformation server_list[2]; int server_list_count = 0; diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h index 2fb7067..471ad8a 100644 --- a/net/base/host_resolver.h +++ b/net/base/host_resolver.h @@ -20,6 +20,7 @@ namespace net { class AddressList; class BoundNetLog; class HostResolverImpl; +class HostResolverProc; class NetLog; // This class represents the task of resolving hostnames (or IP address @@ -230,13 +231,13 @@ class SingleRequestHostResolver { DISALLOW_COPY_AND_ASSIGN(SingleRequestHostResolver); }; -// Creates a HostResolver implementation that queries the underlying system. -// (Except if a unit-test has changed the global HostResolverProc using -// ScopedHostResolverProc to intercept requests to the system). -// |max_concurrent_resolves| is how many resolve requests will be allowed to -// run in parallel. Pass HostResolver::kDefaultParallelism to choose a -// default value. +// Creates a HostResolver implementation using |resolver_proc| as resolver, +// (which if NULL, will default to getaddrinfo() wrapper) that queries the +// underlying system, |max_concurrent_resolves| is how many resolve +// requests will be allowed to run in parallel. Pass +// HostResolver::kDefaultParallelism to choose a default value. HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, + HostResolverProc* resolver_proc, NetLog* net_log); } // namespace net diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc index 246f50a..13dce85 100644 --- a/net/base/host_resolver_impl.cc +++ b/net/base/host_resolver_impl.cc @@ -72,6 +72,7 @@ HostCache* CreateDefaultCache() { } // anonymous namespace HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, + HostResolverProc* resolver_proc, NetLog* net_log) { // Maximum of 50 concurrent threads. // TODO(eroman): Adjust this, do some A/B experiments. @@ -81,7 +82,7 @@ HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, max_concurrent_resolves = kDefaultMaxJobs; HostResolverImpl* resolver = - new HostResolverImpl(NULL, CreateDefaultCache(), + new HostResolverImpl(resolver_proc, CreateDefaultCache(), max_concurrent_resolves, net_log); return resolver; diff --git a/net/proxy/proxy_script_fetcher_impl_unittest.cc b/net/proxy/proxy_script_fetcher_impl_unittest.cc index f84be57..f9828ee 100644 --- a/net/proxy/proxy_script_fetcher_impl_unittest.cc +++ b/net/proxy/proxy_script_fetcher_impl_unittest.cc @@ -36,7 +36,7 @@ class RequestContext : public URLRequestContext { net::ProxyConfig no_proxy; host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, - NULL); + NULL, NULL); proxy_service_ = net::ProxyService::CreateFixed(no_proxy); ssl_config_service_ = new net::SSLConfigServiceDefaults; diff --git a/net/socket/tcp_client_socket_unittest.cc b/net/socket/tcp_client_socket_unittest.cc index fdd966c..3d92166 100644 --- a/net/socket/tcp_client_socket_unittest.cc +++ b/net/socket/tcp_client_socket_unittest.cc @@ -93,7 +93,7 @@ void TCPClientSocketTest::SetUp() { AddressList addr; scoped_ptr<HostResolver> resolver( CreateSystemHostResolver(HostResolver::kDefaultParallelism, - NULL)); + NULL, NULL)); HostResolver::RequestInfo info(HostPortPair("localhost", listen_port_)); int rv = resolver->Resolve(info, &addr, NULL, NULL, BoundNetLog()); CHECK_EQ(rv, OK); diff --git a/net/test/test_server.cc b/net/test/test_server.cc index 3d44fc6..4b426eb 100644 --- a/net/test/test_server.cc +++ b/net/test/test_server.cc @@ -242,7 +242,7 @@ bool TestServer::GetAddressList(AddressList* address_list) const { DCHECK(address_list); scoped_ptr<HostResolver> resolver( - CreateSystemHostResolver(HostResolver::kDefaultParallelism, NULL)); + CreateSystemHostResolver(HostResolver::kDefaultParallelism, NULL, NULL)); HostResolver::RequestInfo info(host_port_pair_); int rv = resolver->Resolve(info, address_list, NULL, NULL, BoundNetLog()); if (rv != net::OK) { diff --git a/net/tools/fetch/fetch_client.cc b/net/tools/fetch/fetch_client.cc index 42949c8..3bdbcbf 100644 --- a/net/tools/fetch/fetch_client.cc +++ b/net/tools/fetch/fetch_client.cc @@ -137,7 +137,7 @@ int main(int argc, char**argv) { scoped_ptr<net::HostResolver> host_resolver( net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, - NULL)); + NULL, NULL)); scoped_refptr<net::ProxyService> proxy_service( net::ProxyService::CreateDirect()); diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h index 2a3ae41..abb6ab5 100644 --- a/net/url_request/url_request_unittest.h +++ b/net/url_request/url_request_unittest.h @@ -126,7 +126,7 @@ class TestURLRequestContext : public URLRequestContext { TestURLRequestContext() { host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, - NULL); + NULL, NULL); proxy_service_ = net::ProxyService::CreateDirect(); Init(); } @@ -134,7 +134,7 @@ class TestURLRequestContext : public URLRequestContext { explicit TestURLRequestContext(const std::string& proxy) { host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, - NULL); + NULL, NULL); net::ProxyConfig proxy_config; proxy_config.proxy_rules().ParseFromString(proxy); proxy_service_ = net::ProxyService::CreateFixed(proxy_config); diff --git a/webkit/tools/test_shell/test_shell_request_context.cc b/webkit/tools/test_shell/test_shell_request_context.cc index 9057fc0..d0e93e2 100644 --- a/webkit/tools/test_shell/test_shell_request_context.cc +++ b/webkit/tools/test_shell/test_shell_request_context.cc @@ -61,7 +61,7 @@ void TestShellRequestContext::Init( #endif host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, - NULL); + NULL, NULL); proxy_service_ = net::ProxyService::CreateUsingSystemProxyResolver( proxy_config_service.release(), 0, NULL); ssl_config_service_ = net::SSLConfigService::CreateSystemSSLConfigService(); |