diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 20:42:58 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 20:42:58 +0000 |
commit | 40caa4c2b0101f6c0fb88db9dd82bfdb2ad8f11b (patch) | |
tree | e9f9dd8043271b1bd06ae90a1bf8370479adb814 /net/http | |
parent | f64ecd4e6610a4f1990b87be11b2d5ee41194e07 (diff) | |
download | chromium_src-40caa4c2b0101f6c0fb88db9dd82bfdb2ad8f11b.zip chromium_src-40caa4c2b0101f6c0fb88db9dd82bfdb2ad8f11b.tar.gz chromium_src-40caa4c2b0101f6c0fb88db9dd82bfdb2ad8f11b.tar.bz2 |
Http cache: Restart transaction after errors reading from cached
data if we have not start validation yet.
BUG=110795
TEST=net_unittests
Review URL: https://chromiumcodereview.appspot.com/9734002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127772 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_cache_transaction.cc | 21 | ||||
-rw-r--r-- | net/http/http_cache_transaction.h | 5 | ||||
-rw-r--r-- | net/http/http_cache_unittest.cc | 10 |
3 files changed, 24 insertions, 12 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc index dbb6d2e..f6a8efc 100644 --- a/net/http/http_cache_transaction.cc +++ b/net/http/http_cache_transaction.cc @@ -1213,7 +1213,7 @@ int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { if (result != io_buf_len_ || !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, &response_, &truncated_)) { - return OnCacheReadError(result); + return OnCacheReadError(result, true); } // Some resources may have slipped in as truncated when they're not. @@ -1299,7 +1299,7 @@ int HttpCache::Transaction::DoCacheReadMetadata() { int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); if (result != response_.metadata->size()) - return OnCacheReadError(result);; + return OnCacheReadError(result, false); return OK; } @@ -1352,7 +1352,7 @@ int HttpCache::Transaction::DoCacheReadDataComplete(int result) { cache_->DoneReadingFromEntry(entry_, this); entry_ = NULL; } else { - return OnCacheReadError(result); + return OnCacheReadError(result, false); } return result; } @@ -2021,13 +2021,24 @@ void HttpCache::Transaction::DoneWritingToEntry(bool success) { mode_ = NONE; // switch to 'pass through' mode } -int HttpCache::Transaction::OnCacheReadError(int result) { +int HttpCache::Transaction::OnCacheReadError(int result, bool restart) { DLOG(ERROR) << "ReadData failed: " << result; // Avoid using this entry in the future. if (cache_) cache_->DoomActiveEntry(cache_key_); + if (restart) { + DCHECK(!reading_); + DCHECK(!network_trans_.get()); + cache_->DoneWithEntry(entry_, this, false); + entry_ = NULL; + is_sparse_ = false; + partial_.reset(); + next_state_ = STATE_GET_BACKEND; + return OK; + } + return ERR_CACHE_READ_FAILURE; } @@ -2060,7 +2071,7 @@ int HttpCache::Transaction::DoPartialCacheReadCompleted(int result) { // We need to move on to the next range. next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; } else if (result < 0) { - return OnCacheReadError(result); + return OnCacheReadError(result, false); } return result; } diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h index 69cf40d..531601e 100644 --- a/net/http/http_cache_transaction.h +++ b/net/http/http_cache_transaction.h @@ -308,8 +308,9 @@ class HttpCache::Transaction : public HttpTransaction { void DoneWritingToEntry(bool success); // Returns an error to signal the caller that the current read failed. The - // current operation |result| is also logged. - int OnCacheReadError(int result); + // current operation |result| is also logged. If |restart| is true, the + // transaction should be restarted. + int OnCacheReadError(int result, bool restart); // Deletes the current partial cache entry (sparse), and optionally removes // the control object (partial_). diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc index dacd057..0f4b8e7 100644 --- a/net/http/http_cache_unittest.cc +++ b/net/http/http_cache_unittest.cc @@ -550,20 +550,20 @@ TEST(HttpCache, SimpleGETWithDiskFailures3) { MockHttpRequest request(kSimpleGET_Transaction); rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog()); - EXPECT_EQ(net::ERR_CACHE_READ_FAILURE, c->callback.GetResult(rv)); + EXPECT_EQ(net::OK, c->callback.GetResult(rv)); // Now verify that the entry was removed from the cache. cache.disk_cache()->set_soft_failures(false); - EXPECT_EQ(1, cache.network_layer()->transaction_count()); + EXPECT_EQ(2, cache.network_layer()->transaction_count()); EXPECT_EQ(1, cache.disk_cache()->open_count()); - EXPECT_EQ(1, cache.disk_cache()->create_count()); + EXPECT_EQ(2, cache.disk_cache()->create_count()); RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); - EXPECT_EQ(2, cache.network_layer()->transaction_count()); + EXPECT_EQ(3, cache.network_layer()->transaction_count()); EXPECT_EQ(1, cache.disk_cache()->open_count()); - EXPECT_EQ(2, cache.disk_cache()->create_count()); + EXPECT_EQ(3, cache.disk_cache()->create_count()); } TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) { |