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

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

Issue 13933029: Add SimpleCache index file heuristics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_file.cc
diff --git a/net/disk_cache/simple/simple_index_file.cc b/net/disk_cache/simple/simple_index_file.cc
index a2913202276b22ef724a04abb6ffd0cdc34aa419..fc33833a0a58040fd9dc9fb175dc45fd44a60971 100644
--- a/net/disk_cache/simple/simple_index_file.cc
+++ b/net/disk_cache/simple/simple_index_file.cc
@@ -66,6 +66,9 @@ bool SimpleIndexFile::IndexMetadata::CheckIndexMetadata() {
// static
scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::LoadFromDisk(
const base::FilePath& index_filename) {
+ // Only load if the index is not stale.
+ if (SimpleIndexFile::IsIndexFileStale(index_filename))
+ return scoped_ptr<SimpleIndex::EntrySet>(NULL);
std::string contents;
if(!file_util::ReadFileToString(index_filename, &contents)) {
LOG(WARNING) << "Could not read Simple Index file.";
@@ -161,4 +164,21 @@ void SimpleIndexFile::WriteToDisk(const base::FilePath& index_filename,
DCHECK(result);
}
+// static
+bool SimpleIndexFile::IsIndexFileStale(const base::FilePath& index_filename) {
+ base::PlatformFileInfo dir_info;
+ base::PlatformFileInfo index_info;
+ if (!file_util::GetFileInfo(index_filename.DirName(), &dir_info))
+ return false;
+ DCHECK(dir_info.is_directory);
+ if (!file_util::GetFileInfo(index_filename, &index_info))
+ return false;
+
+ // Index file last_modified must be equal to the directory last_modified since
+ // the last operation we do is ReplaceFile in the
+ // SimpleIndexFile::WriteToDisk().
+ // If not true, we need to restore the index.
+ return index_info.last_modified >= dir_info.last_modified;
+}
+
} // namespace disk_cache
« net/disk_cache/simple/simple_index_file.h ('K') | « net/disk_cache/simple/simple_index_file.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698