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

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

Issue 691803003: Do not DCHECK on SimpleCache deletion-while-closing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lint 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
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 void UmaRecordIndexInitMethod(IndexInitMethod method, 64 void UmaRecordIndexInitMethod(IndexInitMethod method,
65 net::CacheType cache_type) { 65 net::CacheType cache_type) {
66 SIMPLE_CACHE_UMA(ENUMERATION, 66 SIMPLE_CACHE_UMA(ENUMERATION,
67 "IndexInitializeMethod", cache_type, 67 "IndexInitializeMethod", cache_type,
68 method, INITIALIZE_METHOD_MAX); 68 method, INITIALIZE_METHOD_MAX);
69 } 69 }
70 70
71 bool WritePickleFile(Pickle* pickle, const base::FilePath& file_name) { 71 bool WritePickleFile(Pickle* pickle, const base::FilePath& file_name) {
72 File file( 72 File file(
73 file_name, 73 file_name,
74 File::FLAG_CREATE_ALWAYS | File::FLAG_WRITE | File::FLAG_SHARE_DELETE); 74 File::FLAG_CREATE | File::FLAG_WRITE | File::FLAG_SHARE_DELETE);
75 if (!file.IsValid()) 75 if (!file.IsValid())
76 return false; 76 return false;
77 77
78 int bytes_written = 78 int bytes_written =
79 file.Write(0, static_cast<const char*>(pickle->data()), pickle->size()); 79 file.Write(0, static_cast<const char*>(pickle->data()), pickle->size());
80 if (bytes_written != implicit_cast<int>(pickle->size())) { 80 if (bytes_written != implicit_cast<int>(pickle->size())) {
81 simple_util::SimpleCacheDeleteFile(file_name); 81 simple_util::SimpleCacheDeleteFile(file_name);
82 return false; 82 return false;
83 } 83 }
84 return true; 84 return true;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 LOG(ERROR) << "Could not create a directory to hold the index file"; 215 LOG(ERROR) << "Could not create a directory to hold the index file";
216 return; 216 return;
217 } 217 }
218 if (!WritePickleFile(pickle.get(), temp_index_filename)) { 218 if (!WritePickleFile(pickle.get(), temp_index_filename)) {
219 LOG(ERROR) << "Failed to write the temporary index file"; 219 LOG(ERROR) << "Failed to write the temporary index file";
220 return; 220 return;
221 } 221 }
222 } 222 }
223 223
224 // Atomically rename the temporary index file to become the real one. 224 // Atomically rename the temporary index file to become the real one.
225 bool result = base::ReplaceFile(temp_index_filename, index_filename, NULL); 225 // TODO(gavinp): DCHECK when not shutting down, since that is very strange.
226 DCHECK(result); 226 // 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.
228 if (!base::ReplaceFile(temp_index_filename, index_filename, NULL))
229 return;
227 230
228 if (app_on_background) { 231 if (app_on_background) {
229 SIMPLE_CACHE_UMA(TIMES, 232 SIMPLE_CACHE_UMA(TIMES,
230 "IndexWriteToDiskTime.Background", cache_type, 233 "IndexWriteToDiskTime.Background", cache_type,
231 (base::TimeTicks::Now() - start_time)); 234 (base::TimeTicks::Now() - start_time));
232 } else { 235 } else {
233 SIMPLE_CACHE_UMA(TIMES, 236 SIMPLE_CACHE_UMA(TIMES,
234 "IndexWriteToDiskTime.Foreground", cache_type, 237 "IndexWriteToDiskTime.Foreground", cache_type,
235 (base::TimeTicks::Now() - start_time)); 238 (base::TimeTicks::Now() - start_time));
236 } 239 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 bool SimpleIndexFile::LegacyIsIndexFileStale( 470 bool SimpleIndexFile::LegacyIsIndexFileStale(
468 base::Time cache_last_modified, 471 base::Time cache_last_modified,
469 const base::FilePath& index_file_path) { 472 const base::FilePath& index_file_path) {
470 base::Time index_mtime; 473 base::Time index_mtime;
471 if (!simple_util::GetMTime(index_file_path, &index_mtime)) 474 if (!simple_util::GetMTime(index_file_path, &index_mtime))
472 return true; 475 return true;
473 return index_mtime < cache_last_modified; 476 return index_mtime < cache_last_modified;
474 } 477 }
475 478
476 } // namespace disk_cache 479 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698