Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: net/base/host_resolver_impl.cc

Issue 464084: Cache failed DNS resolutions for 1 second.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Merge changes (to include API change in another file) Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/host_resolver_impl.h ('k') | net/base/host_resolver_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/host_resolver_impl.cc
===================================================================
--- net/base/host_resolver_impl.cc (revision 34231)
+++ net/base/host_resolver_impl.cc (working copy)
@@ -35,9 +35,13 @@
HostResolver* CreateSystemHostResolver() {
static const size_t kMaxHostCacheEntries = 100;
- static const size_t kHostCacheExpirationMs = 60000; // 1 minute.
- return new HostResolverImpl(
- NULL, kMaxHostCacheEntries, kHostCacheExpirationMs);
+
+ HostCache* cache = new HostCache(
+ kMaxHostCacheEntries,
+ base::TimeDelta::FromMinutes(1),
+ base::TimeDelta::FromSeconds(1));
+
+ return new HostResolverImpl(NULL, cache);
}
static int ResolveAddrInfo(HostResolverProc* resolver_proc,
@@ -287,9 +291,8 @@
//-----------------------------------------------------------------------------
HostResolverImpl::HostResolverImpl(HostResolverProc* resolver_proc,
- int max_cache_entries,
- int cache_duration_ms)
- : cache_(max_cache_entries, cache_duration_ms),
+ HostCache* cache)
+ : cache_(cache),
next_request_id_(0),
resolver_proc_(resolver_proc),
default_address_family_(ADDRESS_FAMILY_UNSPECIFIED),
@@ -333,12 +336,13 @@
key.address_family = default_address_family_;
// If we have an unexpired cache entry, use it.
- if (info.allow_cached_response()) {
- const HostCache::Entry* cache_entry = cache_.Lookup(
+ if (info.allow_cached_response() && cache_.get()) {
+ const HostCache::Entry* cache_entry = cache_->Lookup(
key, base::TimeTicks::Now());
if (cache_entry) {
- addresses->SetFrom(cache_entry->addrlist, info.port());
int error = cache_entry->error;
+ if (error == OK)
+ addresses->SetFrom(cache_entry->addrlist, info.port());
// Update the load log and notify registered observers.
OnFinishRequest(load_log, request_id, info, error);
@@ -358,7 +362,8 @@
}
// Write to cache.
- cache_.Set(key, error, addrlist, base::TimeTicks::Now());
+ if (cache_.get())
+ cache_->Set(key, error, addrlist, base::TimeTicks::Now());
// Update the load log and notify registered observers.
OnFinishRequest(load_log, request_id, info, error);
@@ -429,7 +434,7 @@
}
HostCache* HostResolverImpl::GetHostCache() {
- return &cache_;
+ return cache_.get();
}
void HostResolverImpl::Shutdown() {
@@ -467,7 +472,8 @@
RemoveOutstandingJob(job);
// Write result to the cache.
- cache_.Set(job->key(), error, addrlist, base::TimeTicks::Now());
+ if (cache_.get())
+ cache_->Set(job->key(), error, addrlist, base::TimeTicks::Now());
// Make a note that we are executing within OnJobComplete() in case the
// HostResolver is deleted by a callback invocation.
« no previous file with comments | « net/base/host_resolver_impl.h ('k') | net/base/host_resolver_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698