diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-12 21:50:46 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-12 21:50:46 +0000 |
commit | cedecee0bb17e86938fed12c7cdb79b429cdbc27 (patch) | |
tree | c7d8d616982b3a4c133359990cbfacbbf0bd8b6d /net | |
parent | b09505afecd3407aef9603f38907b01eb78222e5 (diff) | |
download | chromium_src-cedecee0bb17e86938fed12c7cdb79b429cdbc27.zip chromium_src-cedecee0bb17e86938fed12c7cdb79b429cdbc27.tar.gz chromium_src-cedecee0bb17e86938fed12c7cdb79b429cdbc27.tar.bz2 |
Http cache: Fix the last access time for the infinite cache simulation.
For cached responses, the request time matches the cache revalidation time so
we use the current time instead.
BUG=147383
TEST=none
Review URL: https://codereview.chromium.org/11091053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161660 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/http/infinite_cache.cc | 46 | ||||
-rw-r--r-- | net/http/infinite_cache_unittest.cc | 19 |
2 files changed, 41 insertions, 24 deletions
diff --git a/net/http/infinite_cache.cc b/net/http/infinite_cache.cc index 5d25cee..9f491c8 100644 --- a/net/http/infinite_cache.cc +++ b/net/http/infinite_cache.cc @@ -336,8 +336,11 @@ void InfiniteCacheTransaction::OnServedFromCache( return; resource_data_->details.flags |= CACHED; - if (!resource_data_->details.last_access) + if (!resource_data_->details.last_access) { OnResponseReceived(response); + // For cached responses, the request time is the last revalidation time. + resource_data_->details.last_access = TimeToInt(Time::Now()); + } } void InfiniteCacheTransaction::Finish() { @@ -456,6 +459,7 @@ class InfiniteCache::Worker : public base::RefCountedThreadSafe<Worker> { void InfiniteCache::Worker::Init(const FilePath& path) { path_ = path; LoadData(); + UMA_HISTOGRAM_BOOLEAN("InfiniteCache.NewSession", true); } void InfiniteCache::Worker::Cleanup() { @@ -509,9 +513,10 @@ void InfiniteCache::Worker::Process( if (data->details.response_size > kMaxTrackingSize) return; - if (header_->num_entries == kMaxNumEntries) + if (header_->num_entries == kMaxNumEntries || header_->disabled) return; + UMA_HISTOGRAM_BOOLEAN("InfiniteCache.TotalRequests", true); header_->num_requests++; KeyMap::iterator i = map_.find(data->key); if (i != map_.end()) { @@ -569,8 +574,10 @@ void InfiniteCache::Worker::LoadData() { if (!ReadData(file)) InitializeData(); base::ClosePlatformFile(file); - if (header_->disabled) + if (header_->disabled) { + UMA_HISTOGRAM_BOOLEAN("InfiniteCache.Full", true); map_.clear(); + } } void InfiniteCache::Worker::StoreData() { @@ -789,20 +796,20 @@ void InfiniteCache::Worker::RecordHit(const Details& old, Details* details) { int access_delta = (IntToTime(details->last_access) - IntToTime(old.last_access)).InMinutes(); if (old.use_count) { - UMA_HISTOGRAM_COUNTS("InfiniteCache.ReuseAge", access_delta); + UMA_HISTOGRAM_COUNTS("InfiniteCache.ReuseAge2", access_delta); if (details->flags & GA_JS_HTTP) { - UMA_HISTOGRAM_COUNTS("InfiniteCache.GaJsHttpReuseAge", access_delta); + UMA_HISTOGRAM_COUNTS("InfiniteCache.GaJsHttpReuseAge2", access_delta); } else if (details->flags & GA_JS_HTTPS) { - UMA_HISTOGRAM_COUNTS("InfiniteCache.GaJsHttpsReuseAge", access_delta); + UMA_HISTOGRAM_COUNTS("InfiniteCache.GaJsHttpsReuseAge2", access_delta); } } else { - UMA_HISTOGRAM_COUNTS("InfiniteCache.FirstReuseAge", access_delta); + UMA_HISTOGRAM_COUNTS("InfiniteCache.FirstReuseAge2", access_delta); if (details->flags & GA_JS_HTTP) { UMA_HISTOGRAM_COUNTS( - "InfiniteCache.GaJsHttpFirstReuseAge", access_delta); + "InfiniteCache.GaJsHttpFirstReuseAge2", access_delta); } else if (details->flags & GA_JS_HTTPS) { UMA_HISTOGRAM_COUNTS( - "InfiniteCache.GaJsHttpsFirstReuseAge", access_delta); + "InfiniteCache.GaJsHttpsFirstReuseAge2", access_delta); } } @@ -824,22 +831,22 @@ void InfiniteCache::Worker::RecordUpdate(const Details& old, Details* details) { int access_delta = (IntToTime(details->last_access) - IntToTime(old.last_access)).InMinutes(); if (old.update_count) { - UMA_HISTOGRAM_COUNTS("InfiniteCache.UpdateAge", access_delta); + UMA_HISTOGRAM_COUNTS("InfiniteCache.UpdateAge2", access_delta); if (details->flags & GA_JS_HTTP) { UMA_HISTOGRAM_COUNTS( - "InfiniteCache.GaJsHttpUpdateAge", access_delta); + "InfiniteCache.GaJsHttpUpdateAge2", access_delta); } else if (details->flags & GA_JS_HTTPS) { UMA_HISTOGRAM_COUNTS( - "InfiniteCache.GaJsHttpsUpdateAge", access_delta); + "InfiniteCache.GaJsHttpsUpdateAge2", access_delta); } } else { - UMA_HISTOGRAM_COUNTS("InfiniteCache.FirstUpdateAge", access_delta); + UMA_HISTOGRAM_COUNTS("InfiniteCache.FirstUpdateAge2", access_delta); if (details->flags & GA_JS_HTTP) { UMA_HISTOGRAM_COUNTS( - "InfiniteCache.GaJsHttpFirstUpdateAge", access_delta); + "InfiniteCache.GaJsHttpFirstUpdateAge2", access_delta); } else if (details->flags & GA_JS_HTTPS) { UMA_HISTOGRAM_COUNTS( - "InfiniteCache.GaJsHttpsFirstUpdateAge", access_delta); + "InfiniteCache.GaJsHttpsFirstUpdateAge2", access_delta); } } @@ -927,8 +934,7 @@ bool InfiniteCache::Worker::CanReuse(const Details& old, }; int reason = REUSE_OK; - Time expiration = IntToTime(old.expiration); - if (expiration < Time::Now()) + if (old.expiration < current.last_access) reason = REUSE_EXPIRED; if (old.flags & EXPIRED) @@ -947,13 +953,13 @@ bool InfiniteCache::Worker::CanReuse(const Details& old, if (reason && (old.flags & REVALIDATEABLE) && !have_to_drop) reason += REUSE_REVALIDATEABLE; - UMA_HISTOGRAM_ENUMERATION("InfiniteCache.ReuseFailure", reason, 15); + UMA_HISTOGRAM_ENUMERATION("InfiniteCache.ReuseFailure2", reason, 15); if (current.flags & GA_JS_HTTP) { UMA_HISTOGRAM_ENUMERATION( - "InfiniteCache.GaJsHttpReuseFailure", reason, 15); + "InfiniteCache.GaJsHttpReuseFailure2", reason, 15); } else if (current.flags & GA_JS_HTTPS) { UMA_HISTOGRAM_ENUMERATION( - "InfiniteCache.GaJsHttpsReuseFailure", reason, 15); + "InfiniteCache.GaJsHttpsReuseFailure2", reason, 15); } return !reason; } diff --git a/net/http/infinite_cache_unittest.cc b/net/http/infinite_cache_unittest.cc index b178c61..707f248 100644 --- a/net/http/infinite_cache_unittest.cc +++ b/net/http/infinite_cache_unittest.cc @@ -11,6 +11,7 @@ #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "net/http/http_transaction_unittest.h" +#include "net/http/http_util.h" #include "testing/gtest/include/gtest/gtest.h" using base::Time; @@ -22,13 +23,21 @@ namespace { void StartRequest(const MockTransaction& http_transaction, InfiniteCacheTransaction* transaction) { + std::string standard_headers(http_transaction.status); + standard_headers.push_back('\n'); + standard_headers.append(http_transaction.response_headers); + std::string raw_headers = + net::HttpUtil::AssembleRawHeaders(standard_headers.c_str(), + standard_headers.size()); + scoped_refptr<net::HttpResponseHeaders> headers( - new net::HttpResponseHeaders(http_transaction.response_headers)); + new net::HttpResponseHeaders(raw_headers)); net::HttpResponseInfo response; response.headers = headers; response.request_time = http_transaction.request_time.is_null() ? Time::Now() : http_transaction.request_time; - response.response_time = Time::Now(); + response.response_time = http_transaction.response_time.is_null() ? + Time::Now() : http_transaction.response_time; MockHttpRequest request(http_transaction); transaction->OnRequestStart(&request); @@ -52,6 +61,7 @@ void ProcessRequestWithTime(const MockTransaction& http_transaction, MockTransaction timed_transaction = http_transaction; timed_transaction.request_time = time; + timed_transaction.response_time = time; StartRequest(timed_transaction, transaction.get()); transaction->OnDataRead(http_transaction.data, strlen(http_transaction.data)); } @@ -202,7 +212,7 @@ TEST(InfiniteCache, DeleteBetween) { Time end = start + TimeDelta::FromSeconds(2); ProcessRequestWithTime(kETagGET_Transaction, cache.get(), - end + TimeDelta::FromSeconds(2)); + end + TimeDelta::FromSeconds(2)); EXPECT_EQ(3, cb.GetResult(cache->QueryItemsForTest(cb.callback()))); EXPECT_EQ(net::OK, @@ -216,7 +226,8 @@ TEST(InfiniteCache, DeleteBetween) { cache->Init(path); EXPECT_EQ(2, cb.GetResult(cache->QueryItemsForTest(cb.callback()))); - ProcessRequest(kETagGET_Transaction, cache.get()); + ProcessRequestWithTime(kETagGET_Transaction, cache.get(), + end + TimeDelta::FromMinutes(5)); EXPECT_EQ(2, cb.GetResult(cache->QueryItemsForTest(cb.callback()))); EXPECT_EQ(net::OK, |