| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 (base::TimeTicks::Now() - start_time)); | 333 (base::TimeTicks::Now() - start_time)); |
| 334 } | 334 } |
| 335 } | 335 } |
| 336 | 336 |
| 337 bool SimpleIndexFile::IndexMetadata::CheckIndexMetadata() { | 337 bool SimpleIndexFile::IndexMetadata::CheckIndexMetadata() { |
| 338 if (entry_count_ > kMaxEntriesInIndex || | 338 if (entry_count_ > kMaxEntriesInIndex || |
| 339 magic_number_ != kSimpleIndexMagicNumber) { | 339 magic_number_ != kSimpleIndexMagicNumber) { |
| 340 return false; | 340 return false; |
| 341 } | 341 } |
| 342 | 342 |
| 343 static_assert(kSimpleVersion == 7, "index metadata reader out of date"); | 343 static_assert(kSimpleVersion == 8, "index metadata reader out of date"); |
| 344 // No |reason_| is saved in the version 6 file format. | 344 // No |reason_| is saved in the version 6 file format. |
| 345 if (version_ == 6) | 345 if (version_ == 6) |
| 346 return reason_ == SimpleIndex::INDEX_WRITE_REASON_MAX; | 346 return reason_ == SimpleIndex::INDEX_WRITE_REASON_MAX; |
| 347 return version_ == 7 && reason_ < SimpleIndex::INDEX_WRITE_REASON_MAX; | 347 return (version_ == 7 || version_ == 8) && |
| 348 reason_ < SimpleIndex::INDEX_WRITE_REASON_MAX; |
| 348 } | 349 } |
| 349 | 350 |
| 350 SimpleIndexFile::SimpleIndexFile( | 351 SimpleIndexFile::SimpleIndexFile( |
| 351 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, | 352 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, |
| 352 const scoped_refptr<base::TaskRunner>& worker_pool, | 353 const scoped_refptr<base::TaskRunner>& worker_pool, |
| 353 net::CacheType cache_type, | 354 net::CacheType cache_type, |
| 354 const base::FilePath& cache_directory) | 355 const base::FilePath& cache_directory) |
| 355 : cache_thread_(cache_thread), | 356 : cache_thread_(cache_thread), |
| 356 worker_pool_(worker_pool), | 357 worker_pool_(worker_pool), |
| 357 cache_type_(cache_type), | 358 cache_type_(cache_type), |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 if (!index_metadata.CheckIndexMetadata()) { | 553 if (!index_metadata.CheckIndexMetadata()) { |
| 553 LOG(ERROR) << "Invalid index_metadata on Simple Cache Index."; | 554 LOG(ERROR) << "Invalid index_metadata on Simple Cache Index."; |
| 554 return; | 555 return; |
| 555 } | 556 } |
| 556 | 557 |
| 557 entries->reserve(index_metadata.entry_count() + kExtraSizeForMerge); | 558 entries->reserve(index_metadata.entry_count() + kExtraSizeForMerge); |
| 558 while (entries->size() < index_metadata.entry_count()) { | 559 while (entries->size() < index_metadata.entry_count()) { |
| 559 uint64_t hash_key; | 560 uint64_t hash_key; |
| 560 EntryMetadata entry_metadata; | 561 EntryMetadata entry_metadata; |
| 561 if (!pickle_it.ReadUInt64(&hash_key) || | 562 if (!pickle_it.ReadUInt64(&hash_key) || |
| 562 !entry_metadata.Deserialize(&pickle_it)) { | 563 !entry_metadata.Deserialize(&pickle_it, |
| 564 index_metadata.has_memory_entry_data())) { |
| 563 LOG(WARNING) << "Invalid EntryMetadata in Simple Index file."; | 565 LOG(WARNING) << "Invalid EntryMetadata in Simple Index file."; |
| 564 entries->clear(); | 566 entries->clear(); |
| 565 return; | 567 return; |
| 566 } | 568 } |
| 567 SimpleIndex::InsertInEntrySet(hash_key, entry_metadata, entries); | 569 SimpleIndex::InsertInEntrySet(hash_key, entry_metadata, entries); |
| 568 } | 570 } |
| 569 | 571 |
| 570 int64_t cache_last_modified; | 572 int64_t cache_last_modified; |
| 571 if (!pickle_it.ReadInt64(&cache_last_modified)) { | 573 if (!pickle_it.ReadInt64(&cache_last_modified)) { |
| 572 entries->clear(); | 574 entries->clear(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 bool SimpleIndexFile::LegacyIsIndexFileStale( | 607 bool SimpleIndexFile::LegacyIsIndexFileStale( |
| 606 base::Time cache_last_modified, | 608 base::Time cache_last_modified, |
| 607 const base::FilePath& index_file_path) { | 609 const base::FilePath& index_file_path) { |
| 608 base::Time index_mtime; | 610 base::Time index_mtime; |
| 609 if (!simple_util::GetMTime(index_file_path, &index_mtime)) | 611 if (!simple_util::GetMTime(index_file_path, &index_mtime)) |
| 610 return true; | 612 return true; |
| 611 return index_mtime < cache_last_modified; | 613 return index_mtime < cache_last_modified; |
| 612 } | 614 } |
| 613 | 615 |
| 614 } // namespace disk_cache | 616 } // namespace disk_cache |
| OLD | NEW |