summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 00:49:38 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 00:49:38 +0000
commit8a00f00ab5d68ffcc998fd04d2ca343af7cdf190 (patch)
treefd464ba49db4271c76c1cf8f769a22120ad631af /chrome
parent77ae132c1bfdd986228b6f1c0d8c63baa441afdf (diff)
downloadchromium_src-8a00f00ab5d68ffcc998fd04d2ca343af7cdf190.zip
chromium_src-8a00f00ab5d68ffcc998fd04d2ca343af7cdf190.tar.gz
chromium_src-8a00f00ab5d68ffcc998fd04d2ca343af7cdf190.tar.bz2
* Avoid doing concurrent DNS resolves of the same hostname in HostResolver.
* Add a 1 minute cache for host resolves. * Refactor HostResolver to handle multiple requests. * Make HostResolver a dependency of URLRequestContext. operate the HostResolver in async mode for proxy resolver (bridging to IO thread). TEST=unittests BUG=13163 Review URL: http://codereview.chromium.org/118100 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18236 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc29
-rw-r--r--chrome/browser/net/dns_global.cc5
-rw-r--r--chrome/browser/net/dns_master.cc7
-rw-r--r--chrome/browser/net/dns_master_unittest.cc2
4 files changed, 26 insertions, 17 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 0a1fb13..b188694 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/extensions/user_script_master.h"
+#include "chrome/browser/net/dns_global.h"
#include "chrome/browser/profile.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
@@ -109,11 +110,15 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
DCHECK(!profile->IsOffTheRecord());
ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
+ // Global host resolver for the context.
+ context->host_resolver_ = chrome_browser_net::GetGlobalHostResolver();
+
context->proxy_service_ = CreateProxyService(
context, *CommandLine::ForCurrentProcess());
net::HttpCache* cache =
- new net::HttpCache(context->proxy_service_,
+ new net::HttpCache(context->host_resolver_,
+ context->proxy_service_,
disk_cache_path.ToWStringHack(), 0);
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
@@ -133,9 +138,11 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
// implementations on Windows.
#if defined(OS_WIN)
if (command_line.HasSwitch(switches::kNewFtp))
- context->ftp_transaction_factory_ = new net::FtpNetworkLayer;
+ context->ftp_transaction_factory_ =
+ new net::FtpNetworkLayer(context->host_resolver_);
#else
- context->ftp_transaction_factory_ = new net::FtpNetworkLayer;
+ context->ftp_transaction_factory_ =
+ new net::FtpNetworkLayer(context->host_resolver_);
#endif
// setup cookie store
@@ -183,14 +190,16 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecord(
DCHECK(profile->IsOffTheRecord());
ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
- // Share the same proxy service as the original profile. This proxy
- // service's lifespan is dependent on the lifespan of the original profile,
- // which we reference (see above).
+ // Share the same proxy service and host resolver as the original profile.
+ // This proxy service's lifespan is dependent on the lifespan of the original
+ // profile which we reference (see above).
+ context->host_resolver_ =
+ profile->GetOriginalProfile()->GetRequestContext()->host_resolver();
context->proxy_service_ =
profile->GetOriginalProfile()->GetRequestContext()->proxy_service();
context->http_transaction_factory_ =
- new net::HttpCache(context->proxy_service_, 0);
+ new net::HttpCache(context->host_resolver_, context->proxy_service_, 0);
context->cookie_store_ = new net::CookieMonster;
return context;
@@ -241,7 +250,8 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia(
} else {
// If original HttpCache doesn't exist, simply construct one with a whole
// new set of network stack.
- cache = new net::HttpCache(original_context->proxy_service(),
+ cache = new net::HttpCache(original_context->host_resolver(),
+ original_context->proxy_service(),
disk_cache_path.ToWStringHack(), 0);
}
@@ -417,4 +427,7 @@ ChromeURLRequestContext::~ChromeURLRequestContext() {
// it is owned by the original URLRequestContext.
if (!is_off_the_record_ && !is_media_)
delete proxy_service_;
+
+ // Do not delete host_resolver_; it will be freed by FreeGlobalHostResolver()
+ // during the teardown of DNS prefetching.
}
diff --git a/chrome/browser/net/dns_global.cc b/chrome/browser/net/dns_global.cc
index 5aaa471..c54b14d 100644
--- a/chrome/browser/net/dns_global.cc
+++ b/chrome/browser/net/dns_global.cc
@@ -429,14 +429,11 @@ static net::HostResolver* global_host_resolver = NULL;
net::HostResolver* GetGlobalHostResolver() {
// Called from UI thread.
if (!global_host_resolver) {
- // TODO(eroman):
-#if 0
static const size_t kMaxHostCacheEntries = 100;
static const size_t kHostCacheExpirationSeconds = 60; // 1 minute.
global_host_resolver = new net::HostResolver(
kMaxHostCacheEntries, kHostCacheExpirationSeconds * 1000);
-#endif
}
return global_host_resolver;
}
@@ -444,8 +441,6 @@ net::HostResolver* GetGlobalHostResolver() {
void FreeGlobalHostResolver() {
if (global_host_resolver) {
// Called from IO thread.
- DCHECK_EQ(MessageLoop::current(),
- g_browser_process->io_thread()->message_loop());
delete global_host_resolver;
global_host_resolver = NULL;
}
diff --git a/chrome/browser/net/dns_master.cc b/chrome/browser/net/dns_master.cc
index 0477ddb..6151087 100644
--- a/chrome/browser/net/dns_master.cc
+++ b/chrome/browser/net/dns_master.cc
@@ -25,12 +25,13 @@ namespace chrome_browser_net {
class DnsMaster::LookupRequest {
public:
LookupRequest(DnsMaster* master,
- net::HostResolver* /*host_resolver*/,
+ net::HostResolver* host_resolver,
const std::string& hostname)
: ALLOW_THIS_IN_INITIALIZER_LIST(
net_callback_(this, &LookupRequest::OnLookupFinished)),
master_(master),
- hostname_(hostname) {
+ hostname_(hostname),
+ resolver_(host_resolver) {
}
bool Start() {
@@ -50,7 +51,7 @@ class DnsMaster::LookupRequest {
DnsMaster* master_; // Master which started us.
const std::string hostname_; // Hostname to resolve.
- net::HostResolver resolver_;
+ net::SingleRequestHostResolver resolver_;
net::AddressList addresses_;
DISALLOW_COPY_AND_ASSIGN(LookupRequest);
diff --git a/chrome/browser/net/dns_master_unittest.cc b/chrome/browser/net/dns_master_unittest.cc
index debc943..be68dfb 100644
--- a/chrome/browser/net/dns_master_unittest.cc
+++ b/chrome/browser/net/dns_master_unittest.cc
@@ -113,7 +113,7 @@ TimeDelta BlockingDnsLookup(const std::string& hostname) {
net::HostResolver resolver;
net::AddressList addresses;
- resolver.Resolve(hostname, 80, &addresses, NULL);
+ resolver.Resolve(hostname, 80, &addresses, NULL, NULL);
return Time::Now() - start;
}