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

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

Issue 2774923002: Try to speed up SimpleCache index re-sync on Windows. (Closed)
Patch Set: Created 3 years, 9 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 file.Write(0, static_cast<const char*>(pickle->data()), pickle->size()); 113 file.Write(0, static_cast<const char*>(pickle->data()), pickle->size());
114 if (bytes_written != base::checked_cast<int>(pickle->size())) { 114 if (bytes_written != base::checked_cast<int>(pickle->size())) {
115 simple_util::SimpleCacheDeleteFile(file_name); 115 simple_util::SimpleCacheDeleteFile(file_name);
116 return false; 116 return false;
117 } 117 }
118 return true; 118 return true;
119 } 119 }
120 120
121 // Called for each cache directory traversal iteration. 121 // Called for each cache directory traversal iteration.
122 void ProcessEntryFile(SimpleIndex::EntrySet* entries, 122 void ProcessEntryFile(SimpleIndex::EntrySet* entries,
123 const base::FilePath& file_path) { 123 const base::FilePath& file_path,
124 base::Time last_accessed,
jkarlin 2017/03/27 14:09:15 Could we instead take a 'const base::FileInfo& fil
Maks Orlovich 2017/03/27 15:25:44 We don't have a base::FileInfo on the Windows path
125 base::Time last_modified,
126 int64_t size) {
124 static const size_t kEntryFilesLength = 127 static const size_t kEntryFilesLength =
125 kEntryFilesHashLength + kEntryFilesSuffixLength; 128 kEntryFilesHashLength + kEntryFilesSuffixLength;
126 // Converting to std::string is OK since we never use UTF8 wide chars in our 129 // Converting to std::string is OK since we never use UTF8 wide chars in our
127 // file names. 130 // file names.
128 const base::FilePath::StringType base_name = file_path.BaseName().value(); 131 const base::FilePath::StringType base_name = file_path.BaseName().value();
129 const std::string file_name(base_name.begin(), base_name.end()); 132 const std::string file_name(base_name.begin(), base_name.end());
130 if (file_name.size() != kEntryFilesLength) 133 if (file_name.size() != kEntryFilesLength)
131 return; 134 return;
132 const base::StringPiece hash_string( 135 const base::StringPiece hash_string(
133 file_name.begin(), file_name.begin() + kEntryFilesHashLength); 136 file_name.begin(), file_name.begin() + kEntryFilesHashLength);
134 uint64_t hash_key = 0; 137 uint64_t hash_key = 0;
135 if (!simple_util::GetEntryHashKeyFromHexString(hash_string, &hash_key)) { 138 if (!simple_util::GetEntryHashKeyFromHexString(hash_string, &hash_key)) {
136 LOG(WARNING) << "Invalid entry hash key filename while restoring index from" 139 LOG(WARNING) << "Invalid entry hash key filename while restoring index from"
137 << " disk: " << file_name; 140 << " disk: " << file_name;
138 return; 141 return;
139 } 142 }
140 143
141 File::Info file_info;
142 if (!base::GetFileInfo(file_path, &file_info)) {
143 LOG(ERROR) << "Could not get file info for " << file_path.value();
144 return;
145 }
146 base::Time last_used_time; 144 base::Time last_used_time;
147 #if defined(OS_POSIX) 145 #if defined(OS_POSIX)
148 // For POSIX systems, a last access time is available. However, it's not 146 // For POSIX systems, a last access time is available. However, it's not
149 // guaranteed to be more accurate than mtime. It is no worse though. 147 // guaranteed to be more accurate than mtime. It is no worse though.
150 last_used_time = file_info.last_accessed; 148 last_used_time = last_accessed;
151 #endif 149 #endif
152 if (last_used_time.is_null()) 150 if (last_used_time.is_null())
153 last_used_time = file_info.last_modified; 151 last_used_time = last_modified;
154 152
155 SimpleIndex::EntrySet::iterator it = entries->find(hash_key); 153 SimpleIndex::EntrySet::iterator it = entries->find(hash_key);
156 base::CheckedNumeric<uint32_t> total_entry_size = file_info.size; 154 base::CheckedNumeric<uint32_t> total_entry_size = size;
157 155
158 if (it == entries->end()) { 156 if (it == entries->end()) {
159 SimpleIndex::InsertInEntrySet( 157 SimpleIndex::InsertInEntrySet(
160 hash_key, EntryMetadata(last_used_time, total_entry_size.ValueOrDie()), 158 hash_key, EntryMetadata(last_used_time, total_entry_size.ValueOrDie()),
161 entries); 159 entries);
162 } else { 160 } else {
163 // Summing up the total size of the entry through all the *_[0-1] files 161 // Summing up the total size of the entry through all the *_[0-1] files
164 total_entry_size += it->second.GetEntrySize(); 162 total_entry_size += it->second.GetEntrySize();
165 it->second.SetEntrySize(total_entry_size.ValueOrDie()); 163 it->second.SetEntrySize(total_entry_size.ValueOrDie());
166 } 164 }
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 bool SimpleIndexFile::LegacyIsIndexFileStale( 552 bool SimpleIndexFile::LegacyIsIndexFileStale(
555 base::Time cache_last_modified, 553 base::Time cache_last_modified,
556 const base::FilePath& index_file_path) { 554 const base::FilePath& index_file_path) {
557 base::Time index_mtime; 555 base::Time index_mtime;
558 if (!simple_util::GetMTime(index_file_path, &index_mtime)) 556 if (!simple_util::GetMTime(index_file_path, &index_mtime))
559 return true; 557 return true;
560 return index_mtime < cache_last_modified; 558 return index_mtime < cache_last_modified;
561 } 559 }
562 560
563 } // namespace disk_cache 561 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698