| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/disk_cache/simple/simple_index_file.h" | 5 #include "net/disk_cache/simple/simple_index_file.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 void SimpleIndexFile::SyncRestoreFromDisk( | 405 void SimpleIndexFile::SyncRestoreFromDisk( |
| 406 const base::FilePath& cache_directory, | 406 const base::FilePath& cache_directory, |
| 407 const base::FilePath& index_file_path, | 407 const base::FilePath& index_file_path, |
| 408 SimpleIndexLoadResult* out_result) { | 408 SimpleIndexLoadResult* out_result) { |
| 409 LOG(INFO) << "Simple Cache Index is being restored from disk."; | 409 LOG(INFO) << "Simple Cache Index is being restored from disk."; |
| 410 base::DeleteFile(index_file_path, /* recursive = */ false); | 410 base::DeleteFile(index_file_path, /* recursive = */ false); |
| 411 out_result->Reset(); | 411 out_result->Reset(); |
| 412 SimpleIndex::EntrySet* entries = &out_result->entries; | 412 SimpleIndex::EntrySet* entries = &out_result->entries; |
| 413 | 413 |
| 414 // TODO(felipeg,gavinp): Fix this once we have a one-file per entry format. | 414 // TODO(felipeg,gavinp): Fix this once we have a one-file per entry format. |
| 415 COMPILE_ASSERT(kSimpleEntryFileCount == 3, | 415 COMPILE_ASSERT(kSimpleEntryFileCount == 2, |
| 416 file_pattern_must_match_file_count); | 416 file_pattern_must_match_file_count); |
| 417 | 417 |
| 418 const bool did_succeed = TraverseCacheDirectory( | 418 const bool did_succeed = TraverseCacheDirectory( |
| 419 cache_directory, base::Bind(&ProcessEntryFile, entries)); | 419 cache_directory, base::Bind(&ProcessEntryFile, entries)); |
| 420 if (!did_succeed) { | 420 if (!did_succeed) { |
| 421 LOG(ERROR) << "Could not reconstruct index from disk"; | 421 LOG(ERROR) << "Could not reconstruct index from disk"; |
| 422 return; | 422 return; |
| 423 } | 423 } |
| 424 out_result->did_load = true; | 424 out_result->did_load = true; |
| 425 // When we restore from disk we write the merged index file to disk right | 425 // When we restore from disk we write the merged index file to disk right |
| 426 // away, this might save us from having to restore again next time. | 426 // away, this might save us from having to restore again next time. |
| 427 out_result->flush_required = true; | 427 out_result->flush_required = true; |
| 428 } | 428 } |
| 429 | 429 |
| 430 // static | 430 // static |
| 431 bool SimpleIndexFile::IsIndexFileStale(base::Time cache_last_modified, | 431 bool SimpleIndexFile::IsIndexFileStale(base::Time cache_last_modified, |
| 432 const base::FilePath& index_file_path) { | 432 const base::FilePath& index_file_path) { |
| 433 base::Time index_mtime; | 433 base::Time index_mtime; |
| 434 if (!simple_util::GetMTime(index_file_path, &index_mtime)) | 434 if (!simple_util::GetMTime(index_file_path, &index_mtime)) |
| 435 return true; | 435 return true; |
| 436 return index_mtime < cache_last_modified; | 436 return index_mtime < cache_last_modified; |
| 437 } | 437 } |
| 438 | 438 |
| 439 } // namespace disk_cache | 439 } // namespace disk_cache |
| OLD | NEW |