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 c2b73b9c80716577363e59f05a4387de37bc4181..e4a7a225f25d764d2a51389aa8631b1f7382199b 100644 |
--- a/net/disk_cache/simple/simple_index.cc |
+++ b/net/disk_cache/simple/simple_index.cc |
@@ -9,6 +9,7 @@ |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
#include "base/file_util.h" |
+#include "base/file_util.h" |
#include "base/logging.h" |
#include "base/message_loop.h" |
#include "base/pickle.h" |
@@ -173,6 +174,8 @@ void SimpleIndex::InsertInEntrySet( |
} |
void SimpleIndex::PostponeWritingToDisk() { |
+ if (!initialized_) |
+ return; |
const base::TimeDelta file_age = base::Time::Now() - last_write_to_disk_; |
if (file_age > base::TimeDelta::FromSeconds(kMaxWriteToDiskDelaySecs) && |
write_to_disk_timer_.IsRunning()) { |
@@ -194,21 +197,24 @@ void SimpleIndex::LoadFromDisk( |
const base::FilePath& index_filename, |
base::SingleThreadTaskRunner* io_thread, |
const IndexCompletionCallback& completion_callback) { |
- scoped_ptr<EntrySet> index_file_entries = |
- SimpleIndexFile::LoadFromDisk(index_filename); |
+ bool restore_from_disk = SimpleIndexFile::IndexFileIsStale(index_filename); |
+ |
+ scoped_ptr<EntrySet> index_file_entries; |
+ if (!restore_from_disk) { |
+ index_file_entries = SimpleIndexFile::LoadFromDisk(index_filename); |
+ } |
- bool force_index_flush = false; |
if (!index_file_entries.get()) { |
index_file_entries = SimpleIndex::RestoreFromDisk(index_filename); |
// When we restore from disk we write the merged index file to disk right |
// away, this might save us from having to restore again next time. |
- force_index_flush = true; |
+ restore_from_disk = true; |
} |
io_thread->PostTask(FROM_HERE, |
base::Bind(completion_callback, |
base::Passed(&index_file_entries), |
- force_index_flush)); |
+ restore_from_disk)); |
} |
// static |