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

Unified Diff: net/base/mock_host_resolver.cc

Issue 9226035: Adds TTL argument to HostCache::Set. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed the two other static initializers Created 8 years, 11 months 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.cc ('k') | net/dns/async_host_resolver.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/mock_host_resolver.cc
diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc
index 612c6007a48d1f076ee3058552c04ebb498e841d..49ef2c851108649007c798f5a8f64832c8bbb59b 100644
--- a/net/base/mock_host_resolver.cc
+++ b/net/base/mock_host_resolver.cc
@@ -22,6 +22,11 @@ namespace net {
namespace {
+// Cache size for the MockCachingHostResolver.
+const unsigned kMaxCacheEntries = 100;
+// TTL for the successful resolutions. Failures are not cached.
+const unsigned kCacheEntryTTLSeconds = 60;
+
char* do_strdup(const char* src) {
#if defined(OS_WIN)
return _strdup(src);
@@ -130,10 +135,7 @@ MockHostResolverBase::MockHostResolverBase(bool use_caching)
proc_ = rules_;
if (use_caching) {
- cache_.reset(new HostCache(
- 100, // max entries.
- base::TimeDelta::FromMinutes(1),
- base::TimeDelta::FromSeconds(0)));
+ cache_.reset(new HostCache(kMaxCacheEntries));
}
}
@@ -173,7 +175,11 @@ int MockHostResolverBase::ResolveProc(size_t id,
HostCache::Key key(info.hostname(),
info.address_family(),
info.host_resolver_flags());
- cache_->Set(key, rv, addr, base::TimeTicks::Now());
+ // Storing a failure with TTL 0 so that it overwrites previous value.
+ base::TimeDelta ttl;
+ if (rv == OK)
+ ttl = base::TimeDelta::FromSeconds(kCacheEntryTTLSeconds);
+ cache_->Set(key, rv, addr, base::TimeTicks::Now(), ttl);
}
if (rv == OK)
*addresses = CreateAddressListUsingPort(addr, info.port());
« no previous file with comments | « net/base/host_resolver_impl.cc ('k') | net/dns/async_host_resolver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698