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 @@
#include <string>
#include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/scoped_temp_dir.h"
#include "base/platform_file.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
......@@ -98,17 +98,13 @@ TEST(ScopedTempDir, MultipleInvocations) {
TEST(ScopedTempDir, LockedTempDir) {
ScopedTempDir dir;
EXPECT_TRUE(dir.CreateUniqueTempDir());
int file_flags = base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_WRITE;
base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
FilePath file_path(dir.path().Append(FILE_PATH_LITERAL("temp")));
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);
base::File file(dir.path().Append(FILE_PATH_LITERAL("temp")),
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
EXPECT_TRUE(file.IsValid());
EXPECT_EQ(base::File::FILE_OK, file.error_details());
EXPECT_FALSE(dir.Delete()); // We should not be able to delete.
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.
EXPECT_TRUE(dir.Delete());
}
......
......@@ -6,8 +6,6 @@
#define NET_ANDROID_CERT_VERIFY_RESULT_ANDROID_H_
#include "base/basictypes.h"
#include "base/platform_file.h"
#include "net/base/net_export.h"
namespace net {
......
......@@ -10,7 +10,6 @@
#include "base/files/scoped_temp_dir.h"
#include "base/i18n/file_util_icu.h"
#include "base/message_loop/message_loop.h"
#include "base/platform_file.h"
#include "base/strings/stringprintf.h"
#include "net/base/directory_lister.h"
#include "net/base/net_errors.h"
......
......@@ -7,7 +7,6 @@
#include <fcntl.h>
#include "base/logging.h"
#include "base/platform_file.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/flash/format.h"
......@@ -22,41 +21,38 @@ Storage::Storage(const base::FilePath& path,
}
bool Storage::Init() {
int flags = base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_OPEN_ALWAYS;
int flags = base::File::FLAG_READ |
base::File::FLAG_WRITE |
base::File::FLAG_OPEN_ALWAYS;
file_ = base::CreatePlatformFile(path_, flags, NULL, NULL);
if (file_ == base::kInvalidPlatformFileValue)
file_.Initialize(path_, flags);
if (!file_.IsValid())
return false;
// TODO(agayev): if file already exists, do some validation and return either
// true or false based on the result.
#if defined(OS_LINUX)
fallocate(file_, 0, 0, size_);
fallocate(file_.GetPlatformFile(), 0, 0, size_);
#endif
return true;
}
Storage::~Storage() {
base::ClosePlatformFile(file_);
}
bool Storage::Read(void* buffer, int32 size, int32 offset) {
DCHECK(offset >= 0 && offset + size <= size_);
int rv = base::ReadPlatformFile(file_, offset, static_cast<char*>(buffer),
size);
int rv = file_.Read(offset, static_cast<char*>(buffer), size);
return rv == size;
}
bool Storage::Write(const void* buffer, int32 size, int32 offset) {
DCHECK(offset >= 0 && offset + size <= size_);
int rv = base::WritePlatformFile(file_, offset,
static_cast<const char*>(buffer), size);
int rv = file_.Write(offset, static_cast<const char*>(buffer), size);
return rv == size;
}
......
......@@ -6,7 +6,7 @@
#define NET_DISK_CACHE_FLASH_STORAGE_H_
#include "base/basictypes.h"
#include "base/platform_file.h"
#include "base/files/file.h"
#include "net/base/net_export.h"
namespace disk_cache {
......@@ -25,7 +25,7 @@ class NET_EXPORT_PRIVATE Storage {
private:
base::FilePath path_;
int32 size_;
base::PlatformFile file_;
base::File file_;
DISALLOW_COPY_AND_ASSIGN(Storage);
};
......
......@@ -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
// flush delay. This simple approach will be reconsidered if it does not allow
// for maintaining freshness.
base::PlatformFileInfo cache_dir_info;
base::Time cache_dir_mtime;
if (!simple_util::GetMTime(cache_directory, &cache_dir_mtime)) {
LOG(ERROR) << "Could obtain information about cache age";
......
......@@ -11,10 +11,10 @@
#include <utility>
#include <vector>
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/platform_file.h"
#include "base/time/time.h"
#include "net/base/cache_type.h"
#include "net/base/net_export.h"
......@@ -213,13 +213,13 @@ class SimpleSynchronousEntry {
// or if the file was not found and is allowed to be omitted if the
// corresponding stream is empty.
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
// 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.
bool MaybeCreateFile(int file_index,
FileRequired file_required,
base::PlatformFileError* out_error);
base::File::Error* out_error);
bool OpenFiles(bool had_index,
SimpleEntryStat* out_entry_stat);
bool CreateFiles(bool had_index,
......@@ -268,7 +268,7 @@ class SimpleSynchronousEntry {
bool CreateSparseFile();
// Closes the sparse data file.
bool CloseSparseFile();
void CloseSparseFile();
// Writes the header to the (newly-created) sparse file.
bool InitializeSparseFile();
......@@ -305,7 +305,7 @@ class SimpleSynchronousEntry {
base::FilePath GetFilenameFromFileIndex(int file_index);
bool sparse_file_open() const {
return sparse_file_ != base::kInvalidPlatformFileValue;
return sparse_file_.IsValid();
}
const net::CacheType cache_type_;
......@@ -316,7 +316,7 @@ class SimpleSynchronousEntry {
bool have_open_files_;
bool initialized_;
base::PlatformFile files_[kSimpleEntryFileCount];
base::File files_[kSimpleEntryFileCount];
// True if the corresponding stream is empty and therefore no on-disk file
// was created to store it.
......@@ -325,7 +325,7 @@ class SimpleSynchronousEntry {
typedef std::map<int64, SparseRange> SparseRangeOffsetMap;
typedef SparseRangeOffsetMap::iterator SparseRangeIterator;
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
// written).
int64 sparse_tail_offset_;
......
......@@ -66,7 +66,7 @@ NET_EXPORT_PRIVATE int64 GetFileSizeFromKeyAndDataSize(const std::string& key,
NET_EXPORT_PRIVATE int GetFileIndexFromStreamIndex(int stream_index);
// 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,
base::Time* out_mtime);
} // namespace simple_backend
......
......@@ -7,11 +7,11 @@
#include <cstring>
#include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/memory_mapped_file.h"
#include "base/logging.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_entry_format_history.h"
#include "third_party/zlib/zlib.h"
......@@ -30,20 +30,17 @@ void LogMessageFailedUpgradeFromVersion(int version) {
}
bool WriteFakeIndexFile(const base::FilePath& file_name) {
base::PlatformFileError error;
base::PlatformFile file = base::CreatePlatformFile(
file_name,
base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE,
NULL,
&error);
base::File file(file_name, base::File::FLAG_CREATE | base::File::FLAG_WRITE);
if (!file.IsValid())
return false;
disk_cache::FakeIndexData file_contents;
file_contents.initial_magic_number =
disk_cache::simplecache_v5::kSimpleInitialMagicNumber;
file_contents.version = disk_cache::kSimpleVersion;
int bytes_written = base::WritePlatformFile(
file, 0, reinterpret_cast<char*>(&file_contents), sizeof(file_contents));
if (!base::ClosePlatformFile(file) ||
bytes_written != sizeof(file_contents)) {
int bytes_written = file.Write(0, reinterpret_cast<char*>(&file_contents),
sizeof(file_contents));
if (bytes_written != sizeof(file_contents)) {
LOG(ERROR) << "Failed to write fake index file: "
<< file_name.LossyDisplayName();
return false;
......@@ -136,29 +133,27 @@ bool UpgradeSimpleCacheOnDisk(const base::FilePath& path) {
// 2. The Simple Backend has pickled file format for the index making it hacky
// to have the magic in the right place.
const base::FilePath fake_index = path.AppendASCII(kFakeIndexFileName);
base::PlatformFileError error;
base::PlatformFile fake_index_file = base::CreatePlatformFile(
fake_index,
base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
NULL,
&error);
if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) {
return WriteFakeIndexFile(fake_index);
} else if (error != base::PLATFORM_FILE_OK) {
base::File fake_index_file(fake_index,
base::File::FLAG_OPEN | base::File::FLAG_READ);
if (!fake_index_file.IsValid()) {
if (fake_index_file.error_details() == base::File::FILE_ERROR_NOT_FOUND) {
return WriteFakeIndexFile(fake_index);
}
return false;
}
FakeIndexData file_header;
int bytes_read = base::ReadPlatformFile(fake_index_file,
0,
reinterpret_cast<char*>(&file_header),
sizeof(file_header));
if (!base::ClosePlatformFile(fake_index_file) ||
bytes_read != sizeof(file_header) ||
int bytes_read = fake_index_file.Read(0,
reinterpret_cast<char*>(&file_header),
sizeof(file_header));
if (bytes_read != sizeof(file_header) ||
file_header.initial_magic_number !=
disk_cache::simplecache_v5::kSimpleInitialMagicNumber) {
LOG(ERROR) << "File structure does not match the disk cache backend.";
return false;
}
fake_index_file.Close();
uint32 version_from = file_header.version;
if (version_from < kMinVersionAbleToUpgrade ||
......
......@@ -23,7 +23,6 @@
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/message_loop/message_loop.h"
#include "base/platform_file.h"
#include "base/strings/string_util.h"
#include "base/synchronization/lock.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