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

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

Issue 23983005: SimpleCache: merge the first and second stream in one file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed gavin's comments Created 7 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 <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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 last_used_time = file_info.last_modified; 110 last_used_time = file_info.last_modified;
111 111
112 int64 file_size = file_info.size; 112 int64 file_size = file_info.size;
113 SimpleIndex::EntrySet::iterator it = entries->find(hash_key); 113 SimpleIndex::EntrySet::iterator it = entries->find(hash_key);
114 if (it == entries->end()) { 114 if (it == entries->end()) {
115 SimpleIndex::InsertInEntrySet( 115 SimpleIndex::InsertInEntrySet(
116 hash_key, 116 hash_key,
117 EntryMetadata(last_used_time, file_size), 117 EntryMetadata(last_used_time, file_size),
118 entries); 118 entries);
119 } else { 119 } else {
120 // Summing up the total size of the entry through all the *_[0-2] files 120 // Summing up the total size of the entry through all the *_[0-1] files
121 it->second.SetEntrySize(it->second.GetEntrySize() + file_size); 121 it->second.SetEntrySize(it->second.GetEntrySize() + file_size);
122 } 122 }
123 } 123 }
124 124
125 } // namespace 125 } // namespace
126 126
127 SimpleIndexLoadResult::SimpleIndexLoadResult() : did_load(false), 127 SimpleIndexLoadResult::SimpleIndexLoadResult() : did_load(false),
128 flush_required(false) { 128 flush_required(false) {
129 } 129 }
130 130
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // static 404 // static
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.
415 COMPILE_ASSERT(kSimpleEntryFileCount == 3,
416 file_pattern_must_match_file_count);
417
418 const bool did_succeed = TraverseCacheDirectory( 414 const bool did_succeed = TraverseCacheDirectory(
419 cache_directory, base::Bind(&ProcessEntryFile, entries)); 415 cache_directory, base::Bind(&ProcessEntryFile, entries));
420 if (!did_succeed) { 416 if (!did_succeed) {
421 LOG(ERROR) << "Could not reconstruct index from disk"; 417 LOG(ERROR) << "Could not reconstruct index from disk";
422 return; 418 return;
423 } 419 }
424 out_result->did_load = true; 420 out_result->did_load = true;
425 // When we restore from disk we write the merged index file to disk right 421 // 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. 422 // away, this might save us from having to restore again next time.
427 out_result->flush_required = true; 423 out_result->flush_required = true;
428 } 424 }
429 425
430 // static 426 // static
431 bool SimpleIndexFile::IsIndexFileStale(base::Time cache_last_modified, 427 bool SimpleIndexFile::IsIndexFileStale(base::Time cache_last_modified,
432 const base::FilePath& index_file_path) { 428 const base::FilePath& index_file_path) {
433 base::Time index_mtime; 429 base::Time index_mtime;
434 if (!simple_util::GetMTime(index_file_path, &index_mtime)) 430 if (!simple_util::GetMTime(index_file_path, &index_mtime))
435 return true; 431 return true;
436 return index_mtime < cache_last_modified; 432 return index_mtime < cache_last_modified;
437 } 433 }
438 434
439 } // namespace disk_cache 435 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.cc ('k') | net/disk_cache/simple/simple_synchronous_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698