Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Unified Diff: components/filesystem/directory_impl.cc

Issue 1942473002: Eliminate mojo:resource_provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/filesystem/directory_impl.h ('k') | components/filesystem/filesystem.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/filesystem/directory_impl.cc
diff --git a/components/filesystem/directory_impl.cc b/components/filesystem/directory_impl.cc
index d6430710db0e45f73821420e5949f8a2225d8a67..aa208bcd85231b98e7a5fb293ddc1893dd0d4d0a 100644
--- a/components/filesystem/directory_impl.cc
+++ b/components/filesystem/directory_impl.cc
@@ -18,8 +18,6 @@
#include "mojo/common/common_type_converters.h"
#include "mojo/platform_handle/platform_handle_functions.h"
-using mojo::ScopedHandle;
-
namespace filesystem {
DirectoryImpl::DirectoryImpl(mojo::InterfaceRequest<Directory> request,
@@ -91,36 +89,24 @@ void DirectoryImpl::OpenFile(const mojo::String& raw_path,
void DirectoryImpl::OpenFileHandle(const mojo::String& raw_path,
uint32_t open_flags,
const OpenFileHandleCallback& callback) {
- base::FilePath path;
- FileError error = ValidatePath(raw_path, directory_path_, &path);
- if (error != FileError::OK) {
- callback.Run(error, ScopedHandle());
- return;
- }
-
- if (base::DirectoryExists(path)) {
- // 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.
- callback.Run(FileError::NOT_A_FILE, ScopedHandle());
- return;
- }
+ FileError error = FileError::OK;
+ mojo::ScopedHandle handle = OpenFileHandleImpl(raw_path, open_flags, &error);
+ callback.Run(error, std::move(handle));
+}
- base::File base_file(path, open_flags);
- if (!base_file.IsValid()) {
- callback.Run(GetError(base_file), ScopedHandle());
- return;
+void DirectoryImpl::OpenFileHandles(mojo::Array<FileOpenDetailsPtr> details,
+ const OpenFileHandlesCallback& callback) {
+ mojo::Array<FileOpenResultPtr> results(
+ mojo::Array<FileOpenResultPtr>::New(details.size()));
+ size_t i = 0;
+ for (const auto& detail : details) {
+ FileOpenResultPtr result(FileOpenResult::New());
+ result->path = detail->path;
+ result->file_handle =
+ OpenFileHandleImpl(detail->path, detail->open_flags, &result->error);
+ results[i++] = std::move(result);
}
-
- MojoHandle mojo_handle;
- MojoResult create_result = MojoCreatePlatformHandleWrapper(
- base_file.TakePlatformFile(), &mojo_handle);
- if (create_result != MOJO_RESULT_OK) {
- callback.Run(FileError::FAILED, ScopedHandle());
- return;
- }
-
- callback.Run(FileError::OK, ScopedHandle(mojo::Handle(mojo_handle)));
+ callback.Run(std::move(results));
}
void DirectoryImpl::OpenDirectory(const mojo::String& raw_path,
@@ -339,4 +325,39 @@ void DirectoryImpl::WriteFile(const mojo::String& raw_path,
callback.Run(FileError::OK);
}
+mojo::ScopedHandle DirectoryImpl::OpenFileHandleImpl(
+ const mojo::String& raw_path,
+ uint32_t open_flags,
+ FileError* error) {
+ base::FilePath path;
+ *error = ValidatePath(raw_path, directory_path_, &path);
+ if (*error != FileError::OK)
+ return mojo::ScopedHandle();
+
+ if (base::DirectoryExists(path)) {
+ // 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.
+ *error = FileError::NOT_A_FILE;
+ return mojo::ScopedHandle();
+ }
+
+ base::File base_file(path, open_flags);
+ if (!base_file.IsValid()) {
+ *error = GetError(base_file);
+ return mojo::ScopedHandle();
+ }
+
+ MojoHandle mojo_handle;
+ MojoResult create_result = MojoCreatePlatformHandleWrapper(
+ base_file.TakePlatformFile(), &mojo_handle);
+ if (create_result != MOJO_RESULT_OK) {
+ *error = FileError::FAILED;
+ return mojo::ScopedHandle();
+ }
+
+ *error = FileError::OK;
+ return mojo::ScopedHandle(mojo::Handle(mojo_handle));
+}
+
} // namespace filesystem
« no previous file with comments | « components/filesystem/directory_impl.h ('k') | components/filesystem/filesystem.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698