OLD | NEW |
---|---|
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 Loading... | |
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); |
gavinp
2014/10/30 18:59:20
This change is good to do while we are here: if mu
| |
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 Loading... | |
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 if (!base::ReplaceFile(temp_index_filename, index_filename, NULL)) |
226 DCHECK(result); | 226 return; |
227 | 227 |
jkarlin
2014/10/30 19:19:24
Would be better to replace DCHECK(result) with DCH
gavinp
2014/10/31 13:55:54
That data isn't easily available here; it would re
| |
228 if (app_on_background) { | 228 if (app_on_background) { |
229 SIMPLE_CACHE_UMA(TIMES, | 229 SIMPLE_CACHE_UMA(TIMES, |
230 "IndexWriteToDiskTime.Background", cache_type, | 230 "IndexWriteToDiskTime.Background", cache_type, |
231 (base::TimeTicks::Now() - start_time)); | 231 (base::TimeTicks::Now() - start_time)); |
232 } else { | 232 } else { |
233 SIMPLE_CACHE_UMA(TIMES, | 233 SIMPLE_CACHE_UMA(TIMES, |
234 "IndexWriteToDiskTime.Foreground", cache_type, | 234 "IndexWriteToDiskTime.Foreground", cache_type, |
235 (base::TimeTicks::Now() - start_time)); | 235 (base::TimeTicks::Now() - start_time)); |
236 } | 236 } |
237 } | 237 } |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 bool SimpleIndexFile::LegacyIsIndexFileStale( | 467 bool SimpleIndexFile::LegacyIsIndexFileStale( |
468 base::Time cache_last_modified, | 468 base::Time cache_last_modified, |
469 const base::FilePath& index_file_path) { | 469 const base::FilePath& index_file_path) { |
470 base::Time index_mtime; | 470 base::Time index_mtime; |
471 if (!simple_util::GetMTime(index_file_path, &index_mtime)) | 471 if (!simple_util::GetMTime(index_file_path, &index_mtime)) |
472 return true; | 472 return true; |
473 return index_mtime < cache_last_modified; | 473 return index_mtime < cache_last_modified; |
474 } | 474 } |
475 | 475 |
476 } // namespace disk_cache | 476 } // namespace disk_cache |
OLD | NEW |