From 0bcd33eacb640e709f36abf3f8d3e88ecd34efef Mon Sep 17 00:00:00 2001 From: "rvargas@google.com" Date: Thu, 6 Aug 2009 18:48:37 +0000 Subject: Disk Cache: Don't depend on the backend being enabled to be able to return the key of an open entry. Whenever a critical corruption is detected by the disk cache, the backend disables itself and starts failing all requests until it's able to re-create the backing store. Key's longer than 928 bytes are not stored inside the entry itself, so a file object is required to access them. The backend will reject any request for a file object after it is disabled, so a user's request for the key of an open entry will also fail. Now we keep a pointer to the related file object (if needed) so that we don't have to ask the backend for it when the user requests the current key. BUG=9952 TEST=unittest Review URL: http://codereview.chromium.org/165030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22637 0039d316-1c4b-4281-b951-d872f2087c98 --- net/disk_cache/backend_unittest.cc | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'net/disk_cache/backend_unittest.cc') diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index 0747d04..ec9b61e 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -67,6 +67,7 @@ class DiskCacheBackendTest : public DiskCacheTestWithCache { void BackendDisable(); void BackendDisable2(); void BackendDisable3(); + void BackendDisable4(); }; void DiskCacheBackendTest::BackendBasics() { @@ -1324,6 +1325,71 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { BackendDisable3(); } +// If we disable the cache, already open entries should work as far as possible. +void DiskCacheBackendTest::BackendDisable4() { + disk_cache::Entry *entry1, *entry2, *entry3, *entry4; + void* iter = NULL; + ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1)); + + char key2[2000]; + char key3[20000]; + CacheTestFillBuffer(key2, sizeof(key2), true); + CacheTestFillBuffer(key3, sizeof(key3), true); + key2[sizeof(key2) - 1] = '\0'; + key3[sizeof(key3) - 1] = '\0'; + ASSERT_TRUE(cache_->CreateEntry(key2, &entry2)); + ASSERT_TRUE(cache_->CreateEntry(key3, &entry3)); + + const int kBufSize = 20000; + scoped_refptr buf = new net::IOBuffer(kBufSize); + memset(buf->data(), 0, kBufSize); + EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false)); + EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false)); + + // This line should disable the cache but not delete it. + EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry4)); + EXPECT_EQ(4, cache_->GetEntryCount()); + + EXPECT_FALSE(cache_->CreateEntry("cache is disabled", &entry4)); + + EXPECT_EQ(100, entry2->ReadData(0, 0, buf, 100, NULL)); + EXPECT_EQ(100, entry2->WriteData(0, 0, buf, 100, NULL, false)); + EXPECT_EQ(100, entry2->WriteData(1, 0, buf, 100, NULL, false)); + + EXPECT_EQ(kBufSize, entry3->ReadData(0, 0, buf, kBufSize, NULL)); + EXPECT_EQ(kBufSize, entry3->WriteData(0, 0, buf, kBufSize, NULL, false)); + EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false)); + + std::string key = entry2->GetKey(); + EXPECT_EQ(sizeof(key2) - 1, key.size()); + key = entry3->GetKey(); + EXPECT_EQ(sizeof(key3) - 1, key.size()); + + entry1->Close(); + entry2->Close(); + entry3->Close(); + MessageLoop::current()->RunAllPending(); + + EXPECT_EQ(0, cache_->GetEntryCount()); +} + +TEST_F(DiskCacheBackendTest, DisableSuccess4) { + ASSERT_TRUE(CopyTestCache(L"bad_rankings")); + DisableFirstCleanup(); + SetDirectMode(); + InitCache(); + BackendDisable4(); +} + +TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) { + ASSERT_TRUE(CopyTestCache(L"bad_rankings")); + DisableFirstCleanup(); + SetDirectMode(); + SetNewEviction(); + InitCache(); + BackendDisable4(); +} + TEST_F(DiskCacheTest, Backend_UsageStats) { MessageLoopHelper helper; -- cgit v1.1