Commit a6d14f74 authored by rvargas@chromium.org's avatar rvargas@chromium.org

Remove some PlatformFile uses from WebKit

BUG=322664
R=kinuko@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251787 0039d316-1c4b-4281-b951-d872f2087c98
parent 026d85b0
......@@ -7,10 +7,10 @@
#include <string>
#include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
#include "base/platform_file.h"
#include "base/run_loop.h"
#include "base/threading/thread.h"
#include "net/base/io_buffer.h"
......@@ -135,14 +135,9 @@ TEST_F(LocalFileStreamReaderTest, NonExistent) {
TEST_F(LocalFileStreamReaderTest, Empty) {
base::FilePath empty_path = test_dir().AppendASCII("empty");
base::PlatformFileError error = base::PLATFORM_FILE_OK;
base::PlatformFile file = base::CreatePlatformFile(
empty_path,
base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ,
NULL, &error);
ASSERT_EQ(base::PLATFORM_FILE_OK, error);
ASSERT_NE(base::kInvalidPlatformFileValue, file);
base::ClosePlatformFile(file);
base::File file(empty_path, base::File::FLAG_CREATE | base::File::FLAG_READ);
ASSERT_TRUE(file.IsValid());
file.Close();
scoped_ptr<LocalFileStreamReader> reader(
CreateFileReader(empty_path, 0, base::Time()));
......
......@@ -10,9 +10,9 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/platform_file.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "net/base/net_errors.h"
......@@ -828,14 +828,11 @@ void DatabaseTracker::ClearSessionOnlyOrigins() {
for (std::vector<base::string16>::iterator database = databases.begin();
database != databases.end(); ++database) {
base::PlatformFile file_handle = base::CreatePlatformFile(
GetFullDBFilePath(*origin, *database),
base::PLATFORM_FILE_OPEN_ALWAYS |
base::PLATFORM_FILE_SHARE_DELETE |
base::PLATFORM_FILE_DELETE_ON_CLOSE |
base::PLATFORM_FILE_READ,
NULL, NULL);
base::ClosePlatformFile(file_handle);
base::File file(GetFullDBFilePath(*origin, *database),
base::File::FLAG_OPEN_ALWAYS |
base::File::FLAG_SHARE_DELETE |
base::File::FLAG_DELETE_ON_CLOSE |
base::File::FLAG_READ);
}
DeleteOrigin(*origin, true);
}
......
......@@ -3,12 +3,12 @@
// found in the LICENSE file.
#include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/platform_file.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "net/base/net_errors.h"
......@@ -173,19 +173,11 @@ class TestQuotaManagerProxy : public quota::QuotaManagerProxy {
bool EnsureFileOfSize(const base::FilePath& file_path, int64 length) {
base::PlatformFileError error_code(base::PLATFORM_FILE_ERROR_FAILED);
base::PlatformFile file =
base::CreatePlatformFile(
file_path,
base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE,
NULL,
&error_code);
if (error_code != base::PLATFORM_FILE_OK)
base::File file(file_path,
base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE);
if (!file.IsValid())
return false;
if (!base::TruncatePlatformFile(file, length))
error_code = base::PLATFORM_FILE_ERROR_FAILED;
base::ClosePlatformFile(file);
return error_code == base::PLATFORM_FILE_OK;
return file.SetLength(length);
}
} // namespace
......
......@@ -9,6 +9,7 @@
#include <vector>
#include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -41,19 +42,14 @@ void CorruptDatabase(const base::FilePath& db_path,
EXPECT_FALSE(picked_file_path.empty());
EXPECT_NE(kuint64max, picked_file_number);
bool created = true;
base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED;
base::PlatformFile file =
CreatePlatformFile(picked_file_path,
base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE,
&created, &error);
EXPECT_EQ(base::PLATFORM_FILE_OK, error);
EXPECT_FALSE(created);
base::File file(picked_file_path,
base::File::FLAG_OPEN | base::File::FLAG_READ |
base::File::FLAG_WRITE);
ASSERT_TRUE(file.IsValid());
EXPECT_FALSE(file.created());
base::PlatformFileInfo file_info;
EXPECT_TRUE(base::GetPlatformFileInfo(file, &file_info));
base::File::Info file_info;
EXPECT_TRUE(file.GetInfo(&file_info));
if (offset < 0)
offset += file_info.size;
EXPECT_GE(offset, 0);
......@@ -62,8 +58,7 @@ void CorruptDatabase(const base::FilePath& db_path,
size = std::min(size, static_cast<size_t>(file_info.size - offset));
std::vector<char> buf(size);
int read_size = base::ReadPlatformFile(file, offset,
vector_as_array(&buf), buf.size());
int read_size = file.Read(offset, vector_as_array(&buf), buf.size());
EXPECT_LT(0, read_size);
EXPECT_GE(buf.size(), static_cast<size_t>(read_size));
buf.resize(read_size);
......@@ -71,12 +66,9 @@ void CorruptDatabase(const base::FilePath& db_path,
std::transform(buf.begin(), buf.end(), buf.begin(),
std::logical_not<char>());
int written_size = base::WritePlatformFile(file, offset,
vector_as_array(&buf), buf.size());
int written_size = file.Write(offset, vector_as_array(&buf), buf.size());
EXPECT_GT(written_size, 0);
EXPECT_EQ(buf.size(), static_cast<size_t>(written_size));
base::ClosePlatformFile(file);
}
void DeleteDatabaseFile(const base::FilePath& db_path,
......
......@@ -9,9 +9,9 @@
#include <vector>
#include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/platform_file.h"
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/leveldatabase/src/db/filename.h"
......@@ -224,15 +224,10 @@ TEST(SandboxOriginDatabaseTest, DatabaseRecoveryTest) {
const base::FilePath kGarbageDir = kFSDir.AppendASCII("foo");
const base::FilePath kGarbageFile = kGarbageDir.AppendASCII("bar");
EXPECT_TRUE(base::CreateDirectory(kGarbageDir));
bool created = false;
base::PlatformFileError error;
base::PlatformFile file = base::CreatePlatformFile(
kGarbageFile,
base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE,
&created, &error);
EXPECT_EQ(base::PLATFORM_FILE_OK, error);
EXPECT_TRUE(created);
EXPECT_TRUE(base::ClosePlatformFile(file));
base::File file(kGarbageFile,
base::File::FLAG_CREATE | base::File::FLAG_WRITE);
EXPECT_TRUE(file.IsValid());
file.Close();
// Corrupt database itself and last log entry to drop last 1 database
// operation. The database should detect the corruption and should recover
......
......@@ -5,11 +5,10 @@
#include "webkit/browser/fileapi/sandbox_prioritized_origin_database.h"
#include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/scoped_platform_file_closer.h"
#include "base/logging.h"
#include "base/pickle.h"
#include "base/platform_file.h"
#include "webkit/browser/fileapi/sandbox_isolated_origin_database.h"
#include "webkit/browser/fileapi/sandbox_origin_database.h"
......@@ -24,23 +23,15 @@ const base::FilePath::CharType kPrimaryOriginFile[] =
bool WritePrimaryOriginFile(const base::FilePath& path,
const std::string& origin) {
base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED;
bool created;
base::PlatformFile file = base::CreatePlatformFile(
path,
base::PLATFORM_FILE_OPEN_ALWAYS |
base::PLATFORM_FILE_WRITE,
&created, &error);
base::ScopedPlatformFileCloser closer(&file);
if (error != base::PLATFORM_FILE_OK ||
file == base::kInvalidPlatformFileValue)
base::File file(path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE);
if (!file.IsValid())
return false;
base::TruncatePlatformFile(file, 0);
if (!file.created())
file.SetLength(0);
Pickle pickle;
pickle.WriteString(origin);
base::WritePlatformFile(file, 0, static_cast<const char*>(pickle.data()),
pickle.size());
base::FlushPlatformFile(file);
file.Write(0, static_cast<const char*>(pickle.data()), pickle.size());
file.Flush();
return true;
}
......
......@@ -7,8 +7,8 @@
#include <string>
#include "base/file_util.h"
#include "base/files/file.h"
#include "base/logging.h"
#include "base/platform_file.h"
#include "base/rand_util.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -46,20 +46,14 @@ void SetUpOneTestCase(const base::FilePath& root_path,
ASSERT_TRUE(base::CreateDirectory(path));
return;
}
base::PlatformFileError error_code;
bool created = false;
int file_flags = base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_WRITE;
base::PlatformFile file_handle =
base::CreatePlatformFile(path, file_flags, &created, &error_code);
EXPECT_TRUE(created);
ASSERT_EQ(base::PLATFORM_FILE_OK, error_code);
ASSERT_NE(base::kInvalidPlatformFileValue, file_handle);
EXPECT_TRUE(base::ClosePlatformFile(file_handle));
if (test_case.data_file_size > 0U) {
base::File file(path,
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
ASSERT_TRUE(file.IsValid());
if (test_case.data_file_size) {
std::string content = base::RandBytesAsString(test_case.data_file_size);
EXPECT_LE(test_case.data_file_size, kint32max);
ASSERT_EQ(static_cast<int>(content.size()),
file_util::WriteFile(path, content.data(), content.size()));
file.Write(0, content.data(), static_cast<int>(content.size())));
}
}
......
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