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..c6a29a28333d99d2617adfa7f26911760c632177 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_ALWAYS | 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; |
@@ -332,10 +341,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 +359,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); |
pasko
2014/10/29 13:01:01
maybe a TODO: it seems it would be cleaner and fas
gavinp
2014/11/20 15:43:03
Fair point; in this case I suppose we could zero t
pasko
2014/11/20 16:19:32
yes, truncate+overwrite should also work.
But on
|
} |
// static |
@@ -434,7 +447,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; |