summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authormpearson <mpearson@chromium.org>2015-10-14 14:35:51 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-14 21:36:46 +0000
commit81c61dd0811b103aeca08e1a5184db725fdb19fb (patch)
tree9fa25ea5b909501de229f8beda9d561eb9f259ae /net
parent118a876ce02703c411e15101de22985da67d1eb8 (diff)
downloadchromium_src-81c61dd0811b103aeca08e1a5184db725fdb19fb.zip
chromium_src-81c61dd0811b103aeca08e1a5184db725fdb19fb.tar.gz
chromium_src-81c61dd0811b103aeca08e1a5184db725fdb19fb.tar.bz2
Revert of Implement cache counting for the simple and memory backends. (patchset #3 id:40001 of https://codereview.chromium.org/1398053002/ )
Reason for revert: Causes test failures on XP bot: https://build.chromium.org/p/chromium.win/builders/XP%20Tests%20%281%29/builds/40465/steps/net_unittests%20on%20Windows-XP-SP3/logs/DiskCacheBackendTest.SimpleCacheCalculateSizeOfAllEntries DiskCacheBackendTest.SimpleCacheCalculateSizeOfAllEntries (run #1): [ RUN ] DiskCacheBackendTest.SimpleCacheCalculateSizeOfAllEntries c:uild\slave\win_builderuild\src et\disk_cacheackend_unittest.cc(1730): error: Value of: result Actual: 7447 Expected: (count - 1) * count / 2 + total_metadata_size Which is: 7455 c:uild\slave\win_builderuild\src et\disk_cacheackend_unittest.cc(1747): error: Value of: new_result Actual: 8243 Expected: result + last_entry_size + GetEntryMetadataSize(key) Which is: 8235 c:uild\slave\win_builderuild\src et\disk_cacheackend_unittest.cc(1751): error: Value of: new_result Actual: 7455 Expected: result Which is: 7447 [ FAILED ] DiskCacheBackendTest.SimpleCacheCalculateSizeOfAllEntries (171 ms) Original issue's description: > Implement cache counting for the simple and memory backends. > > This is a followup to https://codereview.chromium.org/1304363013/, which implemented it for the blockfile backend. > > BUG=510028 > > Committed: https://crrev.com/a319545886d0e297b88301f01b804432bea602f7 > Cr-Commit-Position: refs/heads/master@{#354037} TBR=gavinp@chromium.org,pasko@chromium.org,ttuttle@chromium.org,msramek@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=510028 Review URL: https://codereview.chromium.org/1401053004 Cr-Commit-Position: refs/heads/master@{#354118}
Diffstat (limited to 'net')
-rw-r--r--net/disk_cache/backend_unittest.cc68
-rw-r--r--net/disk_cache/memory/mem_backend_impl.cc3
-rw-r--r--net/disk_cache/simple/simple_backend_impl.cc38
-rw-r--r--net/disk_cache/simple/simple_backend_impl.h4
-rw-r--r--net/disk_cache/simple/simple_index.cc5
-rw-r--r--net/disk_cache/simple/simple_index.h4
6 files changed, 54 insertions, 68 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index cf82a5b..8833729 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -89,10 +89,6 @@ class DiskCacheBackendTest : public DiskCacheTestWithCache {
std::set<std::string>* keys_to_match,
size_t* count);
- // Computes the expected size of entry metadata, i.e. the total size without
- // the actual data stored. This depends only on the entry's |key| size.
- int GetEntryMetadataSize(std::string key);
-
// Actual tests:
void BackendBasics();
void BackendKeying();
@@ -286,18 +282,6 @@ bool DiskCacheBackendTest::EnumerateAndMatchKeys(
return true;
}
-int DiskCacheBackendTest::GetEntryMetadataSize(std::string key) {
- // For blockfile and memory backends, it is just the key size.
- if (!simple_cache_mode_)
- return key.size();
-
- // For the simple cache, we must add the file header and EOF, and that for
- // every stream.
- return disk_cache::kSimpleEntryStreamCount *
- (sizeof(disk_cache::SimpleFileHeader) +
- sizeof(disk_cache::SimpleFileEOF) + key.size());
-}
-
void DiskCacheBackendTest::BackendBasics() {
InitCache();
disk_cache::Entry *entry1 = NULL, *entry2 = NULL;
@@ -1695,7 +1679,12 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
InitCache();
// The cache is initially empty.
- EXPECT_EQ(0, CalculateSizeOfAllEntries());
+ if (memory_only_ || simple_cache_mode_) {
+ // TODO(msramek): Implement.
+ EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, CalculateSizeOfAllEntries());
+ } else {
+ EXPECT_EQ(0, CalculateSizeOfAllEntries());
+ }
// Generate random entries and populate them with data of respective
// sizes 0, 1, ..., count - 1 bytes.
@@ -1708,15 +1697,10 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
scoped_refptr<net::StringIOBuffer> buffer = new net::StringIOBuffer(data);
// Alternate between writing to the first and second stream to test that
- // we are not taking just the first stream into account. For convenience,
- // the last written stream should be 0. This is because writing to
- // the stream 1 in simple cache triggers a write to the stream 0 as well.
- // This will happen asynchronously and possibly later than our call to
- // |CalculateSizeOfAllEntries|.
+ // we are not taking just the first stream into account.
disk_cache::Entry* entry;
ASSERT_EQ(net::OK, OpenEntry(key, &entry));
- ASSERT_EQ(count,
- WriteData(entry, (count + 1) % 2, 0, buffer.get(), count, true));
+ ASSERT_EQ(count, WriteData(entry, count % 2, 0, buffer.get(), count, true));
entry->Close();
++count;
@@ -1724,10 +1708,16 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
// The resulting size should be (0 + 1 + ... + count - 1) plus keys.
int result = CalculateSizeOfAllEntries();
- int total_metadata_size = 0;
- for (std::string key : key_pool)
- total_metadata_size += GetEntryMetadataSize(key);
- EXPECT_EQ((count - 1) * count / 2 + total_metadata_size, result);
+ if (memory_only_ || simple_cache_mode_) {
+ // TODO(msramek): Implement.
+ EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, result);
+ } else {
+ int total_key_size = 0;
+ for (std::string key : key_pool)
+ total_key_size += key.size();
+
+ EXPECT_EQ((count - 1) * count / 2 + total_key_size, result);
+ }
// Add another entry and test if the size is updated. Then remove it and test
// if the size is back to original value.
@@ -1744,16 +1734,32 @@ void DiskCacheBackendTest::BackendCalculateSizeOfAllEntries() {
entry->Close();
int new_result = CalculateSizeOfAllEntries();
- EXPECT_EQ(result + last_entry_size + GetEntryMetadataSize(key), new_result);
+ if (memory_only_ || simple_cache_mode_) {
+ // TODO(msramek): Implement.
+ EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, new_result);
+ } else {
+ EXPECT_EQ(result + last_entry_size + static_cast<int>(key.size()),
+ new_result);
+ }
DoomEntry(key);
new_result = CalculateSizeOfAllEntries();
- EXPECT_EQ(result, new_result);
+ if (memory_only_ || simple_cache_mode_) {
+ // TODO(msramek): Implement.
+ EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, new_result);
+ } else {
+ EXPECT_EQ(result, new_result);
+ }
}
// After dooming the entries, the size should be back to zero.
ASSERT_EQ(net::OK, DoomAllEntries());
- EXPECT_EQ(0, CalculateSizeOfAllEntries());
+ if (memory_only_ || simple_cache_mode_) {
+ // TODO(msramek): Implement.
+ EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, CalculateSizeOfAllEntries());
+ } else {
+ EXPECT_EQ(0, CalculateSizeOfAllEntries());
+ }
}
TEST_F(DiskCacheBackendTest, CalculateSizeOfAllEntries) {
diff --git a/net/disk_cache/memory/mem_backend_impl.cc b/net/disk_cache/memory/mem_backend_impl.cc
index 9948660..ca8cf1b 100644
--- a/net/disk_cache/memory/mem_backend_impl.cc
+++ b/net/disk_cache/memory/mem_backend_impl.cc
@@ -184,7 +184,8 @@ int MemBackendImpl::DoomEntriesSince(const base::Time initial_time,
int MemBackendImpl::CalculateSizeOfAllEntries(
const CompletionCallback& callback) {
- return current_size_;
+ // TODO(msramek): Implement.
+ return net::ERR_NOT_IMPLEMENTED;
}
class MemBackendImpl::MemIterator : public Backend::Iterator {
diff --git a/net/disk_cache/simple/simple_backend_impl.cc b/net/disk_cache/simple/simple_backend_impl.cc
index d1c111e..f985e58 100644
--- a/net/disk_cache/simple/simple_backend_impl.cc
+++ b/net/disk_cache/simple/simple_backend_impl.cc
@@ -442,6 +442,19 @@ int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) {
return DoomEntriesBetween(Time(), Time(), callback);
}
+void SimpleBackendImpl::IndexReadyForDoom(Time initial_time,
+ Time end_time,
+ const CompletionCallback& callback,
+ int result) {
+ if (result != net::OK) {
+ callback.Run(result);
+ return;
+ }
+ scoped_ptr<std::vector<uint64> > removed_key_hashes(
+ index_->GetEntriesBetween(initial_time, end_time).release());
+ DoomEntries(removed_key_hashes.get(), callback);
+}
+
int SimpleBackendImpl::DoomEntriesBetween(
const Time initial_time,
const Time end_time,
@@ -459,8 +472,8 @@ int SimpleBackendImpl::DoomEntriesSince(
int SimpleBackendImpl::CalculateSizeOfAllEntries(
const CompletionCallback& callback) {
- return index_->ExecuteWhenReady(base::Bind(
- &SimpleBackendImpl::IndexReadyForSizeCalculation, AsWeakPtr(), callback));
+ // TODO(msramek): Implement.
+ return net::ERR_NOT_IMPLEMENTED;
}
class SimpleBackendImpl::SimpleIterator final : public Iterator {
@@ -557,27 +570,6 @@ void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback,
callback.Run(result.net_error);
}
-void SimpleBackendImpl::IndexReadyForDoom(Time initial_time,
- Time end_time,
- const CompletionCallback& callback,
- int result) {
- if (result != net::OK) {
- callback.Run(result);
- return;
- }
- scoped_ptr<std::vector<uint64>> removed_key_hashes(
- index_->GetEntriesBetween(initial_time, end_time).release());
- DoomEntries(removed_key_hashes.get(), callback);
-}
-
-void SimpleBackendImpl::IndexReadyForSizeCalculation(
- const CompletionCallback& callback,
- int result) {
- if (result == net::OK)
- result = static_cast<int>(index_->GetCacheSize());
- callback.Run(result);
-}
-
SimpleBackendImpl::DiskStatResult SimpleBackendImpl::InitCacheStructureOnDisk(
const base::FilePath& path,
uint64 suggested_max_size) {
diff --git a/net/disk_cache/simple/simple_backend_impl.h b/net/disk_cache/simple/simple_backend_impl.h
index c8cac21..c9debd0 100644
--- a/net/disk_cache/simple/simple_backend_impl.h
+++ b/net/disk_cache/simple/simple_backend_impl.h
@@ -140,10 +140,6 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend,
const CompletionCallback& callback,
int result);
- // Calculates the size of the entire cache. Invoked when the index is ready.
- void IndexReadyForSizeCalculation(const CompletionCallback& callback,
- int result);
-
// Try to create the directory if it doesn't exist. This must run on the IO
// thread.
static DiskStatResult InitCacheStructureOnDisk(const base::FilePath& path,
diff --git a/net/disk_cache/simple/simple_index.cc b/net/disk_cache/simple/simple_index.cc
index 5557801..fd01abd 100644
--- a/net/disk_cache/simple/simple_index.cc
+++ b/net/disk_cache/simple/simple_index.cc
@@ -239,11 +239,6 @@ int32 SimpleIndex::GetEntryCount() const {
return entries_set_.size();
}
-uint64 SimpleIndex::GetCacheSize() const {
- DCHECK(initialized_);
- return cache_size_;
-}
-
void SimpleIndex::Insert(uint64 entry_hash) {
DCHECK(io_thread_checker_.CalledOnValidThread());
// Upon insert we don't know yet the size of the entry.
diff --git a/net/disk_cache/simple/simple_index.h b/net/disk_cache/simple/simple_index.h
index 5a8046d..11adab9 100644
--- a/net/disk_cache/simple/simple_index.h
+++ b/net/disk_cache/simple/simple_index.h
@@ -130,10 +130,6 @@ class NET_EXPORT_PRIVATE SimpleIndex
// Returns number of indexed entries.
int32 GetEntryCount() const;
- // Returns the size of the entire cache in bytes. Can only be called after the
- // index has been initialized.
- uint64 GetCacheSize() const;
-
// Returns whether the index has been initialized yet.
bool initialized() const { return initialized_; }