Add typemap for mojom::FileError
As part of File System API mojofication, converting the types used for
communicating between renderer and browser processes.
https://docs.google.com/document/d/16e7PbljOpkn9riFPsIyONVfiAyNUPztfBHBfov5W6v4
File::Error is returned from different layers for FS API, within
//storage/ and //base/, thus having this typemap makes more convenient
to send errors from any of these layers. Additionally it unifies all
File::Error instance on base::File::Error, removing mojo version.
Since //base/ can't depend on //components/ where mojom::FileError is
defined, thus we couldn't unify all uses on mojo enum instead.
Move mojom::FileError to //mojo/public/cpp/base/ since it's now a
typemap for an enum in //base.
This CL also fixes lint related to includes, now these 23 files don't
have any lint errors.
Bug: 787281
Change-Id: I891e57651dd35bb7a0d1edea03c06fe63c2e082a
Reviewed-on: https://chromium-review.googlesource.com/912910
Commit-Queue: Luciano Pacheco (SYD) <lucmult@chromium.org>
Reviewed-by: Sam McNally <sammc@chromium.org>
Reviewed-by: Elliot Glaysher <erg@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Reviewed-by: Sasha Morrissey <sashab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541360}diff --git a/chrome/services/file_util/zip_file_creator.cc b/chrome/services/file_util/zip_file_creator.cc
index f19a861..f026e1f 100644
--- a/chrome/services/file_util/zip_file_creator.cc
+++ b/chrome/services/file_util/zip_file_creator.cc
@@ -5,6 +5,7 @@
#include "chrome/services/file_util/zip_file_creator.h"
#include <memory>
+#include <utility>
#include "base/files/file.h"
#include "base/files/file_path.h"
@@ -78,11 +79,11 @@
dir_mojo = source_dir_mojo_.get();
} else {
base::FilePath relative_path = GetRelativePath(dir_path);
- filesystem::mojom::FileError error;
+ base::File::Error error;
source_dir_mojo_->OpenDirectory(
relative_path.value(), mojo::MakeRequest(&dir_mojo_ptr),
filesystem::mojom::kFlagRead | filesystem::mojom::kFlagOpen, &error);
- if (error != filesystem::mojom::FileError::OK) {
+ if (error != base::File::Error::FILE_OK) {
LOG(ERROR) << "Failed to open " << dir_path.value() << " error "
<< error;
return results;
@@ -92,9 +93,9 @@
base::Optional<std::vector<filesystem::mojom::DirectoryEntryPtr>>
directory_contents;
- filesystem::mojom::FileError error;
+ base::File::Error error;
dir_mojo->Read(&error, &directory_contents);
- if (error != filesystem::mojom::FileError::OK) {
+ if (error != base::File::Error::FILE_OK) {
LOG(ERROR) << "Failed to list content of " << dir_path.value()
<< " error " << error;
return results;
@@ -119,10 +120,10 @@
FileInfo GetFileInfo(const base::FilePath& absolute_path) {
base::FilePath relative_path = GetRelativePath(absolute_path);
- filesystem::mojom::FileError error;
+ base::File::Error error;
filesystem::mojom::FileInformationPtr file_info_mojo;
source_dir_mojo_->StatFile(relative_path.value(), &error, &file_info_mojo);
- if (error != filesystem::mojom::FileError::OK) {
+ if (error != base::File::Error::FILE_OK) {
LOG(ERROR) << "Failed to get last modified time of "
<< absolute_path.value() << " error " << error;
return FileInfo();
diff --git a/components/filesystem/directory_impl.cc b/components/filesystem/directory_impl.cc
index 0e28903..21e4adf 100644
--- a/components/filesystem/directory_impl.cc
+++ b/components/filesystem/directory_impl.cc
@@ -5,7 +5,9 @@
#include "components/filesystem/directory_impl.h"
#include <memory>
+#include <string>
#include <utility>
+#include <vector>
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
@@ -44,7 +46,7 @@
entries.push_back(std::move(entry));
}
- std::move(callback).Run(mojom::FileError::OK,
+ std::move(callback).Run(base::File::Error::FILE_OK,
entries.empty()
? base::nullopt
: base::make_optional(std::move(entries)));
@@ -60,8 +62,8 @@
uint32_t open_flags,
OpenFileCallback callback) {
base::FilePath path;
- mojom::FileError error = ValidatePath(raw_path, directory_path_, &path);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = ValidatePath(raw_path, directory_path_, &path);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error);
return;
}
@@ -70,7 +72,7 @@
// We must not return directories as files. In the file abstraction, we can
// fetch raw file descriptors over mojo pipes, and passing a file
// descriptor to a directory is a sandbox escape on Windows.
- std::move(callback).Run(mojom::FileError::NOT_A_FILE);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_NOT_A_FILE);
return;
}
@@ -86,14 +88,14 @@
lock_table_),
std::move(file));
}
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
void DirectoryImpl::OpenFileHandle(const std::string& raw_path,
uint32_t open_flags,
OpenFileHandleCallback callback) {
base::File file = OpenFileHandleImpl(raw_path, open_flags);
- mojom::FileError error = GetError(file);
+ base::File::Error error = GetError(file);
std::move(callback).Run(error, std::move(file));
}
@@ -117,15 +119,15 @@
uint32_t open_flags,
OpenDirectoryCallback callback) {
base::FilePath path;
- mojom::FileError error = ValidatePath(raw_path, directory_path_, &path);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = ValidatePath(raw_path, directory_path_, &path);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error);
return;
}
if (!base::DirectoryExists(path)) {
if (base::PathExists(path)) {
- std::move(callback).Run(mojom::FileError::NOT_A_DIRECTORY);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_NOT_A_DIRECTORY);
return;
}
@@ -133,13 +135,13 @@
open_flags & mojom::kFlagCreate)) {
// The directory doesn't exist, and we weren't passed parameters to
// create it.
- std::move(callback).Run(mojom::FileError::NOT_FOUND);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_NOT_FOUND);
return;
}
base::File::Error error;
if (!base::CreateDirectoryAndGetError(path, &error)) {
- std::move(callback).Run(static_cast<filesystem::mojom::FileError>(error));
+ std::move(callback).Run(error);
return;
}
}
@@ -150,104 +152,105 @@
std::move(directory));
}
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
void DirectoryImpl::Rename(const std::string& raw_old_path,
const std::string& raw_new_path,
RenameCallback callback) {
base::FilePath old_path;
- mojom::FileError error =
+ base::File::Error error =
ValidatePath(raw_old_path, directory_path_, &old_path);
- if (error != mojom::FileError::OK) {
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error);
return;
}
base::FilePath new_path;
error = ValidatePath(raw_new_path, directory_path_, &new_path);
- if (error != mojom::FileError::OK) {
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error);
return;
}
if (!base::Move(old_path, new_path)) {
- std::move(callback).Run(mojom::FileError::FAILED);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED);
return;
}
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
void DirectoryImpl::Replace(const std::string& raw_old_path,
const std::string& raw_new_path,
ReplaceCallback callback) {
base::FilePath old_path;
- mojom::FileError error =
+ base::File::Error error =
ValidatePath(raw_old_path, directory_path_, &old_path);
- if (error != mojom::FileError::OK) {
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error);
return;
}
base::FilePath new_path;
error = ValidatePath(raw_new_path, directory_path_, &new_path);
- if (error != mojom::FileError::OK) {
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error);
return;
}
base::File::Error file_error;
if (!base::ReplaceFile(old_path, new_path, &file_error)) {
- std::move(callback).Run(static_cast<mojom::FileError>(file_error));
+ std::move(callback).Run(file_error);
return;
}
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
void DirectoryImpl::Delete(const std::string& raw_path,
uint32_t delete_flags,
DeleteCallback callback) {
base::FilePath path;
- mojom::FileError error = ValidatePath(raw_path, directory_path_, &path);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = ValidatePath(raw_path, directory_path_, &path);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error);
return;
}
bool recursive = delete_flags & mojom::kDeleteFlagRecursive;
if (!base::DeleteFile(path, recursive)) {
- std::move(callback).Run(mojom::FileError::FAILED);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED);
return;
}
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
void DirectoryImpl::Exists(const std::string& raw_path,
ExistsCallback callback) {
base::FilePath path;
- mojom::FileError error = ValidatePath(raw_path, directory_path_, &path);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = ValidatePath(raw_path, directory_path_, &path);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error, false);
return;
}
bool exists = base::PathExists(path);
- std::move(callback).Run(mojom::FileError::OK, exists);
+ std::move(callback).Run(base::File::Error::FILE_OK, exists);
}
void DirectoryImpl::IsWritable(const std::string& raw_path,
IsWritableCallback callback) {
base::FilePath path;
- mojom::FileError error = ValidatePath(raw_path, directory_path_, &path);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = ValidatePath(raw_path, directory_path_, &path);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error, false);
return;
}
- std::move(callback).Run(mojom::FileError::OK, base::PathIsWritable(path));
+ std::move(callback).Run(base::File::Error::FILE_OK,
+ base::PathIsWritable(path));
}
void DirectoryImpl::Flush(FlushCallback callback) {
@@ -262,18 +265,18 @@
}
if (!file.Flush()) {
- std::move(callback).Run(mojom::FileError::FAILED);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED);
return;
}
#endif
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
void DirectoryImpl::StatFile(const std::string& raw_path,
StatFileCallback callback) {
base::FilePath path;
- mojom::FileError error = ValidatePath(raw_path, directory_path_, &path);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = ValidatePath(raw_path, directory_path_, &path);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error, nullptr);
return;
}
@@ -286,11 +289,12 @@
base::File::Info info;
if (!base_file.GetInfo(&info)) {
- std::move(callback).Run(mojom::FileError::FAILED, nullptr);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED, nullptr);
return;
}
- std::move(callback).Run(mojom::FileError::OK, MakeFileInformation(info));
+ std::move(callback).Run(base::File::Error::FILE_OK,
+ MakeFileInformation(info));
}
void DirectoryImpl::Clone(mojom::DirectoryRequest directory) {
@@ -304,14 +308,14 @@
void DirectoryImpl::ReadEntireFile(const std::string& raw_path,
ReadEntireFileCallback callback) {
base::FilePath path;
- mojom::FileError error = ValidatePath(raw_path, directory_path_, &path);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = ValidatePath(raw_path, directory_path_, &path);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error, std::vector<uint8_t>());
return;
}
if (base::DirectoryExists(path)) {
- std::move(callback).Run(mojom::FileError::NOT_A_FILE,
+ std::move(callback).Run(base::File::Error::FILE_ERROR_NOT_A_FILE,
std::vector<uint8_t>());
return;
}
@@ -329,21 +333,21 @@
while ((len = base_file.ReadAtCurrentPos(buf.get(), kBufferSize)) > 0)
contents.insert(contents.end(), buf.get(), buf.get() + len);
- std::move(callback).Run(mojom::FileError::OK, contents);
+ std::move(callback).Run(base::File::Error::FILE_OK, contents);
}
void DirectoryImpl::WriteFile(const std::string& raw_path,
const std::vector<uint8_t>& data,
WriteFileCallback callback) {
base::FilePath path;
- mojom::FileError error = ValidatePath(raw_path, directory_path_, &path);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = ValidatePath(raw_path, directory_path_, &path);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error);
return;
}
if (base::DirectoryExists(path)) {
- std::move(callback).Run(mojom::FileError::NOT_A_FILE);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_NOT_A_FILE);
return;
}
@@ -364,14 +368,14 @@
}
}
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
base::File DirectoryImpl::OpenFileHandleImpl(const std::string& raw_path,
uint32_t open_flags) {
base::FilePath path;
- mojom::FileError error = ValidatePath(raw_path, directory_path_, &path);
- if (error != mojom::FileError::OK)
+ base::File::Error error = ValidatePath(raw_path, directory_path_, &path);
+ if (error != base::File::Error::FILE_OK)
return base::File(static_cast<base::File::Error>(error));
if (base::DirectoryExists(path)) {
diff --git a/components/filesystem/directory_impl_unittest.cc b/components/filesystem/directory_impl_unittest.cc
index 38410a2..b129972 100644
--- a/components/filesystem/directory_impl_unittest.cc
+++ b/components/filesystem/directory_impl_unittest.cc
@@ -21,7 +21,7 @@
TEST_F(DirectoryImplTest, Read) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
// Make some files.
const struct {
@@ -32,25 +32,25 @@
{"my_file2", mojom::kFlagWrite | mojom::kFlagCreate},
{"my_file3", mojom::kFlagAppend | mojom::kFlagCreate}};
for (size_t i = 0; i < arraysize(files_to_create); i++) {
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenFile(files_to_create[i].name, nullptr,
files_to_create[i].open_flags, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
// Make a directory.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenDirectory(
"my_dir", nullptr,
mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
base::Optional<std::vector<mojom::DirectoryEntryPtr>> directory_contents;
handled = directory->Read(&error, &directory_contents);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_TRUE(directory_contents.has_value());
// Expected contents of the directory.
@@ -77,87 +77,87 @@
TEST_F(DirectoryImplTest, BasicRenameDelete) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
// Create my_file.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenFile(
"my_file", nullptr, mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Opening my_file should succeed.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = directory->OpenFile("my_file", nullptr,
mojom::kFlagRead | mojom::kFlagOpen, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Rename my_file to my_new_file.
handled = directory->Rename("my_file", "my_new_file", &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Opening my_file should fail.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = directory->OpenFile("my_file", nullptr,
mojom::kFlagRead | mojom::kFlagOpen, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::NOT_FOUND, error);
+ EXPECT_EQ(base::File::Error::FILE_ERROR_NOT_FOUND, error);
// Opening my_new_file should succeed.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = directory->OpenFile("my_new_file", nullptr,
mojom::kFlagRead | mojom::kFlagOpen, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Delete my_new_file (no flags).
handled = directory->Delete("my_new_file", 0, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Opening my_new_file should fail.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = directory->OpenFile("my_new_file", nullptr,
mojom::kFlagRead | mojom::kFlagOpen, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::NOT_FOUND, error);
+ EXPECT_EQ(base::File::Error::FILE_ERROR_NOT_FOUND, error);
}
TEST_F(DirectoryImplTest, CantOpenDirectoriesAsFiles) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
{
// Create a directory called 'my_file'
mojom::DirectoryPtr my_file_directory;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenDirectory(
"my_file", MakeRequest(&my_file_directory),
mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
{
// Attempt to open that directory as a file. This must fail!
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagRead | mojom::kFlagOpen, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::NOT_A_FILE, error);
+ EXPECT_EQ(base::File::Error::FILE_ERROR_NOT_A_FILE, error);
}
}
TEST_F(DirectoryImplTest, Clone) {
mojom::DirectoryPtr clone_one;
mojom::DirectoryPtr clone_two;
- mojom::FileError error;
+ base::File::Error error;
{
mojom::DirectoryPtr directory;
@@ -174,14 +174,14 @@
{
bool handled = clone_one->WriteFile("data", data, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
{
std::vector<uint8_t> file_contents;
bool handled = clone_two->ReadEntireFile("data", &error, &file_contents);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(data, file_contents);
}
@@ -190,20 +190,20 @@
TEST_F(DirectoryImplTest, WriteFileReadFile) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
std::vector<uint8_t> data(kData, kData + strlen(kData));
{
bool handled = directory->WriteFile("data", data, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
{
std::vector<uint8_t> file_contents;
bool handled = directory->ReadEntireFile("data", &error, &file_contents);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(data, file_contents);
}
@@ -212,31 +212,31 @@
TEST_F(DirectoryImplTest, ReadEmptyFileIsNotFoundError) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
{
std::vector<uint8_t> file_contents;
bool handled =
directory->ReadEntireFile("doesnt_exist", &error, &file_contents);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::NOT_FOUND, error);
+ EXPECT_EQ(base::File::Error::FILE_ERROR_NOT_FOUND, error);
}
}
TEST_F(DirectoryImplTest, CantReadEntireFileOnADirectory) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
// Create a directory
{
mojom::DirectoryPtr my_file_directory;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenDirectory(
"my_dir", MakeRequest(&my_file_directory),
mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
// Try to read it as a file
@@ -244,43 +244,43 @@
std::vector<uint8_t> file_contents;
bool handled = directory->ReadEntireFile("my_dir", &error, &file_contents);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::NOT_A_FILE, error);
+ EXPECT_EQ(base::File::Error::FILE_ERROR_NOT_A_FILE, error);
}
}
TEST_F(DirectoryImplTest, CantWriteFileOnADirectory) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
// Create a directory
{
mojom::DirectoryPtr my_file_directory;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenDirectory(
"my_dir", MakeRequest(&my_file_directory),
mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
{
std::vector<uint8_t> data(kData, kData + strlen(kData));
bool handled = directory->WriteFile("my_dir", data, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::NOT_A_FILE, error);
+ EXPECT_EQ(base::File::Error::FILE_ERROR_NOT_A_FILE, error);
}
}
TEST_F(DirectoryImplTest, Flush) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
{
bool handled = directory->Flush(&error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
}
diff --git a/components/filesystem/file_impl.cc b/components/filesystem/file_impl.cc
index 3fff0f3a..1e726f3 100644
--- a/components/filesystem/file_impl.cc
+++ b/components/filesystem/file_impl.cc
@@ -6,9 +6,11 @@
#include <stddef.h>
#include <stdint.h>
+
#include <limits>
#include <memory>
#include <utility>
+#include <vector>
#include "base/files/file_path.h"
#include "base/files/scoped_file.h"
@@ -80,7 +82,7 @@
lock_table_->RemoveFromLockTable(path_);
file_.Close();
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
// TODO(vtl): Move the implementation to a thread pool.
@@ -93,22 +95,24 @@
return;
}
if (num_bytes_to_read > kMaxReadSize) {
- std::move(callback).Run(mojom::FileError::INVALID_OPERATION, base::nullopt);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_INVALID_OPERATION,
+ base::nullopt);
return;
}
- mojom::FileError error = IsOffsetValid(offset);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = IsOffsetValid(offset);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error, base::nullopt);
return;
}
error = IsWhenceValid(whence);
- if (error != mojom::FileError::OK) {
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error, base::nullopt);
return;
}
if (file_.Seek(static_cast<base::File::Whence>(whence), offset) == -1) {
- std::move(callback).Run(mojom::FileError::FAILED, base::nullopt);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED,
+ base::nullopt);
return;
}
@@ -116,13 +120,14 @@
int num_bytes_read = file_.ReadAtCurrentPos(
reinterpret_cast<char*>(&bytes_read.front()), num_bytes_to_read);
if (num_bytes_read < 0) {
- std::move(callback).Run(mojom::FileError::FAILED, base::nullopt);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED,
+ base::nullopt);
return;
}
DCHECK_LE(static_cast<size_t>(num_bytes_read), num_bytes_to_read);
bytes_read.resize(static_cast<size_t>(num_bytes_read));
- std::move(callback).Run(mojom::FileError::OK, std::move(bytes_read));
+ std::move(callback).Run(base::File::Error::FILE_OK, std::move(bytes_read));
}
// TODO(vtl): Move the implementation to a thread pool.
@@ -142,22 +147,22 @@
#else
static_cast<size_t>(std::numeric_limits<ssize_t>::max())) {
#endif
- std::move(callback).Run(mojom::FileError::INVALID_OPERATION, 0);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_INVALID_OPERATION, 0);
return;
}
- mojom::FileError error = IsOffsetValid(offset);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = IsOffsetValid(offset);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error, 0);
return;
}
error = IsWhenceValid(whence);
- if (error != mojom::FileError::OK) {
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error, 0);
return;
}
if (file_.Seek(static_cast<base::File::Whence>(whence), offset) == -1) {
- std::move(callback).Run(mojom::FileError::FAILED, 0);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED, 0);
return;
}
@@ -167,13 +172,13 @@
int num_bytes_written = file_.WriteAtCurrentPos(
buf, static_cast<int>(bytes_to_write.size()));
if (num_bytes_written < 0) {
- std::move(callback).Run(mojom::FileError::FAILED, 0);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED, 0);
return;
}
DCHECK_LE(static_cast<size_t>(num_bytes_written),
std::numeric_limits<uint32_t>::max());
- std::move(callback).Run(mojom::FileError::OK,
+ std::move(callback).Run(base::File::Error::FILE_OK,
static_cast<uint32_t>(num_bytes_written));
}
@@ -188,13 +193,13 @@
std::move(callback).Run(GetError(file_), 0);
return;
}
- mojom::FileError error = IsOffsetValid(offset);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = IsOffsetValid(offset);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error, 0);
return;
}
error = IsWhenceValid(whence);
- if (error != mojom::FileError::OK) {
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error, 0);
return;
}
@@ -202,11 +207,12 @@
int64_t position =
file_.Seek(static_cast<base::File::Whence>(whence), offset);
if (position < 0) {
- std::move(callback).Run(mojom::FileError::FAILED, 0);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED, 0);
return;
}
- std::move(callback).Run(mojom::FileError::OK, static_cast<int64_t>(position));
+ std::move(callback).Run(base::File::Error::FILE_OK,
+ static_cast<int64_t>(position));
}
void FileImpl::Stat(StatCallback callback) {
@@ -217,11 +223,12 @@
base::File::Info info;
if (!file_.GetInfo(&info)) {
- std::move(callback).Run(mojom::FileError::FAILED, nullptr);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED, nullptr);
return;
}
- std::move(callback).Run(mojom::FileError::OK, MakeFileInformation(info));
+ std::move(callback).Run(base::File::Error::FILE_OK,
+ MakeFileInformation(info));
}
void FileImpl::Truncate(int64_t size, TruncateCallback callback) {
@@ -230,21 +237,21 @@
return;
}
if (size < 0) {
- std::move(callback).Run(mojom::FileError::INVALID_OPERATION);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_INVALID_OPERATION);
return;
}
- mojom::FileError error = IsOffsetValid(size);
- if (error != mojom::FileError::OK) {
+ base::File::Error error = IsOffsetValid(size);
+ if (error != base::File::Error::FILE_OK) {
std::move(callback).Run(error);
return;
}
if (!file_.SetLength(size)) {
- std::move(callback).Run(mojom::FileError::NOT_FOUND);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_NOT_FOUND);
return;
}
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
void FileImpl::Touch(mojom::TimespecOrNowPtr atime,
@@ -259,7 +266,7 @@
if (!atime) {
base::File::Info info;
if (!file_.GetInfo(&info)) {
- std::move(callback).Run(mojom::FileError::FAILED);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED);
return;
}
@@ -272,7 +279,7 @@
if (!mtime) {
base::File::Info info;
if (!file_.GetInfo(&info)) {
- std::move(callback).Run(mojom::FileError::FAILED);
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED);
return;
}
@@ -282,7 +289,7 @@
}
file_.SetTimes(base_atime, base_mtime);
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
void FileImpl::Dup(mojom::FileRequest file, DupCallback callback) {
@@ -303,7 +310,7 @@
lock_table_),
std::move(file));
}
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
void FileImpl::Flush(FlushCallback callback) {
@@ -313,18 +320,18 @@
}
bool ret = file_.Flush();
- std::move(callback).Run(ret ? mojom::FileError::OK
- : mojom::FileError::FAILED);
+ std::move(callback).Run(ret ? base::File::Error::FILE_OK
+ : base::File::Error::FILE_ERROR_FAILED);
}
void FileImpl::Lock(LockCallback callback) {
std::move(callback).Run(
- static_cast<filesystem::mojom::FileError>(lock_table_->LockFile(this)));
+ static_cast<base::File::Error>(lock_table_->LockFile(this)));
}
void FileImpl::Unlock(UnlockCallback callback) {
std::move(callback).Run(
- static_cast<filesystem::mojom::FileError>(lock_table_->UnlockFile(this)));
+ static_cast<base::File::Error>(lock_table_->UnlockFile(this)));
}
void FileImpl::AsHandle(AsHandleCallback callback) {
@@ -341,7 +348,7 @@
base::File::Info info;
if (!new_file.GetInfo(&info)) {
- std::move(callback).Run(mojom::FileError::FAILED, base::File());
+ std::move(callback).Run(base::File::Error::FILE_ERROR_FAILED, base::File());
return;
}
@@ -350,11 +357,12 @@
// passing a file descriptor to a directory is a sandbox escape on Windows,
// we should be absolutely paranoid.
if (info.is_directory) {
- std::move(callback).Run(mojom::FileError::NOT_A_FILE, base::File());
+ std::move(callback).Run(base::File::Error::FILE_ERROR_NOT_A_FILE,
+ base::File());
return;
}
- std::move(callback).Run(mojom::FileError::OK, std::move(new_file));
+ std::move(callback).Run(base::File::Error::FILE_OK, std::move(new_file));
}
} // namespace filesystem
diff --git a/components/filesystem/file_impl_unittest.cc b/components/filesystem/file_impl_unittest.cc
index 492c243..32410be 100644
--- a/components/filesystem/file_impl_unittest.cc
+++ b/components/filesystem/file_impl_unittest.cc
@@ -20,18 +20,18 @@
TEST_F(FileImplTest, CreateWriteCloseRenameOpenRead) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
bool handled = false;
{
// Create my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Write to it.
std::vector<uint8_t> bytes_to_write;
@@ -40,43 +40,43 @@
bytes_to_write.push_back(static_cast<uint8_t>('l'));
bytes_to_write.push_back(static_cast<uint8_t>('l'));
bytes_to_write.push_back(static_cast<uint8_t>('o'));
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
uint32_t num_bytes_written = 0;
handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT,
&error, &num_bytes_written);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(bytes_to_write.size(), num_bytes_written);
// Close it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Close((&error));
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
// Rename it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = directory->Rename("my_file", "your_file", &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
{
// Open my_file again.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("your_file", MakeRequest(&file),
mojom::kFlagRead | mojom::kFlagOpen, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Read from it.
base::Optional<std::vector<uint8_t>> bytes_read;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Read(3, 1, mojom::Whence::FROM_BEGIN, &error, &bytes_read);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_TRUE(bytes_read.has_value());
ASSERT_EQ(3u, bytes_read.value().size());
EXPECT_EQ(static_cast<uint8_t>('e'), bytes_read.value()[0]);
@@ -90,7 +90,7 @@
TEST_F(FileImplTest, CantWriteInReadMode) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
std::vector<uint8_t> bytes_to_write;
bytes_to_write.push_back(static_cast<uint8_t>('h'));
@@ -102,71 +102,71 @@
{
// Create my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Write to it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
uint32_t num_bytes_written = 0;
handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT,
&error, &num_bytes_written);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(bytes_to_write.size(), num_bytes_written);
// Close it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Close((&error));
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
{
// Open my_file again, this time with read only mode.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagRead | mojom::kFlagOpen, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Try to write in read mode; it should fail.
- error = mojom::FileError::OK;
+ error = base::File::Error::FILE_OK;
uint32_t num_bytes_written = 0;
handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT,
&error, &num_bytes_written);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::FAILED, error);
+ EXPECT_EQ(base::File::Error::FILE_ERROR_FAILED, error);
EXPECT_EQ(0u, num_bytes_written);
// Close it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Close((&error));
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
}
TEST_F(FileImplTest, OpenInAppendMode) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
{
// Create my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Write to it.
std::vector<uint8_t> bytes_to_write;
@@ -175,30 +175,30 @@
bytes_to_write.push_back(static_cast<uint8_t>('l'));
bytes_to_write.push_back(static_cast<uint8_t>('l'));
bytes_to_write.push_back(static_cast<uint8_t>('o'));
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
uint32_t num_bytes_written = 0;
handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT,
&error, &num_bytes_written);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(bytes_to_write.size(), num_bytes_written);
// Close it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Close(&error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
{
// Append to my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagAppend | mojom::kFlagOpen, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Write to it.
std::vector<uint8_t> bytes_to_write;
@@ -209,37 +209,37 @@
bytes_to_write.push_back(static_cast<uint8_t>('b'));
bytes_to_write.push_back(static_cast<uint8_t>('y'));
bytes_to_write.push_back(static_cast<uint8_t>('e'));
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
uint32_t num_bytes_written = 0;
handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT,
&error, &num_bytes_written);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(bytes_to_write.size(), num_bytes_written);
// Close it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Close((&error));
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
{
// Open my_file again.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagRead | mojom::kFlagOpen, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Read from it.
base::Optional<std::vector<uint8_t>> bytes_read;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Read(12, 0, mojom::Whence::FROM_BEGIN, &error, &bytes_read);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_TRUE(bytes_read.has_value());
ASSERT_EQ(12u, bytes_read.value().size());
EXPECT_EQ(static_cast<uint8_t>('l'), bytes_read.value()[3]);
@@ -252,17 +252,17 @@
TEST_F(FileImplTest, OpenInTruncateMode) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
{
// Create my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Write to it.
std::vector<uint8_t> bytes_to_write;
@@ -271,30 +271,30 @@
bytes_to_write.push_back(static_cast<uint8_t>('l'));
bytes_to_write.push_back(static_cast<uint8_t>('l'));
bytes_to_write.push_back(static_cast<uint8_t>('o'));
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
uint32_t num_bytes_written = 0;
handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT,
&error, &num_bytes_written);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(bytes_to_write.size(), num_bytes_written);
// Close it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Close(&error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
{
// Append to my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenFile(
"my_file", MakeRequest(&file),
mojom::kFlagWrite | mojom::kFlagOpenTruncated, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Write to it.
std::vector<uint8_t> bytes_to_write;
@@ -305,37 +305,37 @@
bytes_to_write.push_back(static_cast<uint8_t>('b'));
bytes_to_write.push_back(static_cast<uint8_t>('y'));
bytes_to_write.push_back(static_cast<uint8_t>('e'));
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
uint32_t num_bytes_written = 0;
handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT,
&error, &num_bytes_written);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(bytes_to_write.size(), num_bytes_written);
// Close it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Close(&error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
{
// Open my_file again.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagRead | mojom::kFlagOpen, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Read from it.
base::Optional<std::vector<uint8_t>> bytes_read;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Read(7, 0, mojom::Whence::FROM_BEGIN, &error, &bytes_read);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_TRUE(bytes_read.has_value());
ASSERT_EQ(7u, bytes_read.value().size());
EXPECT_EQ(static_cast<uint8_t>('g'), bytes_read.value()[0]);
@@ -350,23 +350,23 @@
TEST_F(FileImplTest, StatTouch) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
// Create my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Stat it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
mojom::FileInformationPtr file_info;
handled = file->Stat(&error, &file_info);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_FALSE(file_info.is_null());
EXPECT_EQ(mojom::FsFileType::REGULAR_FILE, file_info->type);
EXPECT_EQ(0, file_info->size);
@@ -375,21 +375,21 @@
double first_mtime = file_info->mtime;
// Touch only the atime.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
mojom::TimespecOrNowPtr t(mojom::TimespecOrNow::New());
t->now = false;
const int64_t kPartyTime1 = 1234567890; // Party like it's 2009-02-13.
t->seconds = kPartyTime1;
handled = file->Touch(std::move(t), nullptr, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Stat again.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
file_info.reset();
handled = file->Stat(&error, &file_info);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_FALSE(file_info.is_null());
EXPECT_EQ(kPartyTime1, file_info->atime);
EXPECT_EQ(first_mtime, file_info->mtime);
@@ -401,14 +401,14 @@
t->seconds = kPartyTime2;
handled = file->Touch(nullptr, std::move(t), &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Stat again.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
file_info.reset();
handled = file->Stat(&error, &file_info);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_FALSE(file_info.is_null());
EXPECT_EQ(kPartyTime1, file_info->atime);
EXPECT_EQ(kPartyTime2, file_info->mtime);
@@ -421,83 +421,83 @@
TEST_F(FileImplTest, TellSeek) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
// Create my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Write to it.
std::vector<uint8_t> bytes_to_write(1000, '!');
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
uint32_t num_bytes_written = 0;
handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, &error,
&num_bytes_written);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(bytes_to_write.size(), num_bytes_written);
const int size = static_cast<int>(num_bytes_written);
// Tell.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
int64_t position = -1;
handled = file->Tell(&error, &position);
ASSERT_TRUE(handled);
// Should be at the end.
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(size, position);
// Seek back 100.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
position = -1;
handled = file->Seek(-100, mojom::Whence::FROM_CURRENT, &error, &position);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(size - 100, position);
// Tell.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
position = -1;
handled = file->Tell(&error, &position);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(size - 100, position);
// Seek to 123 from start.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
position = -1;
handled = file->Seek(123, mojom::Whence::FROM_BEGIN, &error, &position);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(123, position);
// Tell.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
position = -1;
handled = file->Tell(&error, &position);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(123, position);
// Seek to 123 back from end.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
position = -1;
handled = file->Seek(-123, mojom::Whence::FROM_END, &error, &position);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(size - 123, position);
// Tell.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
position = -1;
handled = file->Tell(&error, &position);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(size - 123, position);
// TODO(vtl): Check that seeking actually affects reading/writing.
@@ -507,16 +507,16 @@
TEST_F(FileImplTest, Dup) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
// Create my_file.
mojom::FilePtr file1;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenFile(
"my_file", MakeRequest(&file1),
mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Write to it.
std::vector<uint8_t> bytes_to_write;
@@ -525,28 +525,28 @@
bytes_to_write.push_back(static_cast<uint8_t>('l'));
bytes_to_write.push_back(static_cast<uint8_t>('l'));
bytes_to_write.push_back(static_cast<uint8_t>('o'));
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
uint32_t num_bytes_written = 0;
handled = file1->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, &error,
&num_bytes_written);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(bytes_to_write.size(), num_bytes_written);
const int end_hello_pos = static_cast<int>(num_bytes_written);
// Dup it.
mojom::FilePtr file2;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file1->Dup(MakeRequest(&file2), &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// |file2| should have the same position.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
int64_t position = -1;
handled = file2->Tell(&error, &position);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(end_hello_pos, position);
// Write using |file2|.
@@ -556,36 +556,36 @@
more_bytes_to_write.push_back(static_cast<uint8_t>('r'));
more_bytes_to_write.push_back(static_cast<uint8_t>('l'));
more_bytes_to_write.push_back(static_cast<uint8_t>('d'));
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
num_bytes_written = 0;
handled = file2->Write(more_bytes_to_write, 0, mojom::Whence::FROM_CURRENT,
&error, &num_bytes_written);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(more_bytes_to_write.size(), num_bytes_written);
const int end_world_pos = end_hello_pos + static_cast<int>(num_bytes_written);
// |file1| should have the same position.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
position = -1;
handled = file1->Tell(&error, &position);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(end_world_pos, position);
// Close |file1|.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file1->Close(&error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Read everything using |file2|.
base::Optional<std::vector<uint8_t>> bytes_read;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled =
file2->Read(1000, 0, mojom::Whence::FROM_BEGIN, &error, &bytes_read);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_TRUE(bytes_read.has_value());
ASSERT_EQ(static_cast<size_t>(end_world_pos), bytes_read.value().size());
// Just check the first and last bytes.
@@ -601,48 +601,48 @@
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
// Create my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file),
mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Write to it.
std::vector<uint8_t> bytes_to_write(kInitialSize, '!');
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
uint32_t num_bytes_written = 0;
handled = file->Write(bytes_to_write, 0, mojom::Whence::FROM_CURRENT, &error,
&num_bytes_written);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
EXPECT_EQ(kInitialSize, num_bytes_written);
// Stat it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
mojom::FileInformationPtr file_info;
handled = file->Stat(&error, &file_info);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_FALSE(file_info.is_null());
EXPECT_EQ(kInitialSize, file_info->size);
// Truncate it.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Truncate(kTruncatedSize, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Stat again.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
file_info.reset();
handled = file->Stat(&error, &file_info);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_FALSE(file_info.is_null());
EXPECT_EQ(kTruncatedSize, file_info->size);
}
@@ -650,24 +650,24 @@
TEST_F(FileImplTest, AsHandle) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
{
// Create my_file.
mojom::FilePtr file1;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenFile(
"my_file", MakeRequest(&file1),
mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Fetch the file.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
base::File raw_file;
handled = file1->AsHandle(&error, &raw_file);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_TRUE(raw_file.IsValid());
EXPECT_EQ(5, raw_file.WriteAtCurrentPos("hello", 5));
@@ -676,19 +676,19 @@
{
// Reopen my_file.
mojom::FilePtr file2;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled =
directory->OpenFile("my_file", MakeRequest(&file2),
mojom::kFlagRead | mojom::kFlagOpen, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Verify that we wrote data raw on the file descriptor.
base::Optional<std::vector<uint8_t>> bytes_read;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file2->Read(5, 0, mojom::Whence::FROM_BEGIN, &error, &bytes_read);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
ASSERT_TRUE(bytes_read.has_value());
ASSERT_EQ(5u, bytes_read.value().size());
EXPECT_EQ(static_cast<uint8_t>('h'), bytes_read.value()[0]);
@@ -702,94 +702,94 @@
TEST_F(FileImplTest, SimpleLockUnlock) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
// Create my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenFile(
"my_file", MakeRequest(&file),
mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Lock the file.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Lock(&error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Unlock the file.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Unlock(&error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
TEST_F(FileImplTest, CantDoubleLock) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
// Create my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenFile(
"my_file", MakeRequest(&file),
mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Lock the file.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Lock(&error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Lock the file again.
- error = mojom::FileError::OK;
+ error = base::File::Error::FILE_OK;
handled = file->Lock(&error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::FAILED, error);
+ EXPECT_EQ(base::File::Error::FILE_ERROR_FAILED, error);
}
TEST_F(FileImplTest, ClosingFileClearsLock) {
mojom::DirectoryPtr directory;
GetTemporaryRoot(&directory);
- mojom::FileError error;
+ base::File::Error error;
{
// Create my_file.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenFile(
"my_file", MakeRequest(&file),
mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagOpenAlways, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// Lock the file.
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Lock(&error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
{
// Open the file again.
mojom::FilePtr file;
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
bool handled = directory->OpenFile(
"my_file", MakeRequest(&file),
mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagOpenAlways, &error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
// The file shouldn't be locked (and we check by trying to lock it).
- error = mojom::FileError::FAILED;
+ error = base::File::Error::FILE_ERROR_FAILED;
handled = file->Lock(&error);
ASSERT_TRUE(handled);
- EXPECT_EQ(mojom::FileError::OK, error);
+ EXPECT_EQ(base::File::Error::FILE_OK, error);
}
}
diff --git a/components/filesystem/file_system_impl.cc b/components/filesystem/file_system_impl.cc
index 508b4bc..34aa7388 100644
--- a/components/filesystem/file_system_impl.cc
+++ b/components/filesystem/file_system_impl.cc
@@ -46,7 +46,7 @@
mojo::MakeStrongBinding(std::make_unique<DirectoryImpl>(
path, std::move(shared_temp_dir), lock_table_),
std::move(directory));
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
void FileSystemImpl::OpenPersistentFileSystem(
@@ -63,7 +63,7 @@
mojo::MakeStrongBinding(std::make_unique<DirectoryImpl>(
path, std::move(shared_temp_dir), lock_table_),
std::move(directory));
- std::move(callback).Run(mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
} // namespace filesystem
diff --git a/components/filesystem/files_test_base.cc b/components/filesystem/files_test_base.cc
index facb600b..5e3b356 100644
--- a/components/filesystem/files_test_base.cc
+++ b/components/filesystem/files_test_base.cc
@@ -25,10 +25,10 @@
}
void FilesTestBase::GetTemporaryRoot(mojom::DirectoryPtr* directory) {
- mojom::FileError error = mojom::FileError::FAILED;
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
bool handled = files()->OpenTempDirectory(MakeRequest(directory), &error);
ASSERT_TRUE(handled);
- ASSERT_EQ(mojom::FileError::OK, error);
+ ASSERT_EQ(base::File::Error::FILE_OK, error);
}
} // namespace filesystem
diff --git a/components/filesystem/public/interfaces/BUILD.gn b/components/filesystem/public/interfaces/BUILD.gn
index b65d3a7..2e5cc65b 100644
--- a/components/filesystem/public/interfaces/BUILD.gn
+++ b/components/filesystem/public/interfaces/BUILD.gn
@@ -13,5 +13,6 @@
]
public_deps = [
"//mojo/common:common_custom_types",
+ "//mojo/public/mojom/base",
]
}
diff --git a/components/filesystem/public/interfaces/directory.mojom b/components/filesystem/public/interfaces/directory.mojom
index 1cd6b01..4874ee2c 100644
--- a/components/filesystem/public/interfaces/directory.mojom
+++ b/components/filesystem/public/interfaces/directory.mojom
@@ -7,6 +7,7 @@
import "components/filesystem/public/interfaces/file.mojom";
import "components/filesystem/public/interfaces/types.mojom";
import "mojo/common/file.mojom";
+import "mojo/public/mojom/base/file_error.mojom";
struct FileOpenDetails {
string path;
@@ -15,7 +16,7 @@
struct FileOpenResult {
string path;
- FileError error;
+ mojo_base.mojom.FileError error;
mojo.common.mojom.File? file_handle;
};
@@ -32,7 +33,8 @@
// Reads the contents of this directory.
// TODO(vtl): Clarify error codes versus |directory_contents|.
[Sync]
- Read() => (FileError error, array<DirectoryEntry>? directory_contents);
+ Read() => (mojo_base.mojom.FileError error,
+ array<DirectoryEntry>? directory_contents);
// Operations *in* "this" |Directory|:
@@ -41,13 +43,14 @@
// together with |kOpenFlagCreate|, for "touching" a file).
[Sync]
OpenFile(string path, File&? file, uint32 open_flags)
- => (FileError error);
+ => (mojo_base.mojom.FileError error);
// Opens the file specified by |path| with the given |open_flags|. Returns a
// native file descriptor wrapped in a MojoHandle.
[Sync]
OpenFileHandle(string path, uint32 open_flags)
- => (FileError error, mojo.common.mojom.File? file_handle);
+ => (mojo_base.mojom.FileError error,
+ mojo.common.mojom.File? file_handle);
// Like OpenFileHandle, but opens multiple files.
[Sync]
@@ -59,52 +62,57 @@
[Sync]
OpenDirectory(string path,
Directory&? directory,
- uint32 open_flags) => (FileError error);
+ uint32 open_flags) => (mojo_base.mojom.FileError error);
// Renames/moves the file/directory given by |path| to |new_path|.
[Sync]
- Rename(string path, string new_path) => (FileError error);
+ Rename(string path, string new_path) => (mojo_base.mojom.FileError error);
// Renames file |path| to |new_path|. Both paths must be on the same volume,
// or the function will fail. Destination file will be created if it doesn't
// exist. Prefer this function over Rename when dealing with temporary files.
// On Windows it preserves attributes of the target file.
[Sync]
- Replace(string path, string new_path) => (FileError error);
+ Replace(string path, string new_path) => (mojo_base.mojom.FileError error);
// Deletes the given path, which may be a file or a directory (see
// |kDeleteFlag...| for details).
[Sync]
- Delete(string path, uint32 delete_flags) => (FileError error);
+ Delete(string path, uint32 delete_flags)
+ => (mojo_base.mojom.FileError error);
// Returns true if |path| exists.
[Sync]
- Exists(string path) => (FileError error, bool exists);
+ Exists(string path) => (mojo_base.mojom.FileError error, bool exists);
// Returns true if |path| is writable.
[Sync]
- IsWritable(string path) => (FileError error, bool is_writable);
+ IsWritable(string path)
+ => (mojo_base.mojom.FileError error, bool is_writable);
// Opens a file descriptor on this directory and calls
// fsync()/FlushFileBuffers().
[Sync]
- Flush() => (FileError error);
+ Flush() => (mojo_base.mojom.FileError error);
// Gets information about this file. On success, |file_information| is
// non-null and will contain this information.
[Sync]
- StatFile(string path) => (FileError error, FileInformation? file_information);
+ StatFile(string path)
+ => (mojo_base.mojom.FileError error, FileInformation? file_information);
// Creates a copy of this directory.
Clone(Directory& directory);
// Reads the contents of an entire file.
[Sync]
- ReadEntireFile(string path) => (FileError error, array<uint8> data);
+ ReadEntireFile(string path)
+ => (mojo_base.mojom.FileError error, array<uint8> data);
// Writes |data| to |path|, overwriting the file if it already exists.
[Sync]
- WriteFile(string path, array<uint8> data) => (FileError error);
+ WriteFile(string path, array<uint8> data)
+ => (mojo_base.mojom.FileError error);
// TODO(vtl): directory "streaming"?
// TODO(vtl): "make root" (i.e., prevent cd-ing, etc., to parent); note that
diff --git a/components/filesystem/public/interfaces/file.mojom b/components/filesystem/public/interfaces/file.mojom
index 9a4a515..7af8a7cf 100644
--- a/components/filesystem/public/interfaces/file.mojom
+++ b/components/filesystem/public/interfaces/file.mojom
@@ -11,6 +11,7 @@
import "components/filesystem/public/interfaces/types.mojom";
import "mojo/common/file.mojom";
+import "mojo/public/mojom/base/file_error.mojom";
// TODO(vtl): Write comments.
interface File {
@@ -18,7 +19,7 @@
// this. Note that any error code is strictly informational -- the close may
// not be retried.
[Sync]
- Close() => (FileError err);
+ Close() => (mojo_base.mojom.FileError err);
// Reads (at most) |num_bytes_to_read| from the location specified by
// |offset|/|whence|. On success, |bytes_read| is set to the data read.
@@ -28,62 +29,66 @@
// modifies the file position. Or maybe there should be a flag?
[Sync]
Read(uint32 num_bytes_to_read, int64 offset, Whence whence)
- => (FileError error, array<uint8>? bytes_read);
+ => (mojo_base.mojom.FileError error, array<uint8>? bytes_read);
// Writes |bytes_to_write| to the location specified by |offset|/|whence|.
// TODO(vtl): Clarify behavior when |num_bytes_written| is less than the size
// of |bytes_to_write|.
[Sync]
Write(array<uint8> bytes_to_write, int64 offset, Whence whence)
- => (FileError error, uint32 num_bytes_written);
+ => (mojo_base.mojom.FileError error, uint32 num_bytes_written);
// Gets the current file position. On success, |position| is the current
// offset (in bytes) from the beginning of the file).
[Sync]
- Tell() => (FileError error, int64 position);
+ Tell() => (mojo_base.mojom.FileError error, int64 position);
// Sets the current file position to that specified by |offset|/|whence|. On
// success, |position| is the offset (in bytes) from the beginning of the
// file.
[Sync]
- Seek(int64 offset, Whence whence) => (FileError error, int64 position);
+ Seek(int64 offset, Whence whence)
+ => (mojo_base.mojom.FileError error, int64 position);
// Gets information about this file. On success, |file_information| is
// non-null and will contain this information.
[Sync]
- Stat() => (FileError error, FileInformation? file_information);
+ Stat()
+ => (mojo_base.mojom.FileError error, FileInformation? file_information);
// Truncates this file to the size specified by |size| (in bytes).
[Sync]
- Truncate(int64 size) => (FileError error);
+ Truncate(int64 size) => (mojo_base.mojom.FileError error);
// Updates this file's atime and/or mtime to the time specified by |atime| (or
// |mtime|, respectively), which may also indicate "now". If |atime| or
// |mtime| is null, then the corresponding time is not modified.
[Sync]
- Touch(TimespecOrNow? atime, TimespecOrNow? mtime) => (FileError error);
+ Touch(TimespecOrNow? atime, TimespecOrNow? mtime)
+ => (mojo_base.mojom.FileError error);
// Creates a new |File| instance, which shares the same "file description".
// I.e., the access mode, etc. (as specified to |Directory::OpenFile()| by the
// |open_flags| argument) as well as file position.
[Sync]
- Dup(File& file) => (FileError error);
+ Dup(File& file) => (mojo_base.mojom.FileError error);
// Syncs data to disk.
[Sync]
- Flush() => (FileError error);
+ Flush() => (mojo_base.mojom.FileError error);
// Attempts to take an exclusive write lock on the file. This both takes a
// native OS file lock (so that non-chrome, non-mojo processes can't write to
// this file).
[Sync]
- Lock() => (FileError error);
+ Lock() => (mojo_base.mojom.FileError error);
// Unlocks a previously locked file.
[Sync]
- Unlock() => (FileError error);
+ Unlock() => (mojo_base.mojom.FileError error);
// Returns a handle to the file for raw access.
[Sync]
- AsHandle() => (FileError error, mojo.common.mojom.File? file_handle);
+ AsHandle() => (mojo_base.mojom.FileError error,
+ mojo.common.mojom.File? file_handle);
};
diff --git a/components/filesystem/public/interfaces/file_system.mojom b/components/filesystem/public/interfaces/file_system.mojom
index a2ab7961..94a023f5 100644
--- a/components/filesystem/public/interfaces/file_system.mojom
+++ b/components/filesystem/public/interfaces/file_system.mojom
@@ -5,15 +5,17 @@
module filesystem.mojom;
import "components/filesystem/public/interfaces/directory.mojom";
-import "components/filesystem/public/interfaces/types.mojom";
+import "mojo/public/mojom/base/file_error.mojom";
interface FileSystem {
// Opens a temporary filesystem. Will return a different directory each time
// it is called.
[Sync]
- OpenTempDirectory(Directory& directory) => (FileError error);
+ OpenTempDirectory(Directory& directory)
+ => (mojo_base.mojom.FileError error);
// Returns a directory which will persist to disk.
[Sync]
- OpenPersistentFileSystem(Directory& directory) => (FileError error);
+ OpenPersistentFileSystem(Directory& directory)
+ => (mojo_base.mojom.FileError error);
};
diff --git a/components/filesystem/public/interfaces/types.mojom b/components/filesystem/public/interfaces/types.mojom
index 7c8fff8..0fa96d6 100644
--- a/components/filesystem/public/interfaces/types.mojom
+++ b/components/filesystem/public/interfaces/types.mojom
@@ -4,28 +4,6 @@
module filesystem.mojom;
-// Error codes used by the file system. These error codes line up exactly with
-// those of base::File.
-enum FileError {
- OK = 0,
- FAILED = -1,
- IN_USE = -2,
- EXISTS = -3,
- NOT_FOUND = -4,
- ACCESS_DENIED = -5,
- TOO_MANY_OPENED = -6,
- NO_MEMORY = -7,
- NO_SPACE = -8,
- NOT_A_DIRECTORY = -9,
- INVALID_OPERATION = -10,
- SECURITY = -11,
- ABORT = -12,
- NOT_A_FILE = -13,
- NOT_EMPTY = -14,
- INVALID_URL = -15,
- IO = -16,
-};
-
// Used to explain the meaning of an offset within a file. These values line up
// exactly with base::File.
enum Whence {
diff --git a/components/filesystem/util.cc b/components/filesystem/util.cc
index ecd3fc6..659b9bb6 100644
--- a/components/filesystem/util.cc
+++ b/components/filesystem/util.cc
@@ -10,6 +10,7 @@
#include <time.h>
#include <limits>
+#include <string>
#include "base/logging.h"
#include "base/strings/string_util.h"
@@ -46,60 +47,6 @@
static_cast<uint32_t>(base::File::FLAG_APPEND),
"");
-// filesystem.Error in types.mojom must be the same as base::File::Error.
-static_assert(static_cast<int>(filesystem::mojom::FileError::OK) ==
- static_cast<int>(base::File::FILE_OK),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::FAILED) ==
- static_cast<int>(base::File::FILE_ERROR_FAILED),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::IN_USE) ==
- static_cast<int>(base::File::FILE_ERROR_IN_USE),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::EXISTS) ==
- static_cast<int>(base::File::FILE_ERROR_EXISTS),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::NOT_FOUND) ==
- static_cast<int>(base::File::FILE_ERROR_NOT_FOUND),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::ACCESS_DENIED) ==
- static_cast<int>(base::File::FILE_ERROR_ACCESS_DENIED),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::TOO_MANY_OPENED) ==
- static_cast<int>(base::File::FILE_ERROR_TOO_MANY_OPENED),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::NO_MEMORY) ==
- static_cast<int>(base::File::FILE_ERROR_NO_MEMORY),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::NO_SPACE) ==
- static_cast<int>(base::File::FILE_ERROR_NO_SPACE),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::NOT_A_DIRECTORY) ==
- static_cast<int>(base::File::FILE_ERROR_NOT_A_DIRECTORY),
- "");
-static_assert(
- static_cast<int>(filesystem::mojom::FileError::INVALID_OPERATION) ==
- static_cast<int>(base::File::FILE_ERROR_INVALID_OPERATION),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::SECURITY) ==
- static_cast<int>(base::File::FILE_ERROR_SECURITY),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::ABORT) ==
- static_cast<int>(base::File::FILE_ERROR_ABORT),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::NOT_A_FILE) ==
- static_cast<int>(base::File::FILE_ERROR_NOT_A_FILE),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::NOT_EMPTY) ==
- static_cast<int>(base::File::FILE_ERROR_NOT_EMPTY),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::INVALID_URL) ==
- static_cast<int>(base::File::FILE_ERROR_INVALID_URL),
- "");
-static_assert(static_cast<int>(filesystem::mojom::FileError::IO) ==
- static_cast<int>(base::File::FILE_ERROR_IO),
- "");
-
// filesystem.Whence in types.mojom must be the same as base::File::Whence.
static_assert(static_cast<int>(filesystem::mojom::Whence::FROM_BEGIN) ==
static_cast<int>(base::File::FROM_BEGIN),
@@ -113,23 +60,23 @@
namespace filesystem {
-mojom::FileError IsWhenceValid(mojom::Whence whence) {
+base::File::Error IsWhenceValid(mojom::Whence whence) {
return (whence == mojom::Whence::FROM_CURRENT ||
whence == mojom::Whence::FROM_BEGIN ||
whence == mojom::Whence::FROM_END)
- ? mojom::FileError::OK
- : mojom::FileError::INVALID_OPERATION;
+ ? base::File::Error::FILE_OK
+ : base::File::Error::FILE_ERROR_INVALID_OPERATION;
}
-mojom::FileError IsOffsetValid(int64_t offset) {
+base::File::Error IsOffsetValid(int64_t offset) {
return (offset >= std::numeric_limits<off_t>::min() &&
offset <= std::numeric_limits<off_t>::max())
- ? mojom::FileError::OK
- : mojom::FileError::INVALID_OPERATION;
+ ? base::File::Error::FILE_OK
+ : base::File::Error::FILE_ERROR_INVALID_OPERATION;
}
-mojom::FileError GetError(const base::File& file) {
- return static_cast<filesystem::mojom::FileError>(file.error_details());
+base::File::Error GetError(const base::File& file) {
+ return file.error_details();
}
mojom::FileInformationPtr MakeFileInformation(const base::File::Info& info) {
@@ -145,11 +92,11 @@
return file_info;
}
-mojom::FileError ValidatePath(const std::string& raw_path,
- const base::FilePath& filesystem_base,
- base::FilePath* out) {
+base::File::Error ValidatePath(const std::string& raw_path,
+ const base::FilePath& filesystem_base,
+ base::FilePath* out) {
if (!base::IsStringUTF8(raw_path))
- return mojom::FileError::INVALID_OPERATION;
+ return base::File::Error::FILE_ERROR_INVALID_OPERATION;
#if defined(OS_POSIX)
base::FilePath::StringType path = raw_path;
@@ -164,11 +111,11 @@
base::FilePath full_path = filesystem_base.Append(path);
if (full_path.ReferencesParent()) {
// TODO(erg): For now, if it references a parent, we'll consider this bad.
- return mojom::FileError::ACCESS_DENIED;
+ return base::File::Error::FILE_ERROR_ACCESS_DENIED;
}
*out = full_path;
- return mojom::FileError::OK;
+ return base::File::Error::FILE_OK;
}
} // namespace filesystem
diff --git a/components/filesystem/util.h b/components/filesystem/util.h
index 70fe7e7..8d90847 100644
--- a/components/filesystem/util.h
+++ b/components/filesystem/util.h
@@ -7,6 +7,8 @@
#include <stdint.h>
+#include <string>
+
#include "base/files/file.h"
#include "components/filesystem/public/interfaces/types.mojom.h"
@@ -19,30 +21,30 @@
// Checks if |path| is (looks like) a valid (relative) path. (On failure,
// returns |ERROR_INVALID_ARGUMENT| if |path| is not UTF-8, or
// |ERROR_PERMISSION_DENIED| if it is not relative.)
-mojom::FileError IsPathValid(const std::string& path);
+base::File::Error IsPathValid(const std::string& path);
// Checks if |whence| is a valid (known) |Whence| value. (On failure, returns
// |ERROR_UNIMPLEMENTED|.)
-mojom::FileError IsWhenceValid(mojom::Whence whence);
+base::File::Error IsWhenceValid(mojom::Whence whence);
// Checks if |offset| is a valid file offset (from some point); this is
// implementation-dependent (typically checking if |offset| fits in an |off_t|).
// (On failure, returns |ERROR_OUT_OF_RANGE|.)
-mojom::FileError IsOffsetValid(int64_t offset);
+base::File::Error IsOffsetValid(int64_t offset);
// Conversion functions:
// Returns the platform dependent error details converted to the
// filesystem.Error enum.
-mojom::FileError GetError(const base::File& file);
+base::File::Error GetError(const base::File& file);
// Serializes Info to the wire format.
mojom::FileInformationPtr MakeFileInformation(const base::File::Info& info);
// Creates an absolute file path and ensures that we don't try to traverse up.
-mojom::FileError ValidatePath(const std::string& raw_path,
- const base::FilePath& filesystem_base,
- base::FilePath* out);
+base::File::Error ValidatePath(const std::string& raw_path,
+ const base::FilePath& filesystem_base,
+ base::FilePath* out);
} // namespace filesystem
diff --git a/components/leveldb/env_mojo.cc b/components/leveldb/env_mojo.cc
index d98c94c..e46931f 100644
--- a/components/leveldb/env_mojo.cc
+++ b/components/leveldb/env_mojo.cc
@@ -5,6 +5,9 @@
#include "components/leveldb/env_mojo.h"
#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
@@ -14,7 +17,6 @@
#include "third_party/leveldatabase/chromium_logger.h"
#include "third_party/leveldatabase/src/include/leveldb/status.h"
-using filesystem::mojom::FileError;
using leveldb_env::UMALogger;
namespace leveldb {
@@ -23,21 +25,20 @@
const base::FilePath::CharType table_extension[] = FILE_PATH_LITERAL(".ldb");
-Status FilesystemErrorToStatus(FileError error,
+Status FilesystemErrorToStatus(base::File::Error error,
const std::string& filename,
leveldb_env::MethodID method) {
- if (error == FileError::OK)
+ if (error == base::File::Error::FILE_OK)
return Status::OK();
- std::string err_str =
- base::File::ErrorToString(base::File::Error(static_cast<int>(error)));
+ std::string err_str = base::File::ErrorToString(error);
char buf[512];
snprintf(buf, sizeof(buf), "%s (MojoFSError: %d::%s)", err_str.c_str(),
method, MethodIDToString(method));
- // TOOD(crbug.com/760362): Map FileError::NOT_FOUND to Status::NotFound, after
- // fixing LevelDB to handle the NotFound correctly.
+ // TOOD(https://crbug.com/760362): Map base::File::Error::NOT_FOUND to
+ // Status::NotFound, after fixing LevelDB to handle the NotFound correctly.
return Status::IOError(filename, buf);
}
@@ -209,12 +210,12 @@
enum Type { kManifest, kTable, kOther };
leveldb::Status SyncParent() {
- FileError error = thread_->SyncDirectory(dir_, parent_dir_);
- if (error != FileError::OK) {
+ base::File::Error error = thread_->SyncDirectory(dir_, parent_dir_);
+ if (error != base::File::Error::FILE_OK) {
uma_logger_->RecordOSError(leveldb_env::kSyncParent,
static_cast<base::File::Error>(error));
}
- return error == FileError::OK
+ return error == base::File::Error::FILE_OK
? Status::OK()
: Status::IOError(filename_,
base::File::ErrorToString(base::File::Error(
@@ -276,10 +277,6 @@
}
}
- bool ShouldKeepTrying(FileError error) {
- return ShouldKeepTrying(static_cast<base::File::Error>(error));
- }
-
bool ShouldKeepTrying(base::File::Error last_error) {
DCHECK_NE(last_error, base::File::FILE_OK);
last_error_ = last_error;
@@ -390,16 +387,16 @@
Status MojoEnv::GetChildren(const std::string& path,
std::vector<std::string>* result) {
TRACE_EVENT1("leveldb", "MojoEnv::GetChildren", "path", path);
- FileError error = thread_->GetChildren(dir_, path, result);
- if (error != FileError::OK)
+ base::File::Error error = thread_->GetChildren(dir_, path, result);
+ if (error != base::File::Error::FILE_OK)
RecordFileError(leveldb_env::kGetChildren, error);
return FilesystemErrorToStatus(error, path, leveldb_env::kGetChildren);
}
Status MojoEnv::DeleteFile(const std::string& fname) {
TRACE_EVENT1("leveldb", "MojoEnv::DeleteFile", "fname", fname);
- FileError error = thread_->Delete(dir_, fname, 0);
- if (error != FileError::OK)
+ base::File::Error error = thread_->Delete(dir_, fname, 0);
+ if (error != base::File::Error::FILE_OK)
RecordFileError(leveldb_env::kDeleteFile, error);
return FilesystemErrorToStatus(error, fname, leveldb_env::kDeleteFile);
}
@@ -407,28 +404,29 @@
Status MojoEnv::CreateDir(const std::string& dirname) {
TRACE_EVENT1("leveldb", "MojoEnv::CreateDir", "dirname", dirname);
Retrier retrier(leveldb_env::kCreateDir, this);
- FileError error;
+ base::File::Error error;
do {
error = thread_->CreateDir(dir_, dirname);
- } while (error != FileError::OK && retrier.ShouldKeepTrying(error));
- if (error != FileError::OK)
+ } while (error != base::File::Error::FILE_OK &&
+ retrier.ShouldKeepTrying(error));
+ if (error != base::File::Error::FILE_OK)
RecordFileError(leveldb_env::kCreateDir, error);
return FilesystemErrorToStatus(error, dirname, leveldb_env::kCreateDir);
}
Status MojoEnv::DeleteDir(const std::string& dirname) {
TRACE_EVENT1("leveldb", "MojoEnv::DeleteDir", "dirname", dirname);
- FileError error =
+ base::File::Error error =
thread_->Delete(dir_, dirname, filesystem::mojom::kDeleteFlagRecursive);
- if (error != FileError::OK)
+ if (error != base::File::Error::FILE_OK)
RecordFileError(leveldb_env::kDeleteDir, error);
return FilesystemErrorToStatus(error, dirname, leveldb_env::kDeleteDir);
}
Status MojoEnv::GetFileSize(const std::string& fname, uint64_t* file_size) {
TRACE_EVENT1("leveldb", "MojoEnv::GetFileSize", "fname", fname);
- FileError error = thread_->GetFileSize(dir_, fname, file_size);
- if (error != FileError::OK)
+ base::File::Error error = thread_->GetFileSize(dir_, fname, file_size);
+ if (error != base::File::Error::FILE_OK)
RecordFileError(leveldb_env::kGetFileSize, error);
return FilesystemErrorToStatus(error, fname, leveldb_env::kGetFileSize);
}
@@ -438,11 +436,12 @@
if (!thread_->FileExists(dir_, src))
return Status::OK();
Retrier retrier(leveldb_env::kRenameFile, this);
- FileError error;
+ base::File::Error error;
do {
error = thread_->RenameFile(dir_, src, target);
- } while (error != FileError::OK && retrier.ShouldKeepTrying(error));
- if (error != FileError::OK)
+ } while (error != base::File::Error::FILE_OK &&
+ retrier.ShouldKeepTrying(error));
+ if (error != base::File::Error::FILE_OK)
RecordFileError(leveldb_env::kRenameFile, error);
return FilesystemErrorToStatus(error, src, leveldb_env::kRenameFile);
}
@@ -451,12 +450,13 @@
TRACE_EVENT1("leveldb", "MojoEnv::LockFile", "fname", fname);
Retrier retrier(leveldb_env::kLockFile, this);
- std::pair<FileError, LevelDBMojoProxy::OpaqueLock*> p;
+ std::pair<base::File::Error, LevelDBMojoProxy::OpaqueLock*> p;
do {
p = thread_->LockFile(dir_, fname);
- } while (p.first != FileError::OK && retrier.ShouldKeepTrying(p.first));
+ } while (p.first != base::File::Error::FILE_OK &&
+ retrier.ShouldKeepTrying(p.first));
- if (p.first != FileError::OK)
+ if (p.first != base::File::Error::FILE_OK)
RecordFileError(leveldb_env::kLockFile, p.first);
if (p.second)
@@ -471,8 +471,8 @@
std::string fname = my_lock ? my_lock->name() : "(invalid)";
TRACE_EVENT1("leveldb", "MojoEnv::UnlockFile", "fname", fname);
- FileError error = thread_->UnlockFile(my_lock->TakeLock());
- if (error != FileError::OK)
+ base::File::Error error = thread_->UnlockFile(my_lock->TakeLock());
+ if (error != base::File::Error::FILE_OK)
RecordFileError(leveldb_env::kUnlockFile, error);
delete my_lock;
return FilesystemErrorToStatus(error, fname, leveldb_env::kUnlockFile);
@@ -565,7 +565,7 @@
}
void MojoEnv::RecordFileError(leveldb_env::MethodID method,
- FileError error) const {
+ base::File::Error error) const {
RecordOSError(method, static_cast<base::File::Error>(error));
}
diff --git a/components/leveldb/env_mojo.h b/components/leveldb/env_mojo.h
index db24046..a2264d96 100644
--- a/components/leveldb/env_mojo.h
+++ b/components/leveldb/env_mojo.h
@@ -5,6 +5,9 @@
#ifndef COMPONENTS_LEVELDB_ENV_MOJO_H_
#define COMPONENTS_LEVELDB_ENV_MOJO_H_
+#include <string>
+#include <vector>
+
#include "components/filesystem/public/interfaces/directory.mojom.h"
#include "components/leveldb/leveldb_mojo_proxy.h"
#include "third_party/leveldatabase/env_chromium.h"
@@ -74,7 +77,7 @@
base::File::Error error) const override;
void RecordFileError(leveldb_env::MethodID method,
- filesystem::mojom::FileError error) const;
+ base::File::Error error) const;
scoped_refptr<LevelDBMojoProxy> thread_;
LevelDBMojoProxy::OpaqueDir* dir_;
diff --git a/components/leveldb/leveldb_mojo_proxy.cc b/components/leveldb/leveldb_mojo_proxy.cc
index 5f35e33..c067719c 100644
--- a/components/leveldb/leveldb_mojo_proxy.cc
+++ b/components/leveldb/leveldb_mojo_proxy.cc
@@ -57,10 +57,9 @@
return file;
}
-filesystem::mojom::FileError LevelDBMojoProxy::SyncDirectory(
- OpaqueDir* dir,
- const std::string& name) {
- filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED;
+base::File::Error LevelDBMojoProxy::SyncDirectory(OpaqueDir* dir,
+ const std::string& name) {
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
RunInternal(base::Bind(&LevelDBMojoProxy::SyncDirectoryImpl, this, dir,
name, &error));
return error;
@@ -73,67 +72,64 @@
return exists;
}
-filesystem::mojom::FileError LevelDBMojoProxy::GetChildren(
+base::File::Error LevelDBMojoProxy::GetChildren(
OpaqueDir* dir,
const std::string& path,
std::vector<std::string>* result) {
- filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED;
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
RunInternal(base::Bind(&LevelDBMojoProxy::GetChildrenImpl, this, dir,
path, result, &error));
return error;
}
-filesystem::mojom::FileError LevelDBMojoProxy::Delete(OpaqueDir* dir,
- const std::string& path,
- uint32_t delete_flags) {
- filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED;
+base::File::Error LevelDBMojoProxy::Delete(OpaqueDir* dir,
+ const std::string& path,
+ uint32_t delete_flags) {
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
RunInternal(base::Bind(&LevelDBMojoProxy::DeleteImpl, this, dir, path,
delete_flags, &error));
return error;
}
-filesystem::mojom::FileError LevelDBMojoProxy::CreateDir(
- OpaqueDir* dir,
- const std::string& path) {
- filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED;
+base::File::Error LevelDBMojoProxy::CreateDir(OpaqueDir* dir,
+ const std::string& path) {
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
RunInternal(base::Bind(&LevelDBMojoProxy::CreateDirImpl, this, dir, path,
&error));
return error;
}
-filesystem::mojom::FileError LevelDBMojoProxy::GetFileSize(
- OpaqueDir* dir,
- const std::string& path,
- uint64_t* file_size) {
- filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED;
+base::File::Error LevelDBMojoProxy::GetFileSize(OpaqueDir* dir,
+ const std::string& path,
+ uint64_t* file_size) {
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
RunInternal(base::Bind(&LevelDBMojoProxy::GetFileSizeImpl, this, dir,
path, file_size, &error));
return error;
}
-filesystem::mojom::FileError LevelDBMojoProxy::RenameFile(
- OpaqueDir* dir,
- const std::string& old_path,
- const std::string& new_path) {
- filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED;
+base::File::Error LevelDBMojoProxy::RenameFile(OpaqueDir* dir,
+ const std::string& old_path,
+ const std::string& new_path) {
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
RunInternal(base::Bind(&LevelDBMojoProxy::RenameFileImpl, this, dir,
old_path, new_path, &error));
return error;
}
-std::pair<filesystem::mojom::FileError, LevelDBMojoProxy::OpaqueLock*>
+std::pair<base::File::Error, LevelDBMojoProxy::OpaqueLock*>
LevelDBMojoProxy::LockFile(OpaqueDir* dir, const std::string& path) {
- filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED;
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
OpaqueLock* out_lock = nullptr;
RunInternal(base::Bind(&LevelDBMojoProxy::LockFileImpl, this, dir, path,
&error, &out_lock));
return std::make_pair(error, out_lock);
}
-filesystem::mojom::FileError LevelDBMojoProxy::UnlockFile(OpaqueLock* lock) {
+base::File::Error LevelDBMojoProxy::UnlockFile(OpaqueLock* lock) {
// Take ownership of the incoming lock so it gets destroyed whatever happens.
std::unique_ptr<OpaqueLock> scoped_lock(lock);
- filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED;
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
RunInternal(base::Bind(&LevelDBMojoProxy::UnlockFileImpl, this,
base::Passed(&scoped_lock), &error));
return error;
@@ -188,22 +184,21 @@
base::File* output_file) {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync;
base::File file;
- filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED;
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
bool completed =
dir->directory->OpenFileHandle(name, open_flags, &error, &file);
DCHECK(completed);
- if (error != filesystem::mojom::FileError::OK) {
- *output_file = base::File(static_cast<base::File::Error>(error));
+ if (error != base::File::Error::FILE_OK) {
+ *output_file = base::File(error);
} else {
*output_file = std::move(file);
}
}
-void LevelDBMojoProxy::SyncDirectoryImpl(
- OpaqueDir* dir,
- std::string name,
- filesystem::mojom::FileError* out_error) {
+void LevelDBMojoProxy::SyncDirectoryImpl(OpaqueDir* dir,
+ std::string name,
+ base::File::Error* out_error) {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync;
filesystem::mojom::DirectoryPtr target;
bool completed = dir->directory->OpenDirectory(
@@ -211,7 +206,7 @@
filesystem::mojom::kFlagRead | filesystem::mojom::kFlagWrite, out_error);
DCHECK(completed);
- if (*out_error != filesystem::mojom::FileError::OK)
+ if (*out_error != base::File::Error::FILE_OK)
return;
completed = target->Flush(out_error);
@@ -222,16 +217,15 @@
std::string name,
bool* exists) {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync;
- filesystem::mojom::FileError error = filesystem::mojom::FileError::FAILED;
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
bool completed = dir->directory->Exists(name, &error, exists);
DCHECK(completed);
}
-void LevelDBMojoProxy::GetChildrenImpl(
- OpaqueDir* dir,
- std::string name,
- std::vector<std::string>* out_contents,
- filesystem::mojom::FileError* out_error) {
+void LevelDBMojoProxy::GetChildrenImpl(OpaqueDir* dir,
+ std::string name,
+ std::vector<std::string>* out_contents,
+ base::File::Error* out_error) {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync;
filesystem::mojom::DirectoryPtr target;
bool completed = dir->directory->OpenDirectory(
@@ -239,7 +233,7 @@
filesystem::mojom::kFlagRead | filesystem::mojom::kFlagWrite, out_error);
DCHECK(completed);
- if (*out_error != filesystem::mojom::FileError::OK)
+ if (*out_error != base::File::Error::FILE_OK)
return;
base::Optional<std::vector<filesystem::mojom::DirectoryEntryPtr>>
@@ -256,7 +250,7 @@
void LevelDBMojoProxy::DeleteImpl(OpaqueDir* dir,
std::string name,
uint32_t delete_flags,
- filesystem::mojom::FileError* out_error) {
+ base::File::Error* out_error) {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync;
bool completed = dir->directory->Delete(name, delete_flags, out_error);
DCHECK(completed);
@@ -264,7 +258,7 @@
void LevelDBMojoProxy::CreateDirImpl(OpaqueDir* dir,
std::string name,
- filesystem::mojom::FileError* out_error) {
+ base::File::Error* out_error) {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync;
bool completed = dir->directory->OpenDirectory(
name, nullptr,
@@ -274,11 +268,10 @@
DCHECK(completed);
}
-void LevelDBMojoProxy::GetFileSizeImpl(
- OpaqueDir* dir,
- const std::string& path,
- uint64_t* file_size,
- filesystem::mojom::FileError* out_error) {
+void LevelDBMojoProxy::GetFileSizeImpl(OpaqueDir* dir,
+ const std::string& path,
+ uint64_t* file_size,
+ base::File::Error* out_error) {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync;
filesystem::mojom::FileInformationPtr info;
bool completed = dir->directory->StatFile(path, out_error, &info);
@@ -290,7 +283,7 @@
void LevelDBMojoProxy::RenameFileImpl(OpaqueDir* dir,
const std::string& old_path,
const std::string& new_path,
- filesystem::mojom::FileError* out_error) {
+ base::File::Error* out_error) {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync;
bool completed = dir->directory->Replace(old_path, new_path, out_error);
DCHECK(completed);
@@ -298,7 +291,7 @@
void LevelDBMojoProxy::LockFileImpl(OpaqueDir* dir,
const std::string& path,
- filesystem::mojom::FileError* out_error,
+ base::File::Error* out_error,
OpaqueLock** out_lock) {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync;
// Since a lock is associated with a file descriptor, we need to open and
@@ -311,13 +304,13 @@
out_error);
DCHECK(completed);
- if (*out_error != filesystem::mojom::FileError::OK)
+ if (*out_error != base::File::Error::FILE_OK)
return;
completed = target->Lock(out_error);
DCHECK(completed);
- if (*out_error == filesystem::mojom::FileError::OK) {
+ if (*out_error == base::File::Error::FILE_OK) {
OpaqueLock* l = new OpaqueLock;
l->lock_file = std::move(target);
*out_lock = l;
@@ -325,7 +318,7 @@
}
void LevelDBMojoProxy::UnlockFileImpl(std::unique_ptr<OpaqueLock> lock,
- filesystem::mojom::FileError* out_error) {
+ base::File::Error* out_error) {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync;
lock->lock_file->Unlock(out_error);
}
diff --git a/components/leveldb/leveldb_mojo_proxy.h b/components/leveldb/leveldb_mojo_proxy.h
index 4b5e0ad..eee605f4b 100644
--- a/components/leveldb/leveldb_mojo_proxy.h
+++ b/components/leveldb/leveldb_mojo_proxy.h
@@ -57,47 +57,44 @@
uint32_t open_flags);
// Synchronously syncs |directory_|.
- filesystem::mojom::FileError SyncDirectory(OpaqueDir* dir,
- const std::string& name);
+ base::File::Error SyncDirectory(OpaqueDir* dir, const std::string& name);
// Synchronously checks whether |name| exists.
bool FileExists(OpaqueDir* dir, const std::string& name);
// Synchronously returns the filenames of all files in |path|.
- filesystem::mojom::FileError GetChildren(OpaqueDir* dir,
- const std::string& path,
- std::vector<std::string>* result);
+ base::File::Error GetChildren(OpaqueDir* dir,
+ const std::string& path,
+ std::vector<std::string>* result);
// Synchronously deletes |path|.
- filesystem::mojom::FileError Delete(OpaqueDir* dir,
- const std::string& path,
- uint32_t delete_flags);
+ base::File::Error Delete(OpaqueDir* dir,
+ const std::string& path,
+ uint32_t delete_flags);
// Synchronously creates |path|.
- filesystem::mojom::FileError CreateDir(OpaqueDir* dir,
- const std::string& path);
+ base::File::Error CreateDir(OpaqueDir* dir, const std::string& path);
// Synchronously gets the size of a file.
- filesystem::mojom::FileError GetFileSize(OpaqueDir* dir,
- const std::string& path,
- uint64_t* file_size);
+ base::File::Error GetFileSize(OpaqueDir* dir,
+ const std::string& path,
+ uint64_t* file_size);
// Synchronously renames a file.
- filesystem::mojom::FileError RenameFile(OpaqueDir* dir,
- const std::string& old_path,
- const std::string& new_path);
+ base::File::Error RenameFile(OpaqueDir* dir,
+ const std::string& old_path,
+ const std::string& new_path);
// Synchronously locks a file. Returns both the file return code, and if OK,
// an opaque object to the lock to enforce going through this interface to
// unlock the file so that unlocking happens on the correct thread.
- std::pair<filesystem::mojom::FileError, OpaqueLock*> LockFile(
- OpaqueDir* dir,
- const std::string& path);
+ std::pair<base::File::Error, OpaqueLock*> LockFile(OpaqueDir* dir,
+ const std::string& path);
// Unlocks a file. LevelDBMojoProxy takes ownership of lock. (We don't make
// this a scoped_ptr because exporting the ctor/dtor for this struct publicly
// defeats the purpose of the struct.)
- filesystem::mojom::FileError UnlockFile(OpaqueLock* lock);
+ base::File::Error UnlockFile(OpaqueLock* lock);
private:
friend class base::RefCountedThreadSafe<LevelDBMojoProxy>;
@@ -120,35 +117,35 @@
base::File* out_file);
void SyncDirectoryImpl(OpaqueDir* dir,
std::string name,
- filesystem::mojom::FileError* out_error);
+ base::File::Error* out_error);
void FileExistsImpl(OpaqueDir* dir,
std::string name,
bool* exists);
void GetChildrenImpl(OpaqueDir* dir,
std::string name,
std::vector<std::string>* contents,
- filesystem::mojom::FileError* out_error);
+ base::File::Error* out_error);
void DeleteImpl(OpaqueDir* dir,
std::string name,
uint32_t delete_flags,
- filesystem::mojom::FileError* out_error);
+ base::File::Error* out_error);
void CreateDirImpl(OpaqueDir* dir,
std::string name,
- filesystem::mojom::FileError* out_error);
+ base::File::Error* out_error);
void GetFileSizeImpl(OpaqueDir* dir,
const std::string& path,
uint64_t* file_size,
- filesystem::mojom::FileError* out_error);
+ base::File::Error* out_error);
void RenameFileImpl(OpaqueDir* dir,
const std::string& old_path,
const std::string& new_path,
- filesystem::mojom::FileError* out_error);
+ base::File::Error* out_error);
void LockFileImpl(OpaqueDir* dir,
const std::string& path,
- filesystem::mojom::FileError* out_error,
+ base::File::Error* out_error,
OpaqueLock** out_lock);
void UnlockFileImpl(std::unique_ptr<OpaqueLock> lock,
- filesystem::mojom::FileError* out_error);
+ base::File::Error* out_error);
// The task runner which represents the sequence that all mojo objects are
// bound to.
diff --git a/components/leveldb/leveldb_service_unittest.cc b/components/leveldb/leveldb_service_unittest.cc
index ef65336..f18a375b8 100644
--- a/components/leveldb/leveldb_service_unittest.cc
+++ b/components/leveldb/leveldb_service_unittest.cc
@@ -14,8 +14,6 @@
#include "services/service_manager/public/cpp/service_context.h"
#include "services/service_manager/public/cpp/service_test.h"
-using filesystem::mojom::FileError;
-
namespace leveldb {
namespace {
@@ -136,10 +134,10 @@
// Note: This has an out parameter rather than returning the |DirectoryPtr|,
// since |ASSERT_...()| doesn't work with return values.
void GetTempDirectory(filesystem::mojom::DirectoryPtr* directory) {
- FileError error = FileError::FAILED;
+ base::File::Error error = base::File::Error::FILE_ERROR_FAILED;
bool handled = files()->OpenTempDirectory(MakeRequest(directory), &error);
ASSERT_TRUE(handled);
- ASSERT_EQ(FileError::OK, error);
+ ASSERT_EQ(base::File::Error::FILE_OK, error);
}
filesystem::mojom::FileSystemPtr& files() { return files_; }
diff --git a/components/unzip_service/unzipper_impl.cc b/components/unzip_service/unzipper_impl.cc
index 95c1855..9039e80 100644
--- a/components/unzip_service/unzipper_impl.cc
+++ b/components/unzip_service/unzipper_impl.cc
@@ -4,6 +4,9 @@
#include "components/unzip_service/unzipper_impl.h"
+#include <string>
+#include <utility>
+
#include "base/compiler_specific.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
@@ -40,25 +43,25 @@
// Modifies output_dir to point to the final directory.
bool CreateDirectory(filesystem::mojom::DirectoryPtr* output_dir,
const base::FilePath& path) {
- filesystem::mojom::FileError err = filesystem::mojom::FileError::OK;
+ base::File::Error err = base::File::Error::FILE_OK;
return (*output_dir)
->OpenDirectory(PathToMojoString(path), nullptr,
filesystem::mojom::kFlagOpenAlways, &err) &&
- err == filesystem::mojom::FileError::OK;
+ err == base::File::Error::FILE_OK;
}
std::unique_ptr<zip::WriterDelegate> MakeFileWriterDelegateNoParent(
filesystem::mojom::DirectoryPtr* output_dir,
const base::FilePath& path) {
auto file = std::make_unique<base::File>();
- filesystem::mojom::FileError err;
+ base::File::Error err;
if (!(*output_dir)
->OpenFileHandle(PathToMojoString(path),
filesystem::mojom::kFlagCreate |
filesystem::mojom::kFlagWrite |
filesystem::mojom::kFlagWriteAttributes,
&err, file.get()) ||
- err != filesystem::mojom::FileError::OK) {
+ err != base::File::Error::FILE_OK) {
return std::make_unique<DudWriterDelegate>();
}
return std::make_unique<zip::FileWriterDelegate>(std::move(file));
@@ -70,12 +73,12 @@
if (path == path.BaseName())
return MakeFileWriterDelegateNoParent(output_dir, path);
filesystem::mojom::DirectoryPtr parent;
- filesystem::mojom::FileError err;
+ base::File::Error err;
if (!(*output_dir)
->OpenDirectory(PathToMojoString(path.DirName()),
mojo::MakeRequest(&parent),
filesystem::mojom::kFlagOpenAlways, &err) ||
- err != filesystem::mojom::FileError::OK) {
+ err != base::File::Error::FILE_OK) {
return std::make_unique<DudWriterDelegate>();
}
return MakeFileWriterDelegateNoParent(&parent, path.BaseName());
diff --git a/content/browser/dom_storage/local_storage_context_mojo.cc b/content/browser/dom_storage/local_storage_context_mojo.cc
index 7193a33d..4a88ace 100644
--- a/content/browser/dom_storage/local_storage_context_mojo.cc
+++ b/content/browser/dom_storage/local_storage_context_mojo.cc
@@ -5,7 +5,13 @@
#include "content/browser/dom_storage/local_storage_context_mojo.h"
#include <inttypes.h>
+
+#include <algorithm>
#include <cctype> // for std::isalnum
+#include <set>
+#include <string>
+#include <utility>
+
#include "base/barrier_closure.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
@@ -680,13 +686,11 @@
}
}
-void LocalStorageContextMojo::OnDirectoryOpened(
- filesystem::mojom::FileError err) {
- if (err != filesystem::mojom::FileError::OK) {
+void LocalStorageContextMojo::OnDirectoryOpened(base::File::Error err) {
+ if (err != base::File::Error::FILE_OK) {
// We failed to open the directory; continue with startup so that we create
// the |level_db_wrappers_|.
- UMA_HISTOGRAM_ENUMERATION("LocalStorageContext.DirectoryOpenError",
- -static_cast<base::File::Error>(err),
+ UMA_HISTOGRAM_ENUMERATION("LocalStorageContext.DirectoryOpenError", -err,
-base::File::FILE_ERROR_MAX);
LogDatabaseOpenResult(OpenResult::DIRECTORY_OPEN_FAILED);
OnDatabaseOpened(false, leveldb::mojom::DatabaseError::OK);
diff --git a/content/browser/dom_storage/local_storage_context_mojo.h b/content/browser/dom_storage/local_storage_context_mojo.h
index b7df333..2d7799a 100644
--- a/content/browser/dom_storage/local_storage_context_mojo.h
+++ b/content/browser/dom_storage/local_storage_context_mojo.h
@@ -107,7 +107,7 @@
// Part of our asynchronous directory opening called from RunWhenConnected().
void InitiateConnection(bool in_memory_only = false);
- void OnDirectoryOpened(filesystem::mojom::FileError err);
+ void OnDirectoryOpened(base::File::Error err);
void OnDatabaseOpened(bool in_memory, leveldb::mojom::DatabaseError status);
void OnGotDatabaseVersion(leveldb::mojom::DatabaseError status,
const std::vector<uint8_t>& value);
diff --git a/mojo/public/cpp/base/file_error.typemap b/mojo/public/cpp/base/file_error.typemap
new file mode 100644
index 0000000..738a9a7c
--- /dev/null
+++ b/mojo/public/cpp/base/file_error.typemap
@@ -0,0 +1,12 @@
+# Copyright 2018 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+mojom = "//mojo/public/mojom/base/file_error.mojom"
+public_headers = [ "//base/files/file.h" ]
+traits_headers = [ "//mojo/public/cpp/base/file_error_mojom_traits.h" ]
+public_deps = [
+ "//base",
+ "//mojo/public/cpp/bindings",
+]
+type_mappings = [ "mojo_base.mojom.FileError=::base::File::Error" ]
diff --git a/mojo/public/cpp/base/file_error_mojom_traits.h b/mojo/public/cpp/base/file_error_mojom_traits.h
new file mode 100644
index 0000000..941608e3
--- /dev/null
+++ b/mojo/public/cpp/base/file_error_mojom_traits.h
@@ -0,0 +1,120 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_CPP_BASE_FILE_ERROR_MOJOM_TRAITS_H_
+#define MOJO_PUBLIC_CPP_BASE_FILE_ERROR_MOJOM_TRAITS_H_
+
+#include "base/files/file.h"
+#include "mojo/public/mojom/base/file_error.mojom.h"
+
+namespace mojo {
+
+template <>
+struct EnumTraits<mojo_base::mojom::FileError, base::File::Error> {
+ static mojo_base::mojom::FileError ToMojom(base::File::Error error) {
+ switch (error) {
+ case base::File::FILE_OK:
+ return mojo_base::mojom::FileError::OK;
+ case base::File::FILE_ERROR_FAILED:
+ return mojo_base::mojom::FileError::FAILED;
+ case base::File::FILE_ERROR_IN_USE:
+ return mojo_base::mojom::FileError::IN_USE;
+ case base::File::FILE_ERROR_EXISTS:
+ return mojo_base::mojom::FileError::EXISTS;
+ case base::File::FILE_ERROR_NOT_FOUND:
+ return mojo_base::mojom::FileError::NOT_FOUND;
+ case base::File::FILE_ERROR_ACCESS_DENIED:
+ return mojo_base::mojom::FileError::ACCESS_DENIED;
+ case base::File::FILE_ERROR_TOO_MANY_OPENED:
+ return mojo_base::mojom::FileError::TOO_MANY_OPENED;
+ case base::File::FILE_ERROR_NO_MEMORY:
+ return mojo_base::mojom::FileError::NO_MEMORY;
+ case base::File::FILE_ERROR_NO_SPACE:
+ return mojo_base::mojom::FileError::NO_SPACE;
+ case base::File::FILE_ERROR_NOT_A_DIRECTORY:
+ return mojo_base::mojom::FileError::NOT_A_DIRECTORY;
+ case base::File::FILE_ERROR_INVALID_OPERATION:
+ return mojo_base::mojom::FileError::INVALID_OPERATION;
+ case base::File::FILE_ERROR_SECURITY:
+ return mojo_base::mojom::FileError::SECURITY;
+ case base::File::FILE_ERROR_ABORT:
+ return mojo_base::mojom::FileError::ABORT;
+ case base::File::FILE_ERROR_NOT_A_FILE:
+ return mojo_base::mojom::FileError::NOT_A_FILE;
+ case base::File::FILE_ERROR_NOT_EMPTY:
+ return mojo_base::mojom::FileError::NOT_EMPTY;
+ case base::File::FILE_ERROR_INVALID_URL:
+ return mojo_base::mojom::FileError::INVALID_URL;
+ case base::File::FILE_ERROR_IO:
+ return mojo_base::mojom::FileError::IO;
+ case base::File::FILE_ERROR_MAX:
+ return mojo_base::mojom::FileError::FAILED;
+ }
+ NOTREACHED();
+ return mojo_base::mojom::FileError::FAILED;
+ }
+
+ static bool FromMojom(mojo_base::mojom::FileError in,
+ base::File::Error* out) {
+ switch (in) {
+ case mojo_base::mojom::FileError::OK:
+ *out = base::File::FILE_OK;
+ return true;
+ case mojo_base::mojom::FileError::FAILED:
+ *out = base::File::FILE_ERROR_FAILED;
+ return true;
+ case mojo_base::mojom::FileError::IN_USE:
+ *out = base::File::FILE_ERROR_IN_USE;
+ return true;
+ case mojo_base::mojom::FileError::EXISTS:
+ *out = base::File::FILE_ERROR_EXISTS;
+ return true;
+ case mojo_base::mojom::FileError::NOT_FOUND:
+ *out = base::File::FILE_ERROR_NOT_FOUND;
+ return true;
+ case mojo_base::mojom::FileError::ACCESS_DENIED:
+ *out = base::File::FILE_ERROR_ACCESS_DENIED;
+ return true;
+ case mojo_base::mojom::FileError::TOO_MANY_OPENED:
+ *out = base::File::FILE_ERROR_TOO_MANY_OPENED;
+ return true;
+ case mojo_base::mojom::FileError::NO_MEMORY:
+ *out = base::File::FILE_ERROR_NO_MEMORY;
+ return true;
+ case mojo_base::mojom::FileError::NO_SPACE:
+ *out = base::File::FILE_ERROR_NO_SPACE;
+ return true;
+ case mojo_base::mojom::FileError::NOT_A_DIRECTORY:
+ *out = base::File::FILE_ERROR_NOT_A_DIRECTORY;
+ return true;
+ case mojo_base::mojom::FileError::INVALID_OPERATION:
+ *out = base::File::FILE_ERROR_INVALID_OPERATION;
+ return true;
+ case mojo_base::mojom::FileError::SECURITY:
+ *out = base::File::FILE_ERROR_SECURITY;
+ return true;
+ case mojo_base::mojom::FileError::ABORT:
+ *out = base::File::FILE_ERROR_ABORT;
+ return true;
+ case mojo_base::mojom::FileError::NOT_A_FILE:
+ *out = base::File::FILE_ERROR_NOT_A_FILE;
+ return true;
+ case mojo_base::mojom::FileError::NOT_EMPTY:
+ *out = base::File::FILE_ERROR_NOT_EMPTY;
+ return true;
+ case mojo_base::mojom::FileError::INVALID_URL:
+ *out = base::File::FILE_ERROR_INVALID_URL;
+ return true;
+ case mojo_base::mojom::FileError::IO:
+ *out = base::File::FILE_ERROR_IO;
+ return true;
+ }
+ NOTREACHED();
+ return false;
+ }
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BASE_FILE_ERROR_MOJOM_TRAITS_H_
diff --git a/mojo/public/cpp/base/typemaps.gni b/mojo/public/cpp/base/typemaps.gni
index 83552ae..3652bc3 100644
--- a/mojo/public/cpp/base/typemaps.gni
+++ b/mojo/public/cpp/base/typemaps.gni
@@ -5,6 +5,7 @@
typemaps = [
"//mojo/public/cpp/base/big_buffer.typemap",
"//mojo/public/cpp/base/big_string.typemap",
+ "//mojo/public/cpp/base/file_error.typemap",
"//mojo/public/cpp/base/ref_counted_memory.typemap",
"//mojo/public/cpp/base/string16.typemap",
]
diff --git a/mojo/public/mojom/base/BUILD.gn b/mojo/public/mojom/base/BUILD.gn
index 51cb4fa..aec5029d 100644
--- a/mojo/public/mojom/base/BUILD.gn
+++ b/mojo/public/mojom/base/BUILD.gn
@@ -8,6 +8,7 @@
sources = [
"big_buffer.mojom",
"big_string.mojom",
+ "file_error.mojom",
"ref_counted_memory.mojom",
"string16.mojom",
]
diff --git a/mojo/public/mojom/base/file_error.mojom b/mojo/public/mojom/base/file_error.mojom
new file mode 100644
index 0000000..3ca61aa9
--- /dev/null
+++ b/mojo/public/mojom/base/file_error.mojom
@@ -0,0 +1,27 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+module mojo_base.mojom;
+
+// Error codes used by the file system. These error codes line up exactly with
+// those of base::File and are typemapped to base::File::Error enum.
+enum FileError {
+ OK = 0,
+ FAILED = -1,
+ IN_USE = -2,
+ EXISTS = -3,
+ NOT_FOUND = -4,
+ ACCESS_DENIED = -5,
+ TOO_MANY_OPENED = -6,
+ NO_MEMORY = -7,
+ NO_SPACE = -8,
+ NOT_A_DIRECTORY = -9,
+ INVALID_OPERATION = -10,
+ SECURITY = -11,
+ ABORT = -12,
+ NOT_A_FILE = -13,
+ NOT_EMPTY = -14,
+ INVALID_URL = -15,
+ IO = -16,
+};
diff --git a/services/file/file_system.cc b/services/file/file_system.cc
index da43652..92a41f83 100644
--- a/services/file/file_system.cc
+++ b/services/file/file_system.cc
@@ -4,6 +4,10 @@
#include "services/file/file_system.h"
+#include <memory>
+#include <string>
+#include <utility>
+
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
@@ -46,7 +50,7 @@
#endif
base::File::Error error;
if (!base::CreateDirectoryAndGetError(subdir, &error)) {
- std::move(callback).Run(static_cast<filesystem::mojom::FileError>(error));
+ std::move(callback).Run(error);
return;
}
@@ -54,7 +58,7 @@
std::make_unique<filesystem::DirectoryImpl>(
subdir, scoped_refptr<filesystem::SharedTempDir>(), lock_table_),
std::move(request));
- std::move(callback).Run(filesystem::mojom::FileError::OK);
+ std::move(callback).Run(base::File::Error::FILE_OK);
}
} // namespace file
diff --git a/services/file/public/mojom/BUILD.gn b/services/file/public/mojom/BUILD.gn
index b2fd12a..98b0cc0b1 100644
--- a/services/file/public/mojom/BUILD.gn
+++ b/services/file/public/mojom/BUILD.gn
@@ -15,6 +15,7 @@
public_deps = [
":constants",
+ "//mojo/public/mojom/base",
]
}
diff --git a/services/file/public/mojom/file_system.mojom b/services/file/public/mojom/file_system.mojom
index c3a422d..2d2659c 100644
--- a/services/file/public/mojom/file_system.mojom
+++ b/services/file/public/mojom/file_system.mojom
@@ -5,7 +5,7 @@
module file.mojom;
import "components/filesystem/public/interfaces/directory.mojom";
-import "components/filesystem/public/interfaces/types.mojom";
+import "mojo/public/mojom/base/file_error.mojom";
// Provide access to various directories within the requesting user's directory.
interface FileSystem {
@@ -15,5 +15,5 @@
// Returns a subdirectory under the user's dir. Returns a filesystem error
// when we fail to create the subdirectory.
GetSubDirectory(string dir_path, filesystem.mojom.Directory& dir)
- => (filesystem.mojom.FileError err);
+ => (mojo_base.mojom.FileError err);
};