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

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

Issue 18584011: Rename base::Delete to base::DeleteFile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/entry_unittest.cc ('k') | net/disk_cache/simple/simple_synchronous_entry.cc » ('j') | 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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 index_filename.DirName().AppendASCII("index_temp"); 44 index_filename.DirName().AppendASCII("index_temp");
45 int bytes_written = file_util::WriteFile( 45 int bytes_written = file_util::WriteFile(
46 temp_filename, 46 temp_filename,
47 reinterpret_cast<const char*>(pickle->data()), 47 reinterpret_cast<const char*>(pickle->data()),
48 pickle->size()); 48 pickle->size());
49 DCHECK_EQ(bytes_written, implicit_cast<int>(pickle->size())); 49 DCHECK_EQ(bytes_written, implicit_cast<int>(pickle->size()));
50 if (bytes_written != static_cast<int>(pickle->size())) { 50 if (bytes_written != static_cast<int>(pickle->size())) {
51 // TODO(felipeg): Add better error handling. 51 // TODO(felipeg): Add better error handling.
52 LOG(ERROR) << "Could not write Simple Cache index to temporary file: " 52 LOG(ERROR) << "Could not write Simple Cache index to temporary file: "
53 << temp_filename.value(); 53 << temp_filename.value();
54 base::Delete(temp_filename, /* recursive = */ false); 54 base::DeleteFile(temp_filename, /* recursive = */ false);
55 } else { 55 } else {
56 // Swap temp and index_file. 56 // Swap temp and index_file.
57 bool result = base::ReplaceFile(temp_filename, index_filename, NULL); 57 bool result = base::ReplaceFile(temp_filename, index_filename, NULL);
58 DCHECK(result); 58 DCHECK(result);
59 } 59 }
60 if (app_on_background) { 60 if (app_on_background) {
61 UMA_HISTOGRAM_TIMES("SimpleCache.IndexWriteToDiskTime.Background", 61 UMA_HISTOGRAM_TIMES("SimpleCache.IndexWriteToDiskTime.Background",
62 (base::TimeTicks::Now() - start_time)); 62 (base::TimeTicks::Now() - start_time));
63 } else { 63 } else {
64 UMA_HISTOGRAM_TIMES("SimpleCache.IndexWriteToDiskTime.Foreground", 64 UMA_HISTOGRAM_TIMES("SimpleCache.IndexWriteToDiskTime.Foreground",
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 base::Passed(&index_file_entries), 222 base::Passed(&index_file_entries),
223 force_index_flush)); 223 force_index_flush));
224 } 224 }
225 225
226 // static 226 // static
227 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::SyncLoadFromDisk( 227 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::SyncLoadFromDisk(
228 const base::FilePath& index_filename) { 228 const base::FilePath& index_filename) {
229 std::string contents; 229 std::string contents;
230 if (!file_util::ReadFileToString(index_filename, &contents)) { 230 if (!file_util::ReadFileToString(index_filename, &contents)) {
231 LOG(WARNING) << "Could not read Simple Index file."; 231 LOG(WARNING) << "Could not read Simple Index file.";
232 base::Delete(index_filename, false); 232 base::DeleteFile(index_filename, false);
233 return scoped_ptr<SimpleIndex::EntrySet>(); 233 return scoped_ptr<SimpleIndex::EntrySet>();
234 } 234 }
235 235
236 scoped_ptr<SimpleIndex::EntrySet> entries = 236 scoped_ptr<SimpleIndex::EntrySet> entries =
237 SimpleIndexFile::Deserialize(contents.data(), contents.size()); 237 SimpleIndexFile::Deserialize(contents.data(), contents.size());
238 if (!entries) { 238 if (!entries) {
239 base::Delete(index_filename, false); 239 base::DeleteFile(index_filename, false);
240 return scoped_ptr<SimpleIndex::EntrySet>(); 240 return scoped_ptr<SimpleIndex::EntrySet>();
241 } 241 }
242 242
243 return entries.Pass(); 243 return entries.Pass();
244 } 244 }
245 245
246 // static 246 // static
247 scoped_ptr<Pickle> SimpleIndexFile::Serialize( 247 scoped_ptr<Pickle> SimpleIndexFile::Serialize(
248 const SimpleIndexFile::IndexMetadata& index_metadata, 248 const SimpleIndexFile::IndexMetadata& index_metadata,
249 const SimpleIndex::EntrySet& entries) { 249 const SimpleIndex::EntrySet& entries) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 309 }
310 310
311 return index_file_entries.Pass(); 311 return index_file_entries.Pass();
312 } 312 }
313 313
314 // static 314 // static
315 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::SyncRestoreFromDisk( 315 scoped_ptr<SimpleIndex::EntrySet> SimpleIndexFile::SyncRestoreFromDisk(
316 const base::FilePath& index_file_path) { 316 const base::FilePath& index_file_path) {
317 LOG(INFO) << "Simple Cache Index is being restored from disk."; 317 LOG(INFO) << "Simple Cache Index is being restored from disk.";
318 318
319 base::Delete(index_file_path, /* recursive = */ false); 319 base::DeleteFile(index_file_path, /* recursive = */ false);
320 scoped_ptr<SimpleIndex::EntrySet> index_file_entries( 320 scoped_ptr<SimpleIndex::EntrySet> index_file_entries(
321 new SimpleIndex::EntrySet()); 321 new SimpleIndex::EntrySet());
322 322
323 // TODO(felipeg,gavinp): Fix this once we have a one-file per entry format. 323 // TODO(felipeg,gavinp): Fix this once we have a one-file per entry format.
324 COMPILE_ASSERT(kSimpleEntryFileCount == 3, 324 COMPILE_ASSERT(kSimpleEntryFileCount == 3,
325 file_pattern_must_match_file_count); 325 file_pattern_must_match_file_count);
326 326
327 const int kFileSuffixLength = sizeof("_0") - 1; 327 const int kFileSuffixLength = sizeof("_0") - 1;
328 const base::FilePath::StringType file_pattern = FILE_PATH_LITERAL("*_[0-2]"); 328 const base::FilePath::StringType file_pattern = FILE_PATH_LITERAL("*_[0-2]");
329 base::FileEnumerator enumerator(index_file_path.DirName(), 329 base::FileEnumerator enumerator(index_file_path.DirName(),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 if (!simple_util::GetMTime(index_filename, &index_mtime)) 380 if (!simple_util::GetMTime(index_filename, &index_mtime))
381 return true; 381 return true;
382 // Index file last_modified must be equal to the directory last_modified since 382 // Index file last_modified must be equal to the directory last_modified since
383 // the last operation we do is ReplaceFile in the 383 // the last operation we do is ReplaceFile in the
384 // SimpleIndexFile::WriteToDisk(). 384 // SimpleIndexFile::WriteToDisk().
385 // If not true, we need to restore the index. 385 // If not true, we need to restore the index.
386 return index_mtime < dir_mtime; 386 return index_mtime < dir_mtime;
387 } 387 }
388 388
389 } // namespace disk_cache 389 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/entry_unittest.cc ('k') | net/disk_cache/simple/simple_synchronous_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698