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

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: Stream 0 size in footer 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-2] files
pasko 2013/09/17 14:17:36 this comment needs to be updated, there is no long
clamy 2013/09/18 16:17:14 Done.
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
pasko 2013/09/17 14:17:36 Please remove the assertion and the TODO. The asse
clamy 2013/09/18 16:17:14 Done.
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698