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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 return; | 88 return; |
89 const base::StringPiece hash_string( | 89 const base::StringPiece hash_string( |
90 file_name.begin(), file_name.begin() + kEntryFilesHashLength); | 90 file_name.begin(), file_name.begin() + kEntryFilesHashLength); |
91 uint64 hash_key = 0; | 91 uint64 hash_key = 0; |
92 if (!simple_util::GetEntryHashKeyFromHexString(hash_string, &hash_key)) { | 92 if (!simple_util::GetEntryHashKeyFromHexString(hash_string, &hash_key)) { |
93 LOG(WARNING) << "Invalid entry hash key filename while restoring index from" | 93 LOG(WARNING) << "Invalid entry hash key filename while restoring index from" |
94 << " disk: " << file_name; | 94 << " disk: " << file_name; |
95 return; | 95 return; |
96 } | 96 } |
97 | 97 |
98 base::PlatformFileInfo file_info; | 98 base::File::Info file_info; |
99 if (!base::GetFileInfo(file_path, &file_info)) { | 99 if (!base::GetFileInfo(file_path, &file_info)) { |
100 LOG(ERROR) << "Could not get file info for " << file_path.value(); | 100 LOG(ERROR) << "Could not get file info for " << file_path.value(); |
101 return; | 101 return; |
102 } | 102 } |
103 base::Time last_used_time; | 103 base::Time last_used_time; |
104 #if defined(OS_POSIX) | 104 #if defined(OS_POSIX) |
105 // For POSIX systems, a last access time is available. However, it's not | 105 // For POSIX systems, a last access time is available. However, it's not |
106 // guaranteed to be more accurate than mtime. It is no worse though. | 106 // guaranteed to be more accurate than mtime. It is no worse though. |
107 last_used_time = file_info.last_accessed; | 107 last_used_time = file_info.last_accessed; |
108 #endif | 108 #endif |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 *out_cache_last_modified = base::Time::FromInternalValue(cache_last_modified); | 427 *out_cache_last_modified = base::Time::FromInternalValue(cache_last_modified); |
428 | 428 |
429 out_result->did_load = true; | 429 out_result->did_load = true; |
430 } | 430 } |
431 | 431 |
432 // static | 432 // static |
433 void SimpleIndexFile::SyncRestoreFromDisk( | 433 void SimpleIndexFile::SyncRestoreFromDisk( |
434 const base::FilePath& cache_directory, | 434 const base::FilePath& cache_directory, |
435 const base::FilePath& index_file_path, | 435 const base::FilePath& index_file_path, |
436 SimpleIndexLoadResult* out_result) { | 436 SimpleIndexLoadResult* out_result) { |
437 LOG(INFO) << "Simple Cache Index is being restored from disk."; | 437 VLOG(1) << "Simple Cache Index is being restored from disk."; |
438 base::DeleteFile(index_file_path, /* recursive = */ false); | 438 base::DeleteFile(index_file_path, /* recursive = */ false); |
439 out_result->Reset(); | 439 out_result->Reset(); |
440 SimpleIndex::EntrySet* entries = &out_result->entries; | 440 SimpleIndex::EntrySet* entries = &out_result->entries; |
441 | 441 |
442 const bool did_succeed = TraverseCacheDirectory( | 442 const bool did_succeed = TraverseCacheDirectory( |
443 cache_directory, base::Bind(&ProcessEntryFile, entries)); | 443 cache_directory, base::Bind(&ProcessEntryFile, entries)); |
444 if (!did_succeed) { | 444 if (!did_succeed) { |
445 LOG(ERROR) << "Could not reconstruct index from disk"; | 445 LOG(ERROR) << "Could not reconstruct index from disk"; |
446 return; | 446 return; |
447 } | 447 } |
448 out_result->did_load = true; | 448 out_result->did_load = true; |
449 // When we restore from disk we write the merged index file to disk right | 449 // When we restore from disk we write the merged index file to disk right |
450 // away, this might save us from having to restore again next time. | 450 // away, this might save us from having to restore again next time. |
451 out_result->flush_required = true; | 451 out_result->flush_required = true; |
452 } | 452 } |
453 | 453 |
454 // static | 454 // static |
455 bool SimpleIndexFile::LegacyIsIndexFileStale( | 455 bool SimpleIndexFile::LegacyIsIndexFileStale( |
456 base::Time cache_last_modified, | 456 base::Time cache_last_modified, |
457 const base::FilePath& index_file_path) { | 457 const base::FilePath& index_file_path) { |
458 base::Time index_mtime; | 458 base::Time index_mtime; |
459 if (!simple_util::GetMTime(index_file_path, &index_mtime)) | 459 if (!simple_util::GetMTime(index_file_path, &index_mtime)) |
460 return true; | 460 return true; |
461 return index_mtime < cache_last_modified; | 461 return index_mtime < cache_last_modified; |
462 } | 462 } |
463 | 463 |
464 } // namespace disk_cache | 464 } // namespace disk_cache |
OLD | NEW |