Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1188)

Unified Diff: net/disk_cache/simple/simple_index.cc

Issue 13913010: Add Cache size to the Simple Index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing the branching issue Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/disk_cache/simple/simple_index.cc
diff --git a/net/disk_cache/simple/simple_index.cc b/net/disk_cache/simple/simple_index.cc
index fb264c510b9b7314dd5b13792df971880e45f8d8..b87381d6a7f5165236b10dd6a9d39e31f8ac759e 100644
--- a/net/disk_cache/simple/simple_index.cc
+++ b/net/disk_cache/simple/simple_index.cc
@@ -112,11 +112,15 @@ bool SimpleIndex::Initialize() {
}
void SimpleIndex::Insert(const std::string& key) {
+ // Upon insert we don't know yet the size of the entry.
+ // It will be updated later when the SynchronousEntryImpl finish and the
+ // UpdateEntrySize will be called.
InsertInternal(SimpleIndexFile::EntryMetadata(GetEntryHashForKey(key),
- base::Time::Now()));
+ base::Time::Now(), 0));
}
void SimpleIndex::Remove(const std::string& key) {
+ UpdateEntrySize(key, 0);
entries_set_.erase(GetEntryHashForKey(key));
}
@@ -132,6 +136,19 @@ bool SimpleIndex::UseIfExists(const std::string& key) {
return true;
}
+bool SimpleIndex::UpdateEntrySize(const std::string& key, uint64 entry_size) {
+ EntrySet::iterator it = entries_set_.find(GetEntryHashForKey(key));
+ if (it == entries_set_.end())
+ return false;
+
+ // Update the total cache size with the new entry size.
+ cache_size_ -= it->second.entry_size;
+ cache_size_ += entry_size;
+ it->second.entry_size = entry_size;
+
+ return true;
+}
+
void SimpleIndex::InsertInternal(
const SimpleIndexFile::EntryMetadata& entry_metadata) {
entries_set_.insert(make_pair(entry_metadata.GetHashKey(), entry_metadata));
@@ -143,11 +160,12 @@ bool SimpleIndex::RestoreFromDisk() {
CloseIndexFile();
file_util::Delete(index_filename_, /* recursive = */ false);
entries_set_.clear();
- const base::FilePath::StringType file_pattern = FILE_PATH_LITERAL("*_0");
+ const base::FilePath::StringType file_pattern = FILE_PATH_LITERAL("*_[0-2]");
gavinp 2013/04/09 15:27:37 This is a scary embedding of SimpleBackend::kSimpl
felipeg 2013/04/09 16:24:35 Added a TODO
FileEnumerator enumerator(path_,
false /* recursive */,
FileEnumerator::FILES,
file_pattern);
+
for (base::FilePath file_path = enumerator.Next(); !file_path.empty();
file_path = enumerator.Next()) {
const base::FilePath::StringType base_name = file_path.BaseName().value();
@@ -166,8 +184,18 @@ bool SimpleIndex::RestoreFromDisk() {
#endif
if (last_used_time.is_null())
last_used_time = FileEnumerator::GetLastModifiedTime(find_info);
- InsertInternal(SimpleIndexFile::EntryMetadata(hash_key, last_used_time));
+
+ int64 file_size = FileEnumerator::GetFilesize(find_info);
+ EntrySet::iterator it = entries_set_.find(hash_key);
+ if (it == entries_set_.end()) {
+ InsertInternal(SimpleIndexFile::EntryMetadata(
+ hash_key, last_used_time, file_size));
+ } else {
+ // Summing up the total size of the entry through all the *_[0-2] files
+ it->second.entry_size += file_size;
+ }
}
+
// TODO(felipeg): Detect unrecoverable problems and return false here.
return true;
}
« net/disk_cache/simple/simple_entry_impl.cc ('K') | « net/disk_cache/simple/simple_index.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698