Commit 306677bb authored by rvargas@chromium.org's avatar rvargas@chromium.org

Convert most of base and net to use base::File

BUG=322664
R=thakis@chromium.org

Review URL: https://codereview.chromium.org/125643002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243852 0039d316-1c4b-4281-b951-d872f2087c98
parent b9e37058
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#include <string> #include <string>
#include "base/file_util.h" #include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/platform_file.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace base { namespace base {
...@@ -98,17 +98,13 @@ TEST(ScopedTempDir, MultipleInvocations) { ...@@ -98,17 +98,13 @@ TEST(ScopedTempDir, MultipleInvocations) {
TEST(ScopedTempDir, LockedTempDir) { TEST(ScopedTempDir, LockedTempDir) {
ScopedTempDir dir; ScopedTempDir dir;
EXPECT_TRUE(dir.CreateUniqueTempDir()); EXPECT_TRUE(dir.CreateUniqueTempDir());
int file_flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::File file(dir.path().Append(FILE_PATH_LITERAL("temp")),
base::PLATFORM_FILE_WRITE; base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
base::PlatformFileError error_code = base::PLATFORM_FILE_OK; EXPECT_TRUE(file.IsValid());
FilePath file_path(dir.path().Append(FILE_PATH_LITERAL("temp"))); EXPECT_EQ(base::File::FILE_OK, file.error_details());
base::PlatformFile file = base::CreatePlatformFile(file_path, file_flags,
NULL, &error_code);
EXPECT_NE(base::kInvalidPlatformFileValue, file);
EXPECT_EQ(base::PLATFORM_FILE_OK, error_code);
EXPECT_FALSE(dir.Delete()); // We should not be able to delete. EXPECT_FALSE(dir.Delete()); // We should not be able to delete.
EXPECT_FALSE(dir.path().empty()); // We should still have a valid path. EXPECT_FALSE(dir.path().empty()); // We should still have a valid path.
EXPECT_TRUE(base::ClosePlatformFile(file)); file.Close();
// Now, we should be able to delete. // Now, we should be able to delete.
EXPECT_TRUE(dir.Delete()); EXPECT_TRUE(dir.Delete());
} }
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
#define NET_ANDROID_CERT_VERIFY_RESULT_ANDROID_H_ #define NET_ANDROID_CERT_VERIFY_RESULT_ANDROID_H_
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/platform_file.h"
#include "net/base/net_export.h"
namespace net { namespace net {
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/i18n/file_util_icu.h" #include "base/i18n/file_util_icu.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/platform_file.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "net/base/directory_lister.h" #include "net/base/directory_lister.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <fcntl.h> #include <fcntl.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/platform_file.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/disk_cache/flash/format.h" #include "net/disk_cache/flash/format.h"
...@@ -22,41 +21,38 @@ Storage::Storage(const base::FilePath& path, ...@@ -22,41 +21,38 @@ Storage::Storage(const base::FilePath& path,
} }
bool Storage::Init() { bool Storage::Init() {
int flags = base::PLATFORM_FILE_READ | int flags = base::File::FLAG_READ |
base::PLATFORM_FILE_WRITE | base::File::FLAG_WRITE |
base::PLATFORM_FILE_OPEN_ALWAYS; base::File::FLAG_OPEN_ALWAYS;
file_ = base::CreatePlatformFile(path_, flags, NULL, NULL); file_.Initialize(path_, flags);
if (file_ == base::kInvalidPlatformFileValue) if (!file_.IsValid())
return false; return false;
// TODO(agayev): if file already exists, do some validation and return either // TODO(agayev): if file already exists, do some validation and return either
// true or false based on the result. // true or false based on the result.
#if defined(OS_LINUX) #if defined(OS_LINUX)
fallocate(file_, 0, 0, size_); fallocate(file_.GetPlatformFile(), 0, 0, size_);
#endif #endif
return true; return true;
} }
Storage::~Storage() { Storage::~Storage() {
base::ClosePlatformFile(file_);
} }
bool Storage::Read(void* buffer, int32 size, int32 offset) { bool Storage::Read(void* buffer, int32 size, int32 offset) {
DCHECK(offset >= 0 && offset + size <= size_); DCHECK(offset >= 0 && offset + size <= size_);
int rv = base::ReadPlatformFile(file_, offset, static_cast<char*>(buffer), int rv = file_.Read(offset, static_cast<char*>(buffer), size);
size);
return rv == size; return rv == size;
} }
bool Storage::Write(const void* buffer, int32 size, int32 offset) { bool Storage::Write(const void* buffer, int32 size, int32 offset) {
DCHECK(offset >= 0 && offset + size <= size_); DCHECK(offset >= 0 && offset + size <= size_);
int rv = base::WritePlatformFile(file_, offset, int rv = file_.Write(offset, static_cast<const char*>(buffer), size);
static_cast<const char*>(buffer), size);
return rv == size; return rv == size;
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define NET_DISK_CACHE_FLASH_STORAGE_H_ #define NET_DISK_CACHE_FLASH_STORAGE_H_
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/platform_file.h" #include "base/files/file.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
namespace disk_cache { namespace disk_cache {
...@@ -25,7 +25,7 @@ class NET_EXPORT_PRIVATE Storage { ...@@ -25,7 +25,7 @@ class NET_EXPORT_PRIVATE Storage {
private: private:
base::FilePath path_; base::FilePath path_;
int32 size_; int32 size_;
base::PlatformFile file_; base::File file_;
DISALLOW_COPY_AND_ASSIGN(Storage); DISALLOW_COPY_AND_ASSIGN(Storage);
}; };
......
...@@ -195,7 +195,6 @@ void SimpleIndexFile::SyncWriteToDisk(net::CacheType cache_type, ...@@ -195,7 +195,6 @@ void SimpleIndexFile::SyncWriteToDisk(net::CacheType cache_type,
// part of a Create operation does not fit into the time budget for the index // part of a Create operation does not fit into the time budget for the index
// flush delay. This simple approach will be reconsidered if it does not allow // flush delay. This simple approach will be reconsidered if it does not allow
// for maintaining freshness. // for maintaining freshness.
base::PlatformFileInfo cache_dir_info;
base::Time cache_dir_mtime; base::Time cache_dir_mtime;
if (!simple_util::GetMTime(cache_directory, &cache_dir_mtime)) { if (!simple_util::GetMTime(cache_directory, &cache_dir_mtime)) {
LOG(ERROR) << "Could obtain information about cache age"; LOG(ERROR) << "Could obtain information about cache age";
......
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/files/file.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/platform_file.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "net/base/cache_type.h" #include "net/base/cache_type.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
...@@ -213,13 +213,13 @@ class SimpleSynchronousEntry { ...@@ -213,13 +213,13 @@ class SimpleSynchronousEntry {
// or if the file was not found and is allowed to be omitted if the // or if the file was not found and is allowed to be omitted if the
// corresponding stream is empty. // corresponding stream is empty.
bool MaybeOpenFile(int file_index, bool MaybeOpenFile(int file_index,
base::PlatformFileError* out_error); base::File::Error* out_error);
// Creates one of the cache entry files if necessary. If the file is allowed // Creates one of the cache entry files if necessary. If the file is allowed
// to be omitted if the corresponding stream is empty, and if |file_required| // to be omitted if the corresponding stream is empty, and if |file_required|
// is FILE_NOT_REQUIRED, then the file is not created; otherwise, it is. // is FILE_NOT_REQUIRED, then the file is not created; otherwise, it is.
bool MaybeCreateFile(int file_index, bool MaybeCreateFile(int file_index,
FileRequired file_required, FileRequired file_required,
base::PlatformFileError* out_error); base::File::Error* out_error);
bool OpenFiles(bool had_index, bool OpenFiles(bool had_index,
SimpleEntryStat* out_entry_stat); SimpleEntryStat* out_entry_stat);
bool CreateFiles(bool had_index, bool CreateFiles(bool had_index,
...@@ -268,7 +268,7 @@ class SimpleSynchronousEntry { ...@@ -268,7 +268,7 @@ class SimpleSynchronousEntry {
bool CreateSparseFile(); bool CreateSparseFile();
// Closes the sparse data file. // Closes the sparse data file.
bool CloseSparseFile(); void CloseSparseFile();
// Writes the header to the (newly-created) sparse file. // Writes the header to the (newly-created) sparse file.
bool InitializeSparseFile(); bool InitializeSparseFile();
...@@ -305,7 +305,7 @@ class SimpleSynchronousEntry { ...@@ -305,7 +305,7 @@ class SimpleSynchronousEntry {
base::FilePath GetFilenameFromFileIndex(int file_index); base::FilePath GetFilenameFromFileIndex(int file_index);
bool sparse_file_open() const { bool sparse_file_open() const {
return sparse_file_ != base::kInvalidPlatformFileValue; return sparse_file_.IsValid();
} }
const net::CacheType cache_type_; const net::CacheType cache_type_;
...@@ -316,7 +316,7 @@ class SimpleSynchronousEntry { ...@@ -316,7 +316,7 @@ class SimpleSynchronousEntry {
bool have_open_files_; bool have_open_files_;
bool initialized_; bool initialized_;
base::PlatformFile files_[kSimpleEntryFileCount]; base::File files_[kSimpleEntryFileCount];
// True if the corresponding stream is empty and therefore no on-disk file // True if the corresponding stream is empty and therefore no on-disk file
// was created to store it. // was created to store it.
...@@ -325,7 +325,7 @@ class SimpleSynchronousEntry { ...@@ -325,7 +325,7 @@ class SimpleSynchronousEntry {
typedef std::map<int64, SparseRange> SparseRangeOffsetMap; typedef std::map<int64, SparseRange> SparseRangeOffsetMap;
typedef SparseRangeOffsetMap::iterator SparseRangeIterator; typedef SparseRangeOffsetMap::iterator SparseRangeIterator;
SparseRangeOffsetMap sparse_ranges_; SparseRangeOffsetMap sparse_ranges_;
base::PlatformFile sparse_file_; base::File sparse_file_;
// Offset of the end of the sparse file (where the next sparse range will be // Offset of the end of the sparse file (where the next sparse range will be
// written). // written).
int64 sparse_tail_offset_; int64 sparse_tail_offset_;
......
...@@ -66,7 +66,7 @@ NET_EXPORT_PRIVATE int64 GetFileSizeFromKeyAndDataSize(const std::string& key, ...@@ -66,7 +66,7 @@ NET_EXPORT_PRIVATE int64 GetFileSizeFromKeyAndDataSize(const std::string& key,
NET_EXPORT_PRIVATE int GetFileIndexFromStreamIndex(int stream_index); NET_EXPORT_PRIVATE int GetFileIndexFromStreamIndex(int stream_index);
// Fills |out_time| with the time the file last modified time. Unlike the // Fills |out_time| with the time the file last modified time. Unlike the
// functions in platform_file.h, the time resolution is milliseconds. // functions in file.h, the time resolution is milliseconds.
NET_EXPORT_PRIVATE bool GetMTime(const base::FilePath& path, NET_EXPORT_PRIVATE bool GetMTime(const base::FilePath& path,
base::Time* out_mtime); base::Time* out_mtime);
} // namespace simple_backend } // namespace simple_backend
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
#include <cstring> #include <cstring>
#include "base/file_util.h" #include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/memory_mapped_file.h" #include "base/files/memory_mapped_file.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/pickle.h" #include "base/pickle.h"
#include "base/platform_file.h"
#include "net/disk_cache/simple/simple_backend_version.h" #include "net/disk_cache/simple/simple_backend_version.h"
#include "net/disk_cache/simple/simple_entry_format_history.h" #include "net/disk_cache/simple/simple_entry_format_history.h"
#include "third_party/zlib/zlib.h" #include "third_party/zlib/zlib.h"
...@@ -30,20 +30,17 @@ void LogMessageFailedUpgradeFromVersion(int version) { ...@@ -30,20 +30,17 @@ void LogMessageFailedUpgradeFromVersion(int version) {
} }
bool WriteFakeIndexFile(const base::FilePath& file_name) { bool WriteFakeIndexFile(const base::FilePath& file_name) {
base::PlatformFileError error; base::File file(file_name, base::File::FLAG_CREATE | base::File::FLAG_WRITE);
base::PlatformFile file = base::CreatePlatformFile( if (!file.IsValid())
file_name, return false;
base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE,
NULL,
&error);
disk_cache::FakeIndexData file_contents; disk_cache::FakeIndexData file_contents;
file_contents.initial_magic_number = file_contents.initial_magic_number =
disk_cache::simplecache_v5::kSimpleInitialMagicNumber; disk_cache::simplecache_v5::kSimpleInitialMagicNumber;
file_contents.version = disk_cache::kSimpleVersion; file_contents.version = disk_cache::kSimpleVersion;
int bytes_written = base::WritePlatformFile( int bytes_written = file.Write(0, reinterpret_cast<char*>(&file_contents),
file, 0, reinterpret_cast<char*>(&file_contents), sizeof(file_contents)); sizeof(file_contents));
if (!base::ClosePlatformFile(file) || if (bytes_written != sizeof(file_contents)) {
bytes_written != sizeof(file_contents)) {
LOG(ERROR) << "Failed to write fake index file: " LOG(ERROR) << "Failed to write fake index file: "
<< file_name.LossyDisplayName(); << file_name.LossyDisplayName();
return false; return false;
...@@ -136,29 +133,27 @@ bool UpgradeSimpleCacheOnDisk(const base::FilePath& path) { ...@@ -136,29 +133,27 @@ bool UpgradeSimpleCacheOnDisk(const base::FilePath& path) {
// 2. The Simple Backend has pickled file format for the index making it hacky // 2. The Simple Backend has pickled file format for the index making it hacky
// to have the magic in the right place. // to have the magic in the right place.
const base::FilePath fake_index = path.AppendASCII(kFakeIndexFileName); const base::FilePath fake_index = path.AppendASCII(kFakeIndexFileName);
base::PlatformFileError error; base::File fake_index_file(fake_index,
base::PlatformFile fake_index_file = base::CreatePlatformFile( base::File::FLAG_OPEN | base::File::FLAG_READ);
fake_index,
base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, if (!fake_index_file.IsValid()) {
NULL, if (fake_index_file.error_details() == base::File::FILE_ERROR_NOT_FOUND) {
&error); return WriteFakeIndexFile(fake_index);
if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) { }
return WriteFakeIndexFile(fake_index);
} else if (error != base::PLATFORM_FILE_OK) {
return false; return false;
} }
FakeIndexData file_header; FakeIndexData file_header;
int bytes_read = base::ReadPlatformFile(fake_index_file, int bytes_read = fake_index_file.Read(0,
0, reinterpret_cast<char*>(&file_header),
reinterpret_cast<char*>(&file_header), sizeof(file_header));
sizeof(file_header)); if (bytes_read != sizeof(file_header) ||
if (!base::ClosePlatformFile(fake_index_file) ||
bytes_read != sizeof(file_header) ||
file_header.initial_magic_number != file_header.initial_magic_number !=
disk_cache::simplecache_v5::kSimpleInitialMagicNumber) { disk_cache::simplecache_v5::kSimpleInitialMagicNumber) {
LOG(ERROR) << "File structure does not match the disk cache backend."; LOG(ERROR) << "File structure does not match the disk cache backend.";
return false; return false;
} }
fake_index_file.Close();
uint32 version_from = file_header.version; uint32 version_from = file_header.version;
if (version_from < kMinVersionAbleToUpgrade || if (version_from < kMinVersionAbleToUpgrade ||
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/platform_file.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/task_runner.h" #include "base/task_runner.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment