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

Unified Diff: net/disk_cache/simple/simple_index_file.cc

Issue 683113005: Update from chromium https://crrev.com/302282 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_index_file.cc
diff --git a/net/disk_cache/simple/simple_index_file.cc b/net/disk_cache/simple/simple_index_file.cc
index d819c9fcbd0a3f2a231da774d09698678e9ee281..37347c8ad0d458d05bc0980a639f5591919ea021 100644
--- a/net/disk_cache/simple/simple_index_file.cc
+++ b/net/disk_cache/simple/simple_index_file.cc
@@ -6,6 +6,7 @@
#include <vector>
+#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/hash.h"
@@ -22,6 +23,8 @@
#include "net/disk_cache/simple/simple_util.h"
#include "third_party/zlib/zlib.h"
+using base::File;
+
namespace disk_cache {
namespace {
@@ -66,10 +69,16 @@ void UmaRecordIndexInitMethod(IndexInitMethod method,
}
bool WritePickleFile(Pickle* pickle, const base::FilePath& file_name) {
- int bytes_written = base::WriteFile(
- file_name, static_cast<const char*>(pickle->data()), pickle->size());
+ File file(
+ file_name,
+ File::FLAG_CREATE | File::FLAG_WRITE | File::FLAG_SHARE_DELETE);
+ if (!file.IsValid())
+ return false;
+
+ int bytes_written =
+ file.Write(0, static_cast<const char*>(pickle->data()), pickle->size());
if (bytes_written != implicit_cast<int>(pickle->size())) {
- base::DeleteFile(file_name, /* recursive = */ false);
+ simple_util::SimpleCacheDeleteFile(file_name);
return false;
}
return true;
@@ -95,7 +104,7 @@ void ProcessEntryFile(SimpleIndex::EntrySet* entries,
return;
}
- base::File::Info file_info;
+ File::Info file_info;
if (!base::GetFileInfo(file_path, &file_info)) {
LOG(ERROR) << "Could not get file info for " << file_path.value();
return;
@@ -213,8 +222,11 @@ void SimpleIndexFile::SyncWriteToDisk(net::CacheType cache_type,
}
// Atomically rename the temporary index file to become the real one.
- bool result = base::ReplaceFile(temp_index_filename, index_filename, NULL);
- DCHECK(result);
+ // TODO(gavinp): DCHECK when not shutting down, since that is very strange.
+ // The rename failing during shutdown is legal because it's legal to begin
+ // erasing a cache as soon as the destructor has been called.
+ if (!base::ReplaceFile(temp_index_filename, index_filename, NULL))
+ return;
if (app_on_background) {
SIMPLE_CACHE_UMA(TIMES,
@@ -332,10 +344,14 @@ void SimpleIndexFile::SyncLoadFromDisk(const base::FilePath& index_filename,
SimpleIndexLoadResult* out_result) {
out_result->Reset();
+ File file(index_filename,
+ File::FLAG_OPEN | File::FLAG_READ | File::FLAG_SHARE_DELETE);
+ if (!file.IsValid())
+ return;
+
base::MemoryMappedFile index_file_map;
- if (!index_file_map.Initialize(index_filename)) {
- LOG(WARNING) << "Could not map Simple Index file.";
- base::DeleteFile(index_filename, false);
+ if (!index_file_map.Initialize(file.Pass())) {
+ simple_util::SimpleCacheDeleteFile(index_filename);
return;
}
@@ -346,7 +362,7 @@ void SimpleIndexFile::SyncLoadFromDisk(const base::FilePath& index_filename,
out_result);
if (!out_result->did_load)
- base::DeleteFile(index_filename, false);
+ simple_util::SimpleCacheDeleteFile(index_filename);
}
// static
@@ -434,7 +450,7 @@ void SimpleIndexFile::SyncRestoreFromDisk(
const base::FilePath& index_file_path,
SimpleIndexLoadResult* out_result) {
VLOG(1) << "Simple Cache Index is being restored from disk.";
- base::DeleteFile(index_file_path, /* recursive = */ false);
+ simple_util::SimpleCacheDeleteFile(index_file_path);
out_result->Reset();
SimpleIndex::EntrySet* entries = &out_result->entries;
« 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