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 |