summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-20 21:52:22 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-20 21:52:22 +0000
commit064b9a4dc94e9a5f911d1e474aa23dcd81a929c8 (patch)
tree8493d9f730596a9c773db65d738f2cbf0e7dff08 /net/base
parent96b939a7b319b4e925ed847cb5cbbcc921872f41 (diff)
downloadchromium_src-064b9a4dc94e9a5f911d1e474aa23dcd81a929c8.zip
chromium_src-064b9a4dc94e9a5f911d1e474aa23dcd81a929c8.tar.gz
chromium_src-064b9a4dc94e9a5f911d1e474aa23dcd81a929c8.tar.bz2
Revert 118489 since it seems to regress linux-sizes.
""" Adds custom ttl argument to HostCache::Set. BUG=25472,107880 TEST=net_unittests Review URL: http://codereview.chromium.org/9197009 TBR=szym@chromium.org Review URL: https://chromiumcodereview.appspot.com/9138039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118512 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/host_cache.cc34
-rw-r--r--net/base/host_cache.h25
-rw-r--r--net/base/host_cache_unittest.cc111
-rw-r--r--net/base/host_resolver_impl.cc16
-rw-r--r--net/base/mock_host_resolver.cc17
5 files changed, 100 insertions, 103 deletions
diff --git a/net/base/host_cache.cc b/net/base/host_cache.cc
index 731e5f5..03eb23a 100644
--- a/net/base/host_cache.cc
+++ b/net/base/host_cache.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -22,8 +22,12 @@ HostCache::Entry::~Entry() {
//-----------------------------------------------------------------------------
-HostCache::HostCache(size_t max_entries)
- : max_entries_(max_entries) {
+HostCache::HostCache(size_t max_entries,
+ base::TimeDelta success_entry_ttl,
+ base::TimeDelta failure_entry_ttl)
+ : max_entries_(max_entries),
+ success_entry_ttl_(success_entry_ttl),
+ failure_entry_ttl_(failure_entry_ttl) {
}
HostCache::~HostCache() {
@@ -49,13 +53,13 @@ const HostCache::Entry* HostCache::Lookup(const Key& key,
HostCache::Entry* HostCache::Set(const Key& key,
int error,
const AddressList& addrlist,
- base::TimeTicks now,
- base::TimeDelta ttl) {
+ base::TimeTicks now) {
DCHECK(CalledOnValidThread());
if (caching_is_disabled())
return NULL;
- base::TimeTicks expiration = now + ttl;
+ base::TimeTicks expiration = now +
+ (error == OK ? success_entry_ttl_ : failure_entry_ttl_);
scoped_refptr<Entry>& entry = entries_[key];
if (!entry) {
@@ -92,6 +96,16 @@ size_t HostCache::max_entries() const {
return max_entries_;
}
+base::TimeDelta HostCache::success_entry_ttl() const {
+ DCHECK(CalledOnValidThread());
+ return success_entry_ttl_;
+}
+
+base::TimeDelta HostCache::failure_entry_ttl() const {
+ DCHECK(CalledOnValidThread());
+ return failure_entry_ttl_;
+}
+
// Note that this map may contain expired entries.
const HostCache::EntryMap& HostCache::entries() const {
DCHECK(CalledOnValidThread());
@@ -106,7 +120,13 @@ bool HostCache::CanUseEntry(const Entry* entry, const base::TimeTicks now) {
// static
HostCache* HostCache::CreateDefaultCache() {
static const size_t kMaxHostCacheEntries = 100;
- return new HostCache(kMaxHostCacheEntries);
+
+ HostCache* cache = new HostCache(
+ kMaxHostCacheEntries,
+ base::TimeDelta::FromMinutes(1),
+ base::TimeDelta::FromSeconds(0)); // Disable caching of failed DNS.
+
+ return cache;
}
void HostCache::Compact(base::TimeTicks now, const Entry* pinned_entry) {
diff --git a/net/base/host_cache.h b/net/base/host_cache.h
index d7c1590..62c07ab 100644
--- a/net/base/host_cache.h
+++ b/net/base/host_cache.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -73,8 +73,12 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) {
typedef std::map<Key, scoped_refptr<Entry> > EntryMap;
- // Constructs a HostCache that stores up to |max_entries|.
- explicit HostCache(size_t max_entries);
+ // Constructs a HostCache that caches successful host resolves for
+ // |success_entry_ttl| time, and failed host resolves for
+ // |failure_entry_ttl|. The cache will store up to |max_entries|.
+ HostCache(size_t max_entries,
+ base::TimeDelta success_entry_ttl,
+ base::TimeDelta failure_entry_ttl);
~HostCache();
@@ -84,13 +88,12 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) {
// Overwrites or creates an entry for |key|. Returns the pointer to the
// entry, or NULL on failure (fails if caching is disabled).
- // (|error|, |addrlist|) is the value to set, |now| is the current time
- // |ttl| is the "time to live".
+ // (|error|, |addrlist|) is the value to set, and |now| is the current
+ // timestamp.
Entry* Set(const Key& key,
int error,
const AddressList& addrlist,
- base::TimeTicks now,
- base::TimeDelta ttl);
+ base::TimeTicks now);
// Empties the cache
void clear();
@@ -101,6 +104,10 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) {
// Following are used by net_internals UI.
size_t max_entries() const;
+ base::TimeDelta success_entry_ttl() const;
+
+ base::TimeDelta failure_entry_ttl() const;
+
// Note that this map may contain expired entries.
const EntryMap& entries() const;
@@ -126,6 +133,10 @@ class NET_EXPORT HostCache : NON_EXPORTED_BASE(public base::NonThreadSafe) {
// Bound on total size of the cache.
size_t max_entries_;
+ // Time to live for cache entries.
+ base::TimeDelta success_entry_ttl_;
+ base::TimeDelta failure_entry_ttl_;
+
// Map from hostname (presumably in lowercase canonicalized format) to
// a resolved result entry.
EntryMap entries_;
diff --git a/net/base/host_cache_unittest.cc b/net/base/host_cache_unittest.cc
index f00364d..4c99688 100644
--- a/net/base/host_cache_unittest.cc
+++ b/net/base/host_cache_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// 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.
@@ -14,9 +14,11 @@
namespace net {
namespace {
-
const int kMaxCacheEntries = 10;
+const base::TimeDelta kSuccessEntryTTL = base::TimeDelta::FromSeconds(10);
+const base::TimeDelta kFailureEntryTTL = base::TimeDelta::FromSeconds(0);
+
// Builds a key for |hostname|, defaulting the address family to unspecified.
HostCache::Key Key(const std::string& hostname) {
return HostCache::Key(hostname, ADDRESS_FAMILY_UNSPECIFIED, 0);
@@ -25,9 +27,7 @@ HostCache::Key Key(const std::string& hostname) {
} // namespace
TEST(HostCacheTest, Basic) {
- const base::TimeDelta kTTL = base::TimeDelta::FromSeconds(10);
-
- HostCache cache(kMaxCacheEntries);
+ HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL);
// Start at t=0.
base::TimeTicks now;
@@ -39,7 +39,7 @@ TEST(HostCacheTest, Basic) {
// Add an entry for "foobar.com" at t=0.
EXPECT_TRUE(cache.Lookup(Key("foobar.com"), base::TimeTicks()) == NULL);
- cache.Set(Key("foobar.com"), OK, AddressList(), now, kTTL);
+ cache.Set(Key("foobar.com"), OK, AddressList(), now);
entry1 = cache.Lookup(Key("foobar.com"), base::TimeTicks());
EXPECT_FALSE(entry1 == NULL);
EXPECT_EQ(1U, cache.size());
@@ -49,7 +49,7 @@ TEST(HostCacheTest, Basic) {
// Add an entry for "foobar2.com" at t=5.
EXPECT_TRUE(cache.Lookup(Key("foobar2.com"), base::TimeTicks()) == NULL);
- cache.Set(Key("foobar2.com"), OK, AddressList(), now, kTTL);
+ cache.Set(Key("foobar2.com"), OK, AddressList(), now);
entry2 = cache.Lookup(Key("foobar2.com"), base::TimeTicks());
EXPECT_FALSE(NULL == entry1);
EXPECT_EQ(2U, cache.size());
@@ -68,7 +68,7 @@ TEST(HostCacheTest, Basic) {
EXPECT_EQ(entry2, cache.Lookup(Key("foobar2.com"), now));
// Update entry1, so it is no longer expired.
- cache.Set(Key("foobar.com"), OK, AddressList(), now, kTTL);
+ cache.Set(Key("foobar.com"), OK, AddressList(), now);
// Re-uses existing entry storage.
EXPECT_EQ(entry1, cache.Lookup(Key("foobar.com"), now));
EXPECT_EQ(2U, cache.size());
@@ -84,20 +84,16 @@ TEST(HostCacheTest, Basic) {
EXPECT_TRUE(cache.Lookup(Key("foobar2.com"), now) == NULL);
}
-// Try caching entries for a failed resolve attempt -- since we set the TTL of
-// such entries to 0 it won't store, but it will kick out the previous result.
+// Try caching entries for a failed resolve attempt -- since we set
+// the TTL of such entries to 0 it won't work.
TEST(HostCacheTest, NoCacheNegative) {
- const base::TimeDelta kSuccessEntryTTL = base::TimeDelta::FromSeconds(10);
- const base::TimeDelta kFailureEntryTTL = base::TimeDelta::FromSeconds(0);
-
- HostCache cache(kMaxCacheEntries);
+ HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL);
// Set t=0.
base::TimeTicks now;
EXPECT_TRUE(cache.Lookup(Key("foobar.com"), base::TimeTicks()) == NULL);
- cache.Set(Key("foobar.com"), ERR_NAME_NOT_RESOLVED, AddressList(),
- now, kFailureEntryTTL);
+ cache.Set(Key("foobar.com"), ERR_NAME_NOT_RESOLVED, AddressList(), now);
EXPECT_EQ(1U, cache.size());
// We disallow use of negative entries.
@@ -105,18 +101,17 @@ TEST(HostCacheTest, NoCacheNegative) {
// Now overwrite with a valid entry, and then overwrite with negative entry
// again -- the valid entry should be kicked out.
- cache.Set(Key("foobar.com"), OK, AddressList(), now, kSuccessEntryTTL);
+ cache.Set(Key("foobar.com"), OK, AddressList(), now);
EXPECT_FALSE(cache.Lookup(Key("foobar.com"), now) == NULL);
- cache.Set(Key("foobar.com"), ERR_NAME_NOT_RESOLVED, AddressList(),
- now, kFailureEntryTTL);
+ cache.Set(Key("foobar.com"), ERR_NAME_NOT_RESOLVED, AddressList(), now);
EXPECT_TRUE(cache.Lookup(Key("foobar.com"), now) == NULL);
}
// Try caching entries for a failed resolves for 10 seconds.
TEST(HostCacheTest, CacheNegativeEntry) {
- const base::TimeDelta kFailureEntryTTL = base::TimeDelta::FromSeconds(10);
-
- HostCache cache(kMaxCacheEntries);
+ HostCache cache(kMaxCacheEntries,
+ base::TimeDelta::FromSeconds(0), // success entry TTL.
+ base::TimeDelta::FromSeconds(10)); // failure entry TTL.
// Start at t=0.
base::TimeTicks now;
@@ -128,8 +123,7 @@ TEST(HostCacheTest, CacheNegativeEntry) {
// Add an entry for "foobar.com" at t=0.
EXPECT_TRUE(cache.Lookup(Key("foobar.com"), base::TimeTicks()) == NULL);
- cache.Set(Key("foobar.com"), ERR_NAME_NOT_RESOLVED, AddressList(),
- now, kFailureEntryTTL);
+ cache.Set(Key("foobar.com"), ERR_NAME_NOT_RESOLVED, AddressList(), now);
entry1 = cache.Lookup(Key("foobar.com"), base::TimeTicks());
EXPECT_FALSE(entry1 == NULL);
EXPECT_EQ(1U, cache.size());
@@ -139,8 +133,7 @@ TEST(HostCacheTest, CacheNegativeEntry) {
// Add an entry for "foobar2.com" at t=5.
EXPECT_TRUE(cache.Lookup(Key("foobar2.com"), base::TimeTicks()) == NULL);
- cache.Set(Key("foobar2.com"), ERR_NAME_NOT_RESOLVED, AddressList(),
- now, kFailureEntryTTL);
+ cache.Set(Key("foobar2.com"), ERR_NAME_NOT_RESOLVED, AddressList(), now);
entry2 = cache.Lookup(Key("foobar2.com"), base::TimeTicks());
EXPECT_FALSE(NULL == entry1);
EXPECT_EQ(2U, cache.size());
@@ -159,8 +152,7 @@ TEST(HostCacheTest, CacheNegativeEntry) {
EXPECT_EQ(entry2, cache.Lookup(Key("foobar2.com"), now));
// Update entry1, so it is no longer expired.
- cache.Set(Key("foobar.com"), ERR_NAME_NOT_RESOLVED, AddressList(),
- now, kFailureEntryTTL);
+ cache.Set(Key("foobar.com"), ERR_NAME_NOT_RESOLVED, AddressList(), now);
// Re-uses existing entry storage.
EXPECT_EQ(entry1, cache.Lookup(Key("foobar.com"), now));
EXPECT_EQ(2U, cache.size());
@@ -178,9 +170,7 @@ TEST(HostCacheTest, CacheNegativeEntry) {
TEST(HostCacheTest, Compact) {
// Initial entries limit is big enough to accomadate everything we add.
- const base::TimeDelta kSuccessEntryTTL = base::TimeDelta::FromSeconds(10);
- const base::TimeDelta kFailureEntryTTL = base::TimeDelta::FromSeconds(0);
- HostCache cache(kMaxCacheEntries);
+ HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL);
EXPECT_EQ(0U, cache.size());
@@ -190,7 +180,7 @@ TEST(HostCacheTest, Compact) {
// Add five valid entries at t=10.
for (int i = 0; i < 5; ++i) {
std::string hostname = base::StringPrintf("valid%d", i);
- cache.Set(Key(hostname), OK, AddressList(), now, kSuccessEntryTTL);
+ cache.Set(Key(hostname), OK, AddressList(), now);
}
EXPECT_EQ(5U, cache.size());
@@ -198,15 +188,14 @@ TEST(HostCacheTest, Compact) {
for (int i = 0; i < 3; ++i) {
std::string hostname = base::StringPrintf("expired%d", i);
base::TimeTicks t = now - base::TimeDelta::FromSeconds(10);
- cache.Set(Key(hostname), OK, AddressList(), t, kSuccessEntryTTL);
+ cache.Set(Key(hostname), OK, AddressList(), t);
}
EXPECT_EQ(8U, cache.size());
// Add 2 negative entries at t=10
for (int i = 0; i < 2; ++i) {
std::string hostname = base::StringPrintf("negative%d", i);
- cache.Set(Key(hostname), ERR_NAME_NOT_RESOLVED, AddressList(),
- now, kFailureEntryTTL);
+ cache.Set(Key(hostname), ERR_NAME_NOT_RESOLVED, AddressList(), now);
}
EXPECT_EQ(10U, cache.size());
@@ -247,16 +236,14 @@ TEST(HostCacheTest, Compact) {
// Add entries while the cache is at capacity, causing evictions.
TEST(HostCacheTest, SetWithCompact) {
- const base::TimeDelta kTTL = base::TimeDelta::FromSeconds(10);
-
- HostCache cache(3);
+ HostCache cache(3, kSuccessEntryTTL, kFailureEntryTTL);
// t=10
- base::TimeTicks now = base::TimeTicks() + kTTL;
+ base::TimeTicks now = base::TimeTicks() + kSuccessEntryTTL;
- cache.Set(Key("host1"), OK, AddressList(), now, kTTL);
- cache.Set(Key("host2"), OK, AddressList(), now, kTTL);
- cache.Set(Key("expired"), OK, AddressList(), now, kTTL - kTTL);
+ cache.Set(Key("host1"), OK, AddressList(), now);
+ cache.Set(Key("host2"), OK, AddressList(), now);
+ cache.Set(Key("expired"), OK, AddressList(), now - kSuccessEntryTTL);
EXPECT_EQ(3U, cache.size());
@@ -266,7 +253,7 @@ TEST(HostCacheTest, SetWithCompact) {
EXPECT_TRUE(NULL == cache.Lookup(Key("expired"), now));
// Adding the fourth entry will cause "expired" to be evicted.
- cache.Set(Key("host3"), OK, AddressList(), now, kTTL);
+ cache.Set(Key("host3"), OK, AddressList(), now);
EXPECT_EQ(3U, cache.size());
EXPECT_TRUE(cache.Lookup(Key("expired"), now) == NULL);
EXPECT_FALSE(cache.Lookup(Key("host1"), now) == NULL);
@@ -275,9 +262,9 @@ TEST(HostCacheTest, SetWithCompact) {
// Add two more entries. Something should be evicted, however "host5"
// should definitely be in there (since it was last inserted).
- cache.Set(Key("host4"), OK, AddressList(), now, kTTL);
+ cache.Set(Key("host4"), OK, AddressList(), now);
EXPECT_EQ(3U, cache.size());
- cache.Set(Key("host5"), OK, AddressList(), now, kTTL);
+ cache.Set(Key("host5"), OK, AddressList(), now);
EXPECT_EQ(3U, cache.size());
EXPECT_FALSE(cache.Lookup(Key("host5"), now) == NULL);
}
@@ -285,9 +272,7 @@ TEST(HostCacheTest, SetWithCompact) {
// Tests that the same hostname can be duplicated in the cache, so long as
// the address family differs.
TEST(HostCacheTest, AddressFamilyIsPartOfKey) {
- const base::TimeDelta kSuccessEntryTTL = base::TimeDelta::FromSeconds(10);
-
- HostCache cache(kMaxCacheEntries);
+ HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL);
// t=0.
base::TimeTicks now;
@@ -302,14 +287,14 @@ TEST(HostCacheTest, AddressFamilyIsPartOfKey) {
// Add an entry for ("foobar.com", UNSPECIFIED) at t=0.
EXPECT_TRUE(cache.Lookup(key1, base::TimeTicks()) == NULL);
- cache.Set(key1, OK, AddressList(), now, kSuccessEntryTTL);
+ cache.Set(key1, OK, AddressList(), now);
entry1 = cache.Lookup(key1, base::TimeTicks());
EXPECT_FALSE(entry1 == NULL);
EXPECT_EQ(1U, cache.size());
// Add an entry for ("foobar.com", IPV4_ONLY) at t=0.
EXPECT_TRUE(cache.Lookup(key2, base::TimeTicks()) == NULL);
- cache.Set(key2, OK, AddressList(), now, kSuccessEntryTTL);
+ cache.Set(key2, OK, AddressList(), now);
entry2 = cache.Lookup(key2, base::TimeTicks());
EXPECT_FALSE(entry2 == NULL);
EXPECT_EQ(2U, cache.size());
@@ -322,9 +307,7 @@ TEST(HostCacheTest, AddressFamilyIsPartOfKey) {
// Tests that the same hostname can be duplicated in the cache, so long as
// the HostResolverFlags differ.
TEST(HostCacheTest, HostResolverFlagsArePartOfKey) {
- const base::TimeDelta kTTL = base::TimeDelta::FromSeconds(10);
-
- HostCache cache(kMaxCacheEntries);
+ HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL);
// t=0.
base::TimeTicks now;
@@ -343,21 +326,21 @@ TEST(HostCacheTest, HostResolverFlagsArePartOfKey) {
// Add an entry for ("foobar.com", IPV4, NONE) at t=0.
EXPECT_TRUE(cache.Lookup(key1, base::TimeTicks()) == NULL);
- cache.Set(key1, OK, AddressList(), now, kTTL);
+ cache.Set(key1, OK, AddressList(), now);
entry1 = cache.Lookup(key1, base::TimeTicks());
EXPECT_FALSE(entry1 == NULL);
EXPECT_EQ(1U, cache.size());
// Add an entry for ("foobar.com", IPV4, CANONNAME) at t=0.
EXPECT_TRUE(cache.Lookup(key2, base::TimeTicks()) == NULL);
- cache.Set(key2, OK, AddressList(), now, kTTL);
+ cache.Set(key2, OK, AddressList(), now);
entry2 = cache.Lookup(key2, base::TimeTicks());
EXPECT_FALSE(entry2 == NULL);
EXPECT_EQ(2U, cache.size());
// Add an entry for ("foobar.com", IPV4, LOOPBACK_ONLY) at t=0.
EXPECT_TRUE(cache.Lookup(key3, base::TimeTicks()) == NULL);
- cache.Set(key3, OK, AddressList(), now, kTTL);
+ cache.Set(key3, OK, AddressList(), now);
entry3 = cache.Lookup(key3, base::TimeTicks());
EXPECT_FALSE(entry3 == NULL);
EXPECT_EQ(3U, cache.size());
@@ -371,9 +354,7 @@ TEST(HostCacheTest, HostResolverFlagsArePartOfKey) {
TEST(HostCacheTest, NoCache) {
// Disable caching.
- const base::TimeDelta kTTL = base::TimeDelta::FromSeconds(10);
-
- HostCache cache(0);
+ HostCache cache(0, kSuccessEntryTTL, kFailureEntryTTL);
EXPECT_TRUE(cache.caching_is_disabled());
// Set t=0.
@@ -381,16 +362,14 @@ TEST(HostCacheTest, NoCache) {
// Lookup and Set should have no effect.
EXPECT_TRUE(cache.Lookup(Key("foobar.com"), base::TimeTicks()) == NULL);
- cache.Set(Key("foobar.com"), OK, AddressList(), now, kTTL);
+ cache.Set(Key("foobar.com"), OK, AddressList(), now);
EXPECT_TRUE(cache.Lookup(Key("foobar.com"), base::TimeTicks()) == NULL);
EXPECT_EQ(0U, cache.size());
}
TEST(HostCacheTest, Clear) {
- const base::TimeDelta kTTL = base::TimeDelta::FromSeconds(10);
-
- HostCache cache(kMaxCacheEntries);
+ HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL);
// Set t=0.
base::TimeTicks now;
@@ -398,9 +377,9 @@ TEST(HostCacheTest, Clear) {
EXPECT_EQ(0u, cache.size());
// Add three entries.
- cache.Set(Key("foobar1.com"), OK, AddressList(), now, kTTL);
- cache.Set(Key("foobar2.com"), OK, AddressList(), now, kTTL);
- cache.Set(Key("foobar3.com"), OK, AddressList(), now, kTTL);
+ cache.Set(Key("foobar1.com"), OK, AddressList(), now);
+ cache.Set(Key("foobar2.com"), OK, AddressList(), now);
+ cache.Set(Key("foobar3.com"), OK, AddressList(), now);
EXPECT_EQ(3u, cache.size());
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc
index af75022..217f1e1 100644
--- a/net/base/host_resolver_impl.cc
+++ b/net/base/host_resolver_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -50,9 +50,6 @@ namespace {
// some platform's resolvers.
const size_t kMaxHostLength = 4096;
-// Default TTL for successful resolutions with ProcTask.
-const base::TimeDelta kCacheEntryTTL = base::TimeDelta::FromMinutes(1);
-
// Helper to mutate the linked list contained by AddressList to the given
// port. Note that in general this is dangerous since the AddressList's
// data might be shared (and you should use AddressList::SetPort).
@@ -1356,14 +1353,9 @@ void HostResolverImpl::OnJobComplete(Job* job,
RemoveOutstandingJob(job);
// Write result to the cache.
- if (cache_.get()) {
- base::TimeDelta ttl = base::TimeDelta::FromSeconds(0);
- if (net_error == OK)
- ttl = kCacheEntryTTL;
- cache_->Set(job->key(), net_error, addrlist,
- base::TimeTicks::Now(),
- ttl);
- }
+ if (cache_.get())
+ cache_->Set(job->key(), net_error, addrlist, base::TimeTicks::Now());
+
OnJobCompleteInternal(job, net_error, os_error, addrlist);
}
diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc
index 7af8f14..612c600 100644
--- a/net/base/mock_host_resolver.cc
+++ b/net/base/mock_host_resolver.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -22,11 +22,6 @@ namespace net {
namespace {
-// Cache size for the MockCachingHostResolver.
-const unsigned kMaxCacheEntries = 100;
-// TTL for the successful resolutions. Failures are not cached.
-const base::TimeDelta kCacheEntryTTL = base::TimeDelta::FromMinutes(1);
-
char* do_strdup(const char* src) {
#if defined(OS_WIN)
return _strdup(src);
@@ -135,7 +130,10 @@ MockHostResolverBase::MockHostResolverBase(bool use_caching)
proc_ = rules_;
if (use_caching) {
- cache_.reset(new HostCache(kMaxCacheEntries));
+ cache_.reset(new HostCache(
+ 100, // max entries.
+ base::TimeDelta::FromMinutes(1),
+ base::TimeDelta::FromSeconds(0)));
}
}
@@ -175,10 +173,7 @@ int MockHostResolverBase::ResolveProc(size_t id,
HostCache::Key key(info.hostname(),
info.address_family(),
info.host_resolver_flags());
- // Storing a failure with TTL 0 so that it overwrites previous value.
- cache_->Set(key, rv, addr,
- base::TimeTicks::Now(),
- (rv == OK) ? kCacheEntryTTL : base::TimeDelta());
+ cache_->Set(key, rv, addr, base::TimeTicks::Now());
}
if (rv == OK)
*addresses = CreateAddressListUsingPort(addr, info.port());