Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: net/disk_cache/simple/simple_index_file.cc

Issue 2957133002: Implement in-memory byte hints in SimpleCache (Closed)
Patch Set: Adjust to the interface's naming change. Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 (base::TimeTicks::Now() - start_time)); 330 (base::TimeTicks::Now() - start_time));
331 } 331 }
332 } 332 }
333 333
334 bool SimpleIndexFile::IndexMetadata::CheckIndexMetadata() { 334 bool SimpleIndexFile::IndexMetadata::CheckIndexMetadata() {
335 if (entry_count_ > kMaxEntriesInIndex || 335 if (entry_count_ > kMaxEntriesInIndex ||
336 magic_number_ != kSimpleIndexMagicNumber) { 336 magic_number_ != kSimpleIndexMagicNumber) {
337 return false; 337 return false;
338 } 338 }
339 339
340 static_assert(kSimpleVersion == 7, "index metadata reader out of date"); 340 static_assert(kSimpleVersion == 8, "index metadata reader out of date");
341 // No |reason_| is saved in the version 6 file format. 341 // No |reason_| is saved in the version 6 file format.
342 if (version_ == 6) 342 if (version_ == 6)
343 return reason_ == SimpleIndex::INDEX_WRITE_REASON_MAX; 343 return reason_ == SimpleIndex::INDEX_WRITE_REASON_MAX;
344 return version_ == 7 && reason_ < SimpleIndex::INDEX_WRITE_REASON_MAX; 344 return (version_ == 7 || version_ == 8) &&
345 reason_ < SimpleIndex::INDEX_WRITE_REASON_MAX;
345 } 346 }
346 347
347 SimpleIndexFile::SimpleIndexFile( 348 SimpleIndexFile::SimpleIndexFile(
348 const scoped_refptr<base::SequencedTaskRunner>& cache_runner, 349 const scoped_refptr<base::SequencedTaskRunner>& cache_runner,
349 const scoped_refptr<base::TaskRunner>& worker_pool, 350 const scoped_refptr<base::TaskRunner>& worker_pool,
350 net::CacheType cache_type, 351 net::CacheType cache_type,
351 const base::FilePath& cache_directory) 352 const base::FilePath& cache_directory)
352 : cache_runner_(cache_runner), 353 : cache_runner_(cache_runner),
353 worker_pool_(worker_pool), 354 worker_pool_(worker_pool),
354 cache_type_(cache_type), 355 cache_type_(cache_type),
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 if (!index_metadata.CheckIndexMetadata()) { 549 if (!index_metadata.CheckIndexMetadata()) {
549 LOG(ERROR) << "Invalid index_metadata on Simple Cache Index."; 550 LOG(ERROR) << "Invalid index_metadata on Simple Cache Index.";
550 return; 551 return;
551 } 552 }
552 553
553 entries->reserve(index_metadata.entry_count() + kExtraSizeForMerge); 554 entries->reserve(index_metadata.entry_count() + kExtraSizeForMerge);
554 while (entries->size() < index_metadata.entry_count()) { 555 while (entries->size() < index_metadata.entry_count()) {
555 uint64_t hash_key; 556 uint64_t hash_key;
556 EntryMetadata entry_metadata; 557 EntryMetadata entry_metadata;
557 if (!pickle_it.ReadUInt64(&hash_key) || 558 if (!pickle_it.ReadUInt64(&hash_key) ||
558 !entry_metadata.Deserialize(&pickle_it)) { 559 !entry_metadata.Deserialize(
560 &pickle_it, index_metadata.has_entry_in_memory_data())) {
559 LOG(WARNING) << "Invalid EntryMetadata in Simple Index file."; 561 LOG(WARNING) << "Invalid EntryMetadata in Simple Index file.";
560 entries->clear(); 562 entries->clear();
561 return; 563 return;
562 } 564 }
563 SimpleIndex::InsertInEntrySet(hash_key, entry_metadata, entries); 565 SimpleIndex::InsertInEntrySet(hash_key, entry_metadata, entries);
564 } 566 }
565 567
566 int64_t cache_last_modified; 568 int64_t cache_last_modified;
567 if (!pickle_it.ReadInt64(&cache_last_modified)) { 569 if (!pickle_it.ReadInt64(&cache_last_modified)) {
568 entries->clear(); 570 entries->clear();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 bool SimpleIndexFile::LegacyIsIndexFileStale( 603 bool SimpleIndexFile::LegacyIsIndexFileStale(
602 base::Time cache_last_modified, 604 base::Time cache_last_modified,
603 const base::FilePath& index_file_path) { 605 const base::FilePath& index_file_path) {
604 base::Time index_mtime; 606 base::Time index_mtime;
605 if (!simple_util::GetMTime(index_file_path, &index_mtime)) 607 if (!simple_util::GetMTime(index_file_path, &index_mtime))
606 return true; 608 return true;
607 return index_mtime < cache_last_modified; 609 return index_mtime < cache_last_modified;
608 } 610 }
609 611
610 } // namespace disk_cache 612 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_index_file.h ('k') | net/disk_cache/simple/simple_index_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698