summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 01:32:25 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 01:32:25 +0000
commitdc8b936deddb16343b09df857bbdd75f11f9408d (patch)
tree813e0f7a7d4cd466133e9742c84944f7655078e1 /net/disk_cache
parent266bc72a27ab755abfcad858d702c891ee2c9155 (diff)
downloadchromium_src-dc8b936deddb16343b09df857bbdd75f11f9408d.zip
chromium_src-dc8b936deddb16343b09df857bbdd75f11f9408d.tar.gz
chromium_src-dc8b936deddb16343b09df857bbdd75f11f9408d.tar.bz2
Disk cache: Reset mask_ when the disk cache is being restarted.
It is possible that the size for the index table is reduced when the cache is restarted (the available disk space could be lower than what it was when the cache was originally created). If that is the case, not resetting mask_ to 0 will prevent the mask to be set correctly for the new table size, resulting in a crash. BUG=12378 TEST=unittests Review URL: http://codereview.chromium.org/113930 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17052 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/backend_impl.cc8
-rw-r--r--net/disk_cache/backend_unittest.cc63
2 files changed, 71 insertions, 0 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index e997b90..5c64d01 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -788,6 +788,10 @@ void BackendImpl::CriticalError(int error) {
LogStats();
ReportError(error);
+ // Reset the mask_ if it was not given by the user.
+ if (mask_ == data_->header.table_len - 1)
+ mask_ = 0;
+
// Setting the index table length to an invalid value will force re-creation
// of the cache files.
data_->header.table_len = 1;
@@ -983,6 +987,10 @@ void BackendImpl::RestartCache() {
}
void BackendImpl::PrepareForRestart() {
+ // Reset the mask_ if it was not given by the user.
+ if (mask_ == data_->header.table_len - 1)
+ mask_ = 0;
+
data_->header.crash = 0;
index_ = NULL;
data_ = NULL;
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index dd33d28..2fbcfa9 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -59,10 +59,12 @@ class DiskCacheBackendTest : public DiskCacheTestWithCache {
void BackendInvalidEntry2();
void BackendNotMarkedButDirty();
void BackendDoomAll();
+ void BackendDoomAll2();
void BackendInvalidRankings();
void BackendInvalidRankings2();
void BackendDisable();
void BackendDisable2();
+ void BackendDisable3();
};
void DiskCacheBackendTest::BackendBasics() {
@@ -1169,6 +1171,38 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) {
BackendDisable2();
}
+// If the index size changes when we disable the cache, we should not crash.
+void DiskCacheBackendTest::BackendDisable3() {
+ disk_cache::Entry *entry1, *entry2;
+ void* iter = NULL;
+ EXPECT_EQ(2, cache_->GetEntryCount());
+ ASSERT_TRUE(cache_->OpenNextEntry(&iter, &entry1));
+ entry1->Close();
+
+ EXPECT_FALSE(cache_->OpenNextEntry(&iter, &entry2));
+ ASSERT_TRUE(cache_->CreateEntry("Something new", &entry2));
+ entry2->Close();
+
+ EXPECT_EQ(1, cache_->GetEntryCount());
+}
+
+TEST_F(DiskCacheBackendTest, DisableSuccess3) {
+ ASSERT_TRUE(CopyTestCache(L"bad_rankings2"));
+ DisableFirstCleanup();
+ SetMaxSize(20 * 1024 * 1024);
+ InitCache();
+ BackendDisable3();
+}
+
+TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) {
+ ASSERT_TRUE(CopyTestCache(L"bad_rankings2"));
+ DisableFirstCleanup();
+ SetMaxSize(20 * 1024 * 1024);
+ SetNewEviction();
+ InitCache();
+ BackendDisable3();
+}
+
TEST_F(DiskCacheTest, Backend_UsageStats) {
MessageLoopHelper helper;
@@ -1240,6 +1274,35 @@ TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) {
BackendDoomAll();
}
+// If the index size changes when we doom the cache, we should not crash.
+void DiskCacheBackendTest::BackendDoomAll2() {
+ EXPECT_EQ(2, cache_->GetEntryCount());
+ EXPECT_TRUE(cache_->DoomAllEntries());
+
+ disk_cache::Entry* entry;
+ ASSERT_TRUE(cache_->CreateEntry("Something new", &entry));
+ entry->Close();
+
+ EXPECT_EQ(1, cache_->GetEntryCount());
+}
+
+TEST_F(DiskCacheBackendTest, DoomAll2) {
+ ASSERT_TRUE(CopyTestCache(L"bad_rankings2"));
+ DisableFirstCleanup();
+ SetMaxSize(20 * 1024 * 1024);
+ InitCache();
+ BackendDoomAll2();
+}
+
+TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) {
+ ASSERT_TRUE(CopyTestCache(L"bad_rankings2"));
+ DisableFirstCleanup();
+ SetMaxSize(20 * 1024 * 1024);
+ SetNewEviction();
+ InitCache();
+ BackendDoomAll2();
+}
+
// We should be able to create the same entry on multiple simultaneous instances
// of the cache.
TEST_F(DiskCacheTest, MultipleInstances) {