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

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

Issue 693943003: Update from https://crrev.com/302630 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 it->ReadUInt64(&cache_size_); 192 it->ReadUInt64(&cache_size_);
193 } 193 }
194 194
195 void SimpleIndexFile::SyncWriteToDisk(net::CacheType cache_type, 195 void SimpleIndexFile::SyncWriteToDisk(net::CacheType cache_type,
196 const base::FilePath& cache_directory, 196 const base::FilePath& cache_directory,
197 const base::FilePath& index_filename, 197 const base::FilePath& index_filename,
198 const base::FilePath& temp_index_filename, 198 const base::FilePath& temp_index_filename,
199 scoped_ptr<Pickle> pickle, 199 scoped_ptr<Pickle> pickle,
200 const base::TimeTicks& start_time, 200 const base::TimeTicks& start_time,
201 bool app_on_background) { 201 bool app_on_background) {
202 DCHECK_EQ(index_filename.DirName().value(),
203 temp_index_filename.DirName().value());
204 base::FilePath index_file_directory = temp_index_filename.DirName();
205 if (!base::DirectoryExists(index_file_directory) &&
206 !base::CreateDirectory(index_file_directory)) {
207 LOG(ERROR) << "Could not create a directory to hold the index file";
208 return;
209 }
210
202 // There is a chance that the index containing all the necessary data about 211 // There is a chance that the index containing all the necessary data about
203 // newly created entries will appear to be stale. This can happen if on-disk 212 // newly created entries will appear to be stale. This can happen if on-disk
204 // part of a Create operation does not fit into the time budget for the index 213 // part of a Create operation does not fit into the time budget for the index
205 // flush delay. This simple approach will be reconsidered if it does not allow 214 // flush delay. This simple approach will be reconsidered if it does not allow
206 // for maintaining freshness. 215 // for maintaining freshness.
207 base::Time cache_dir_mtime; 216 base::Time cache_dir_mtime;
208 if (!simple_util::GetMTime(cache_directory, &cache_dir_mtime)) { 217 if (!simple_util::GetMTime(cache_directory, &cache_dir_mtime)) {
209 LOG(ERROR) << "Could obtain information about cache age"; 218 LOG(ERROR) << "Could obtain information about cache age";
210 return; 219 return;
211 } 220 }
212 SerializeFinalData(cache_dir_mtime, pickle.get()); 221 SerializeFinalData(cache_dir_mtime, pickle.get());
213 if (!WritePickleFile(pickle.get(), temp_index_filename)) { 222 if (!WritePickleFile(pickle.get(), temp_index_filename)) {
214 if (!base::CreateDirectory(temp_index_filename.DirName())) { 223 LOG(ERROR) << "Failed to write the temporary index file";
215 LOG(ERROR) << "Could not create a directory to hold the index file"; 224 return;
216 return;
217 }
218 if (!WritePickleFile(pickle.get(), temp_index_filename)) {
219 LOG(ERROR) << "Failed to write the temporary index file";
220 return;
221 }
222 } 225 }
223 226
224 // Atomically rename the temporary index file to become the real one. 227 // Atomically rename the temporary index file to become the real one.
225 // TODO(gavinp): DCHECK when not shutting down, since that is very strange. 228 // TODO(gavinp): DCHECK when not shutting down, since that is very strange.
226 // The rename failing during shutdown is legal because it's legal to begin 229 // The rename failing during shutdown is legal because it's legal to begin
227 // erasing a cache as soon as the destructor has been called. 230 // erasing a cache as soon as the destructor has been called.
228 if (!base::ReplaceFile(temp_index_filename, index_filename, NULL)) 231 if (!base::ReplaceFile(temp_index_filename, index_filename, NULL))
229 return; 232 return;
230 233
231 if (app_on_background) { 234 if (app_on_background) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 bool SimpleIndexFile::LegacyIsIndexFileStale( 473 bool SimpleIndexFile::LegacyIsIndexFileStale(
471 base::Time cache_last_modified, 474 base::Time cache_last_modified,
472 const base::FilePath& index_file_path) { 475 const base::FilePath& index_file_path) {
473 base::Time index_mtime; 476 base::Time index_mtime;
474 if (!simple_util::GetMTime(index_file_path, &index_mtime)) 477 if (!simple_util::GetMTime(index_file_path, &index_mtime))
475 return true; 478 return true;
476 return index_mtime < cache_last_modified; 479 return index_mtime < cache_last_modified;
477 } 480 }
478 481
479 } // namespace disk_cache 482 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/base/test_completion_callback_unittest.cc ('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