summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-03 22:44:09 +0000
committerrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-03 22:44:09 +0000
commit04ba1825f498cc4db75dcbb80e01682231a104d3 (patch)
treebdb2efd4dd0dac470ef6d56d9fa6e4e53c6e5b2d /net
parent52f5fe716bf5bdd89612235498d73b755b8f862b (diff)
downloadchromium_src-04ba1825f498cc4db75dcbb80e01682231a104d3.zip
chromium_src-04ba1825f498cc4db75dcbb80e01682231a104d3.tar.gz
chromium_src-04ba1825f498cc4db75dcbb80e01682231a104d3.tar.bz2
Net: Remove CreatePlatformFile from the disk cache.
BUG=322664 Review URL: https://codereview.chromium.org/221333003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261555 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/disk_cache/blockfile/backend_impl.cc31
-rw-r--r--net/disk_cache/blockfile/block_files.cc8
-rw-r--r--net/disk_cache/blockfile/file.h14
-rw-r--r--net/disk_cache/blockfile/file_ios.cc65
-rw-r--r--net/disk_cache/blockfile/file_posix.cc61
-rw-r--r--net/disk_cache/blockfile/file_win.cc83
-rw-r--r--net/disk_cache/disk_cache_test_util.cc13
-rw-r--r--net/disk_cache/entry_unittest.cc37
8 files changed, 125 insertions, 187 deletions
diff --git a/net/disk_cache/blockfile/backend_impl.cc b/net/disk_cache/blockfile/backend_impl.cc
index af84b10..49ff0c7 100644
--- a/net/disk_cache/blockfile/backend_impl.cc
+++ b/net/disk_cache/blockfile/backend_impl.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/file_util.h"
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/hash.h"
#include "base/message_loop/message_loop.h"
@@ -668,15 +669,12 @@ bool BackendImpl::CreateExternalFile(Addr* address) {
continue;
}
base::FilePath name = GetFileName(file_address);
- int flags = base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_WRITE |
- base::PLATFORM_FILE_CREATE |
- base::PLATFORM_FILE_EXCLUSIVE_WRITE;
- base::PlatformFileError error;
- scoped_refptr<disk_cache::File> file(new disk_cache::File(
- base::CreatePlatformFile(name, flags, NULL, &error)));
- if (!file->IsValid()) {
- if (error != base::PLATFORM_FILE_ERROR_EXISTS) {
+ int flags = base::File::FLAG_READ | base::File::FLAG_WRITE |
+ base::File::FLAG_CREATE | base::File::FLAG_EXCLUSIVE_WRITE;
+ base::File file(name, flags);
+ if (!file.IsValid()) {
+ base::File::Error error = file.error_details();
+ if (error != base::File::FILE_ERROR_EXISTS) {
LOG(ERROR) << "Unable to create file: " << error;
return false;
}
@@ -1266,17 +1264,16 @@ bool BackendImpl::InitBackingStore(bool* file_created) {
base::FilePath index_name = path_.AppendASCII(kIndexName);
- int flags = base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_WRITE |
- base::PLATFORM_FILE_OPEN_ALWAYS |
- base::PLATFORM_FILE_EXCLUSIVE_WRITE;
- scoped_refptr<disk_cache::File> file(new disk_cache::File(
- base::CreatePlatformFile(index_name, flags, file_created, NULL)));
-
- if (!file->IsValid())
+ int flags = base::File::FLAG_READ | base::File::FLAG_WRITE |
+ base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_EXCLUSIVE_WRITE;
+ base::File base_file(index_name, flags);
+ if (!base_file.IsValid())
return false;
bool ret = true;
+ *file_created = base_file.created();
+
+ scoped_refptr<disk_cache::File> file(new disk_cache::File(base_file.Pass()));
if (*file_created)
ret = CreateBackingStore(file.get());
diff --git a/net/disk_cache/blockfile/block_files.cc b/net/disk_cache/blockfile/block_files.cc
index ac6114e..ae2e1b3 100644
--- a/net/disk_cache/blockfile/block_files.cc
+++ b/net/disk_cache/blockfile/block_files.cc
@@ -445,12 +445,10 @@ bool BlockFiles::IsValid(Addr address) {
bool BlockFiles::CreateBlockFile(int index, FileType file_type, bool force) {
base::FilePath name = Name(index);
- int flags =
- force ? base::PLATFORM_FILE_CREATE_ALWAYS : base::PLATFORM_FILE_CREATE;
- flags |= base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE;
+ int flags = force ? base::File::FLAG_CREATE_ALWAYS : base::File::FLAG_CREATE;
+ flags |= base::File::FLAG_WRITE | base::File::FLAG_EXCLUSIVE_WRITE;
- scoped_refptr<File> file(new File(
- base::CreatePlatformFile(name, flags, NULL, NULL)));
+ scoped_refptr<File> file(new File(base::File(name, flags)));
if (!file->IsValid())
return false;
diff --git a/net/disk_cache/blockfile/file.h b/net/disk_cache/blockfile/file.h
index 437299b..9425d59 100644
--- a/net/disk_cache/blockfile/file.h
+++ b/net/disk_cache/blockfile/file.h
@@ -7,8 +7,8 @@
#ifndef NET_DISK_CACHE_BLOCKFILE_FILE_H_
#define NET_DISK_CACHE_BLOCKFILE_FILE_H_
+#include "base/files/file.h"
#include "base/memory/ref_counted.h"
-#include "base/platform_file.h"
#include "net/base/net_export.h"
namespace base {
@@ -39,15 +39,12 @@ class NET_EXPORT_PRIVATE File : public base::RefCounted<File> {
// Initializes the object to use the passed in file instead of opening it with
// the Init() call. No asynchronous operations can be performed with this
// object.
- explicit File(base::PlatformFile file);
+ explicit File(base::File file);
// Initializes the object to point to a given file. The file must aready exist
// on disk, and allow shared read and write.
bool Init(const base::FilePath& name);
- // Returns the handle or file descriptor.
- base::PlatformFile platform_file() const;
-
// Returns true if the file was opened properly.
bool IsValid() const;
@@ -76,6 +73,9 @@ class NET_EXPORT_PRIVATE File : public base::RefCounted<File> {
protected:
virtual ~File();
+ // Returns the handle or file descriptor.
+ base::PlatformFile platform_file() const;
+
private:
// Performs the actual asynchronous write. If notify is set and there is no
// callback, the call will be re-synchronized.
@@ -89,8 +89,8 @@ class NET_EXPORT_PRIVATE File : public base::RefCounted<File> {
bool init_;
bool mixed_;
- base::PlatformFile platform_file_; // Regular, asynchronous IO handle.
- base::PlatformFile sync_platform_file_; // Synchronous IO handle.
+ base::File base_file_; // Regular, asynchronous IO handle.
+ base::File sync_base_file_; // Synchronous IO handle.
DISALLOW_COPY_AND_ASSIGN(File);
};
diff --git a/net/disk_cache/blockfile/file_ios.cc b/net/disk_cache/blockfile/file_ios.cc
index 48443bf..4659e75 100644
--- a/net/disk_cache/blockfile/file_ios.cc
+++ b/net/disk_cache/blockfile/file_ios.cc
@@ -144,7 +144,7 @@ void FileInFlightIO::OnOperationComplete(disk_cache::BackgroundIO* operation,
callback->OnFileIOComplete(bytes);
}
-// A static object tha will broker all async operations.
+// A static object that will broker all async operations.
FileInFlightIO* s_file_operations = NULL;
// Returns the current FileInFlightIO.
@@ -166,62 +166,46 @@ void DeleteFileInFlightIO() {
namespace disk_cache {
-File::File(base::PlatformFile file)
+File::File(base::File file)
: init_(true),
mixed_(true),
- platform_file_(file),
- sync_platform_file_(base::kInvalidPlatformFileValue) {
+ base_file_(file.Pass()) {
}
bool File::Init(const base::FilePath& name) {
- if (init_)
+ if (base_file_.IsValid())
return false;
- int flags = base::PLATFORM_FILE_OPEN |
- base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_WRITE;
- platform_file_ = base::CreatePlatformFile(name, flags, NULL, NULL);
- if (platform_file_ < 0) {
- platform_file_ = 0;
- return false;
- }
-
- init_ = true;
- return true;
-}
-
-base::PlatformFile File::platform_file() const {
- return platform_file_;
+ int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
+ base::File::FLAG_WRITE;
+ base_file_.Initialize(name, flags);
+ return base_file_.IsValid();
}
bool File::IsValid() const {
- if (!init_)
- return false;
- return (base::kInvalidPlatformFileValue != platform_file_);
+ return base_file_.IsValid();
}
bool File::Read(void* buffer, size_t buffer_len, size_t offset) {
- DCHECK(init_);
+ DCHECK(base_file_.IsValid());
if (buffer_len > static_cast<size_t>(kint32max) ||
offset > static_cast<size_t>(kint32max)) {
return false;
}
- int ret = base::ReadPlatformFile(platform_file_, offset,
- static_cast<char*>(buffer), buffer_len);
+ int ret = base_file_.Read(offset, static_cast<char*>(buffer), buffer_len);
return (static_cast<size_t>(ret) == buffer_len);
}
bool File::Write(const void* buffer, size_t buffer_len, size_t offset) {
- DCHECK(init_);
+ DCHECK(base_file_.IsValid());
if (buffer_len > static_cast<size_t>(kint32max) ||
offset > static_cast<size_t>(kint32max)) {
return false;
}
- int ret = base::WritePlatformFile(platform_file_, offset,
- static_cast<const char*>(buffer),
- buffer_len);
+ int ret = base_file_.Write(offset, static_cast<const char*>(buffer),
+ buffer_len);
return (static_cast<size_t>(ret) == buffer_len);
}
@@ -230,7 +214,7 @@ bool File::Write(const void* buffer, size_t buffer_len, size_t offset) {
// closed while the IO is in flight).
bool File::Read(void* buffer, size_t buffer_len, size_t offset,
FileIOCallback* callback, bool* completed) {
- DCHECK(init_);
+ DCHECK(base_file_.IsValid());
if (!callback) {
if (completed)
*completed = true;
@@ -248,7 +232,7 @@ bool File::Read(void* buffer, size_t buffer_len, size_t offset,
bool File::Write(const void* buffer, size_t buffer_len, size_t offset,
FileIOCallback* callback, bool* completed) {
- DCHECK(init_);
+ DCHECK(base_file_.IsValid());
if (!callback) {
if (completed)
*completed = true;
@@ -259,17 +243,16 @@ bool File::Write(const void* buffer, size_t buffer_len, size_t offset,
}
bool File::SetLength(size_t length) {
- DCHECK(init_);
+ DCHECK(base_file_.IsValid());
if (length > kuint32max)
return false;
- return base::TruncatePlatformFile(platform_file_, length);
+ return base_file_.SetLength(length);
}
size_t File::GetLength() {
- DCHECK(init_);
- int64 len = base::SeekPlatformFile(platform_file_,
- base::PLATFORM_FILE_FROM_END, 0);
+ DCHECK(base_file_.IsValid());
+ int64 len = base_file_.GetLength();
if (len > static_cast<int64>(kuint32max))
return kuint32max;
@@ -292,13 +275,15 @@ void File::DropPendingIO() {
}
File::~File() {
- if (IsValid())
- base::ClosePlatformFile(platform_file_);
+}
+
+base::PlatformFile File::platform_file() const {
+ return base_file_.GetPlatformFile();
}
bool File::AsyncWrite(const void* buffer, size_t buffer_len, size_t offset,
FileIOCallback* callback, bool* completed) {
- DCHECK(init_);
+ DCHECK(base_file_.IsValid());
if (buffer_len > ULONG_MAX || offset > ULONG_MAX)
return false;
diff --git a/net/disk_cache/blockfile/file_posix.cc b/net/disk_cache/blockfile/file_posix.cc
index 7af0f36..c451aa3 100644
--- a/net/disk_cache/blockfile/file_posix.cc
+++ b/net/disk_cache/blockfile/file_posix.cc
@@ -34,68 +34,52 @@ base::LazyInstance<FileWorkerPool>::Leaky s_worker_pool =
namespace disk_cache {
-File::File(base::PlatformFile file)
+File::File(base::File file)
: init_(true),
mixed_(true),
- platform_file_(file),
- sync_platform_file_(base::kInvalidPlatformFileValue) {
+ base_file_(file.Pass()) {
}
bool File::Init(const base::FilePath& name) {
- if (init_)
+ if (base_file_.IsValid())
return false;
- int flags = base::PLATFORM_FILE_OPEN |
- base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_WRITE;
- platform_file_ = base::CreatePlatformFile(name, flags, NULL, NULL);
- if (platform_file_ < 0) {
- platform_file_ = 0;
- return false;
- }
-
- init_ = true;
- return true;
-}
-
-base::PlatformFile File::platform_file() const {
- return platform_file_;
+ int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
+ base::File::FLAG_WRITE;
+ base_file_.Initialize(name, flags);
+ return base_file_.IsValid();
}
bool File::IsValid() const {
- if (!init_)
- return false;
- return (base::kInvalidPlatformFileValue != platform_file_);
+ return base_file_.IsValid();
}
bool File::Read(void* buffer, size_t buffer_len, size_t offset) {
- DCHECK(init_);
+ DCHECK(base_file_.IsValid());
if (buffer_len > static_cast<size_t>(kint32max) ||
offset > static_cast<size_t>(kint32max)) {
return false;
}
- int ret = base::ReadPlatformFile(platform_file_, offset,
- static_cast<char*>(buffer), buffer_len);
+ int ret = base_file_.Read(offset, static_cast<char*>(buffer), buffer_len);
return (static_cast<size_t>(ret) == buffer_len);
}
bool File::Write(const void* buffer, size_t buffer_len, size_t offset) {
- DCHECK(init_);
+ DCHECK(base_file_.IsValid());
if (buffer_len > static_cast<size_t>(kint32max) ||
offset > static_cast<size_t>(kint32max)) {
return false;
}
- int ret = base::WritePlatformFile(platform_file_, offset,
- static_cast<const char*>(buffer),
- buffer_len);
+ int ret = base_file_.Write(offset, static_cast<const char*>(buffer),
+ buffer_len);
return (static_cast<size_t>(ret) == buffer_len);
}
bool File::Read(void* buffer, size_t buffer_len, size_t offset,
FileIOCallback* callback, bool* completed) {
- DCHECK(init_);
+ DCHECK(base_file_.IsValid());
if (!callback) {
if (completed)
*completed = true;
@@ -118,7 +102,7 @@ bool File::Read(void* buffer, size_t buffer_len, size_t offset,
bool File::Write(const void* buffer, size_t buffer_len, size_t offset,
FileIOCallback* callback, bool* completed) {
- DCHECK(init_);
+ DCHECK(base_file_.IsValid());
if (!callback) {
if (completed)
*completed = true;
@@ -140,17 +124,16 @@ bool File::Write(const void* buffer, size_t buffer_len, size_t offset,
}
bool File::SetLength(size_t length) {
- DCHECK(init_);
+ DCHECK(base_file_.IsValid());
if (length > kuint32max)
return false;
- return base::TruncatePlatformFile(platform_file_, length);
+ return base_file_.SetLength(length);
}
size_t File::GetLength() {
- DCHECK(init_);
- int64 len = base::SeekPlatformFile(platform_file_,
- base::PLATFORM_FILE_FROM_END, 0);
+ DCHECK(base_file_.IsValid());
+ int64 len = base_file_.GetLength();
if (len > static_cast<int64>(kuint32max))
return kuint32max;
@@ -173,8 +156,10 @@ void File::DropPendingIO() {
File::~File() {
- if (IsValid())
- base::ClosePlatformFile(platform_file_);
+}
+
+base::PlatformFile File::platform_file() const {
+ return base_file_.GetPlatformFile();
}
// Runs on a worker thread.
diff --git a/net/disk_cache/blockfile/file_win.cc b/net/disk_cache/blockfile/file_win.cc
index d8f5ecd..bf31312 100644
--- a/net/disk_cache/blockfile/file_win.cc
+++ b/net/disk_cache/blockfile/file_win.cc
@@ -69,9 +69,10 @@ MyOverlapped::MyOverlapped(disk_cache::File* file, size_t offset,
namespace disk_cache {
-File::File(base::PlatformFile file)
- : init_(true), mixed_(true), platform_file_(INVALID_HANDLE_VALUE),
- sync_platform_file_(file) {
+File::File(base::File file)
+ : init_(true),
+ mixed_(true),
+ sync_base_file_(file.Pass()) {
}
bool File::Init(const base::FilePath& name) {
@@ -81,46 +82,31 @@ bool File::Init(const base::FilePath& name) {
DWORD sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
DWORD access = GENERIC_READ | GENERIC_WRITE | DELETE;
- platform_file_ = CreateFile(name.value().c_str(), access, sharing, NULL,
- OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
+ base_file_ =
+ base::File(CreateFile(name.value().c_str(), access, sharing, NULL,
+ OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL));
- if (INVALID_HANDLE_VALUE == platform_file_)
+ if (!base_file_.IsValid())
return false;
base::MessageLoopForIO::current()->RegisterIOHandler(
- platform_file_, g_completion_handler.Pointer());
+ base_file_.GetPlatformFile(), g_completion_handler.Pointer());
init_ = true;
- sync_platform_file_ = CreateFile(name.value().c_str(), access, sharing, NULL,
- OPEN_EXISTING, 0, NULL);
+ sync_base_file_ =
+ base::File(CreateFile(name.value().c_str(), access, sharing, NULL,
+ OPEN_EXISTING, 0, NULL));
- if (INVALID_HANDLE_VALUE == sync_platform_file_)
+ if (!sync_base_file_.IsValid())
return false;
return true;
}
-File::~File() {
- if (!init_)
- return;
-
- if (INVALID_HANDLE_VALUE != platform_file_)
- CloseHandle(platform_file_);
- if (INVALID_HANDLE_VALUE != sync_platform_file_)
- CloseHandle(sync_platform_file_);
-}
-
-base::PlatformFile File::platform_file() const {
- DCHECK(init_);
- return (INVALID_HANDLE_VALUE == platform_file_) ? sync_platform_file_ :
- platform_file_;
-}
-
bool File::IsValid() const {
if (!init_)
return false;
- return (INVALID_HANDLE_VALUE != platform_file_ ||
- INVALID_HANDLE_VALUE != sync_platform_file_);
+ return base_file_.IsValid() || sync_base_file_.IsValid();
}
bool File::Read(void* buffer, size_t buffer_len, size_t offset) {
@@ -128,16 +114,9 @@ bool File::Read(void* buffer, size_t buffer_len, size_t offset) {
if (buffer_len > ULONG_MAX || offset > LONG_MAX)
return false;
- DWORD ret = SetFilePointer(sync_platform_file_, static_cast<LONG>(offset),
- NULL, FILE_BEGIN);
- if (INVALID_SET_FILE_POINTER == ret)
- return false;
-
- DWORD actual;
- DWORD size = static_cast<DWORD>(buffer_len);
- if (!ReadFile(sync_platform_file_, buffer, size, &actual, NULL))
- return false;
- return actual == size;
+ int ret = sync_base_file_.Read(offset, static_cast<char*>(buffer),
+ buffer_len);
+ return static_cast<int>(buffer_len) == ret;
}
bool File::Write(const void* buffer, size_t buffer_len, size_t offset) {
@@ -145,16 +124,9 @@ bool File::Write(const void* buffer, size_t buffer_len, size_t offset) {
if (buffer_len > ULONG_MAX || offset > ULONG_MAX)
return false;
- DWORD ret = SetFilePointer(sync_platform_file_, static_cast<LONG>(offset),
- NULL, FILE_BEGIN);
- if (INVALID_SET_FILE_POINTER == ret)
- return false;
-
- DWORD actual;
- DWORD size = static_cast<DWORD>(buffer_len);
- if (!WriteFile(sync_platform_file_, buffer, size, &actual, NULL))
- return false;
- return actual == size;
+ int ret = sync_base_file_.Write(offset, static_cast<const char*>(buffer),
+ buffer_len);
+ return static_cast<int>(buffer_len) == ret;
}
// We have to increase the ref counter of the file before performing the IO to
@@ -176,7 +148,8 @@ bool File::Read(void* buffer, size_t buffer_len, size_t offset,
DWORD size = static_cast<DWORD>(buffer_len);
DWORD actual;
- if (!ReadFile(platform_file_, buffer, size, &actual, data->overlapped())) {
+ if (!ReadFile(base_file_.GetPlatformFile(), buffer, size, &actual,
+ data->overlapped())) {
*completed = false;
if (GetLastError() == ERROR_IO_PENDING)
return true;
@@ -204,6 +177,15 @@ bool File::Write(const void* buffer, size_t buffer_len, size_t offset,
return AsyncWrite(buffer, buffer_len, offset, callback, completed);
}
+File::~File() {
+}
+
+base::PlatformFile File::platform_file() const {
+ DCHECK(init_);
+ return base_file_.IsValid() ? base_file_.GetPlatformFile() :
+ sync_base_file_.GetPlatformFile();
+}
+
bool File::AsyncWrite(const void* buffer, size_t buffer_len, size_t offset,
FileIOCallback* callback, bool* completed) {
DCHECK(init_);
@@ -216,7 +198,8 @@ bool File::AsyncWrite(const void* buffer, size_t buffer_len, size_t offset,
DWORD size = static_cast<DWORD>(buffer_len);
DWORD actual;
- if (!WriteFile(platform_file_, buffer, size, &actual, data->overlapped())) {
+ if (!WriteFile(base_file_.GetPlatformFile(), buffer, size, &actual,
+ data->overlapped())) {
*completed = false;
if (GetLastError() == ERROR_IO_PENDING)
return true;
diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc
index 2b23ee4..3f69492 100644
--- a/net/disk_cache/disk_cache_test_util.cc
+++ b/net/disk_cache/disk_cache_test_util.cc
@@ -4,6 +4,7 @@
#include "net/disk_cache/disk_cache_test_util.h"
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
@@ -42,16 +43,14 @@ void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls) {
}
bool CreateCacheTestFile(const base::FilePath& name) {
- int flags = base::PLATFORM_FILE_CREATE_ALWAYS |
- base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_WRITE;
+ int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_READ |
+ base::File::FLAG_WRITE;
- scoped_refptr<disk_cache::File> file(new disk_cache::File(
- base::CreatePlatformFile(name, flags, NULL, NULL)));
- if (!file->IsValid())
+ base::File file(name, flags);
+ if (!file.IsValid())
return false;
- file->SetLength(4 * 1024 * 1024);
+ file.SetLength(4 * 1024 * 1024);
return true;
}
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index d8334f3..64b26a1 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/file_util.h"
+#include "base/files/file.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/platform_thread.h"
@@ -2508,17 +2509,14 @@ bool DiskCacheEntryTest::SimpleCacheMakeBadChecksumEntry(const std::string& key,
// Corrupt the last byte of the data.
base::FilePath entry_file0_path = cache_path_.AppendASCII(
disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
- int flags = base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_OPEN;
- base::PlatformFile entry_file0 =
- base::CreatePlatformFile(entry_file0_path, flags, NULL, NULL);
- if (entry_file0 == base::kInvalidPlatformFileValue)
+ base::File entry_file0(entry_file0_path,
+ base::File::FLAG_WRITE | base::File::FLAG_OPEN);
+ if (!entry_file0.IsValid())
return false;
int64 file_offset =
sizeof(disk_cache::SimpleFileHeader) + key.size() + kDataSize - 2;
- EXPECT_EQ(1, base::WritePlatformFile(entry_file0, file_offset, "X", 1));
- if (!base::ClosePlatformFile(entry_file0))
- return false;
+ EXPECT_EQ(1, entry_file0.Write(file_offset, "X", 1));
*data_size = kDataSize;
return true;
}
@@ -2570,14 +2568,10 @@ TEST_F(DiskCacheEntryTest, SimpleCacheErrorThenDoom) {
}
bool TruncatePath(const base::FilePath& file_path, int64 length) {
- const int flags = base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_OPEN;
- base::PlatformFile file =
- base::CreatePlatformFile(file_path, flags, NULL, NULL);
- if (base::kInvalidPlatformFileValue == file)
+ base::File file(file_path, base::File::FLAG_WRITE | base::File::FLAG_OPEN);
+ if (!file.IsValid())
return false;
- const bool result = base::TruncatePlatformFile(file, length);
- base::ClosePlatformFile(file);
- return result;
+ return file.SetLength(length);
}
TEST_F(DiskCacheEntryTest, SimpleCacheNoEOF) {
@@ -3590,10 +3584,9 @@ TEST_F(DiskCacheEntryTest, SimpleCacheStream1SizeChanges) {
ASSERT_EQ(net::OK, OpenEntry(key, &entry));
base::FilePath entry_file0_path = cache_path_.AppendASCII(
disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
- int flags = base::PLATFORM_FILE_READ | base::PLATFORM_FILE_OPEN;
- base::PlatformFile entry_file0 =
- base::CreatePlatformFile(entry_file0_path, flags, NULL, NULL);
- ASSERT_TRUE(entry_file0 != base::kInvalidPlatformFileValue);
+ base::File entry_file0(entry_file0_path,
+ base::File::FLAG_READ | base::File::FLAG_OPEN);
+ ASSERT_TRUE(entry_file0.IsValid());
int data_size[disk_cache::kSimpleEntryStreamCount] = {kSize, stream1_size, 0};
int sparse_data_size = 0;
@@ -3601,11 +3594,9 @@ TEST_F(DiskCacheEntryTest, SimpleCacheStream1SizeChanges) {
base::Time::Now(), base::Time::Now(), data_size, sparse_data_size);
int eof_offset = entry_stat.GetEOFOffsetInFile(key, 0);
disk_cache::SimpleFileEOF eof_record;
- ASSERT_EQ(static_cast<int>(sizeof(eof_record)), base::ReadPlatformFile(
- entry_file0,
- eof_offset,
- reinterpret_cast<char*>(&eof_record),
- sizeof(eof_record)));
+ ASSERT_EQ(static_cast<int>(sizeof(eof_record)),
+ entry_file0.Read(eof_offset, reinterpret_cast<char*>(&eof_record),
+ sizeof(eof_record)));
EXPECT_EQ(disk_cache::kSimpleFinalMagicNumber, eof_record.final_magic_number);
EXPECT_TRUE((eof_record.flags & disk_cache::SimpleFileEOF::FLAG_HAS_CRC32) ==
disk_cache::SimpleFileEOF::FLAG_HAS_CRC32);