summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-02 18:17:18 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-02 18:17:18 +0000
commitffd77f7a08e63b7bc531f6c463c39a794a21b6d1 (patch)
tree02efef3f71d5cca8cd0837dab1738585b2ed128c /net/disk_cache
parenta23f3031457f6518580a976204c099bb43069dd2 (diff)
downloadchromium_src-ffd77f7a08e63b7bc531f6c463c39a794a21b6d1.zip
chromium_src-ffd77f7a08e63b7bc531f6c463c39a794a21b6d1.tar.gz
chromium_src-ffd77f7a08e63b7bc531f6c463c39a794a21b6d1.tar.bz2
If a disk cache entry is stored as an external file, and it is reused (open/truncate/write/close), the current cache size should be modified accordingly. I'm also bumping up the version number for the cache files, to force re-creation with this revision.
BUG=1305909 TEST=Unit test. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/disk_format.h2
-rw-r--r--net/disk_cache/entry_impl.cc2
-rw-r--r--net/disk_cache/entry_unittest.cc41
3 files changed, 43 insertions, 2 deletions
diff --git a/net/disk_cache/disk_format.h b/net/disk_cache/disk_format.h
index 4546c88..e23caa9 100644
--- a/net/disk_cache/disk_format.h
+++ b/net/disk_cache/disk_format.h
@@ -88,7 +88,7 @@ typedef uint32 CacheAddr;
const int kIndexTablesize = 0x10000;
const uint32 kIndexMagic = 0xC103CAC3;
-const uint32 kCurrentVersion = 0x10002; // Version 1.2.
+const uint32 kCurrentVersion = 0x10003; // Version 1.3.
// Header for the master index file.
struct IndexHeader {
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index 75ab5ab..58509c1 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -699,9 +699,9 @@ bool EntryImpl::MoveToLocalBuffer(int index) {
bool EntryImpl::ImportSeparateFile(int index, int offset, int buf_len) {
if (entry_.Data()->data_size[index] > offset + buf_len) {
- entry_.Data()->data_size[index] = offset + buf_len;
unreported_size_[index] += offset + buf_len -
entry_.Data()->data_size[index];
+ entry_.Data()->data_size[index] = offset + buf_len;
}
if (!MoveToLocalBuffer(index))
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index d2eea79..b61c657 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -48,6 +48,7 @@ class DiskCacheEntryTest : public DiskCacheTestBase {
void GetKey();
void GrowData();
void TruncateData();
+ void ReuseEntry();
void InvalidData();
void DoomEntry();
void DoomedEntry();
@@ -571,6 +572,46 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyTruncateData) {
TruncateData();
}
+// Write more than the total cache capacity but to a single entry.
+void DiskCacheEntryTest::ReuseEntry() {
+ std::string key1("the first key");
+ disk_cache::Entry *entry;
+ ASSERT_TRUE(cache_->CreateEntry(key1, &entry));
+
+ entry->Close();
+ std::string key2("the second key");
+ ASSERT_TRUE(cache_->CreateEntry(key2, &entry));
+
+ char buffer[20000];
+ CacheTestFillBuffer(buffer, sizeof(buffer), false);
+
+ for (int i = 0; i < 15; i++) {
+ EXPECT_EQ(0, entry->WriteData(0, 0, buffer, 0, NULL, true));
+ EXPECT_EQ(20000, entry->WriteData(0, 0, buffer, 20000, NULL, false));
+ entry->Close();
+ ASSERT_TRUE(cache_->OpenEntry(key2, &entry));
+ }
+
+ entry->Close();
+ ASSERT_TRUE(cache_->OpenEntry(key1, &entry)) << "have not evicted this entry";
+ entry->Close();
+}
+
+TEST_F(DiskCacheEntryTest, ReuseEntry) {
+ SetDirectMode();
+ SetMaxSize(200 * 1024);
+ InitCache();
+ ReuseEntry();
+}
+
+TEST_F(DiskCacheEntryTest, MemoryOnlyReuseEntry) {
+ SetDirectMode();
+ SetMemoryOnlyMode();
+ SetMaxSize(200 * 1024);
+ InitCache();
+ ReuseEntry();
+}
+
// Reading somewhere that was not written should return zeros.
void DiskCacheEntryTest::InvalidData() {
std::string key1("the first key");