Commit 44b9375f authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert NativeFileSystemFileHandle to new Mojo types

This CL converts NativeFileSystemFileHandlePtr to new
Mojo types.

It also updates GetFile from
native_file_system_file_handle.mojom.

Bug: 955171, 978694
Change-Id: Ie1242e453a0331215a005afdd117a5286a18b971
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1771485
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#691516}
parent fdecf5aa
...@@ -88,14 +88,15 @@ void NativeFileSystemDirectoryHandleImpl::GetFile(const std::string& basename, ...@@ -88,14 +88,15 @@ void NativeFileSystemDirectoryHandleImpl::GetFile(const std::string& basename,
blink::mojom::NativeFileSystemErrorPtr get_child_url_result = blink::mojom::NativeFileSystemErrorPtr get_child_url_result =
GetChildURL(basename, &child_url); GetChildURL(basename, &child_url);
if (get_child_url_result->status != NativeFileSystemStatus::kOk) { if (get_child_url_result->status != NativeFileSystemStatus::kOk) {
std::move(callback).Run(std::move(get_child_url_result), nullptr); std::move(callback).Run(std::move(get_child_url_result),
mojo::NullRemote());
return; return;
} }
if (GetReadPermissionStatus() != PermissionStatus::GRANTED) { if (GetReadPermissionStatus() != PermissionStatus::GRANTED) {
std::move(callback).Run(native_file_system_error::FromStatus( std::move(callback).Run(native_file_system_error::FromStatus(
NativeFileSystemStatus::kPermissionDenied), NativeFileSystemStatus::kPermissionDenied),
nullptr); mojo::NullRemote());
return; return;
} }
...@@ -111,7 +112,7 @@ void NativeFileSystemDirectoryHandleImpl::GetFile(const std::string& basename, ...@@ -111,7 +112,7 @@ void NativeFileSystemDirectoryHandleImpl::GetFile(const std::string& basename,
std::move(callback).Run( std::move(callback).Run(
native_file_system_error::FromStatus( native_file_system_error::FromStatus(
NativeFileSystemStatus::kPermissionDenied), NativeFileSystemStatus::kPermissionDenied),
nullptr); mojo::NullRemote());
}), }),
std::move(callback)); std::move(callback));
} else { } else {
...@@ -232,7 +233,7 @@ void NativeFileSystemDirectoryHandleImpl::DidGetFile( ...@@ -232,7 +233,7 @@ void NativeFileSystemDirectoryHandleImpl::DidGetFile(
if (result != base::File::FILE_OK) { if (result != base::File::FILE_OK) {
std::move(callback).Run(native_file_system_error::FromFileError(result), std::move(callback).Run(native_file_system_error::FromFileError(result),
nullptr); mojo::NullRemote());
return; return;
} }
...@@ -376,9 +377,7 @@ NativeFileSystemEntryPtr NativeFileSystemDirectoryHandleImpl::CreateEntry( ...@@ -376,9 +377,7 @@ NativeFileSystemEntryPtr NativeFileSystemDirectoryHandleImpl::CreateEntry(
} }
return NativeFileSystemEntry::New( return NativeFileSystemEntry::New(
NativeFileSystemHandle::NewFile( NativeFileSystemHandle::NewFile(
manager() manager()->CreateFileHandle(context(), url, handle_state())),
->CreateFileHandle(context(), url, handle_state())
.PassInterface()),
basename); basename);
} }
......
...@@ -272,7 +272,7 @@ NativeFileSystemManagerImpl::CreateWritableFileEntryFromPath( ...@@ -272,7 +272,7 @@ NativeFileSystemManagerImpl::CreateWritableFileEntryFromPath(
NativeFileSystemPermissionContext::UserAction::kSave); NativeFileSystemPermissionContext::UserAction::kSave);
} }
blink::mojom::NativeFileSystemFileHandlePtr mojo::PendingRemote<blink::mojom::NativeFileSystemFileHandle>
NativeFileSystemManagerImpl::CreateFileHandle( NativeFileSystemManagerImpl::CreateFileHandle(
const BindingContext& binding_context, const BindingContext& binding_context,
const storage::FileSystemURL& url, const storage::FileSystemURL& url,
...@@ -283,10 +283,10 @@ NativeFileSystemManagerImpl::CreateFileHandle( ...@@ -283,10 +283,10 @@ NativeFileSystemManagerImpl::CreateFileHandle(
handle_state.file_system.is_valid()) handle_state.file_system.is_valid())
<< url.mount_type(); << url.mount_type();
blink::mojom::NativeFileSystemFileHandlePtr result; mojo::PendingRemote<blink::mojom::NativeFileSystemFileHandle> result;
file_bindings_.AddBinding(std::make_unique<NativeFileSystemFileHandleImpl>( file_receivers_.Add(std::make_unique<NativeFileSystemFileHandleImpl>(
this, binding_context, url, handle_state), this, binding_context, url, handle_state),
mojo::MakeRequest(&result)); result.InitWithNewPipeAndPassReceiver());
return result; return result;
} }
...@@ -595,12 +595,10 @@ NativeFileSystemManagerImpl::CreateFileEntryFromPathImpl( ...@@ -595,12 +595,10 @@ NativeFileSystemManagerImpl::CreateFileEntryFromPathImpl(
} }
return blink::mojom::NativeFileSystemEntry::New( return blink::mojom::NativeFileSystemEntry::New(
blink::mojom::NativeFileSystemHandle::NewFile( blink::mojom::NativeFileSystemHandle::NewFile(CreateFileHandle(
CreateFileHandle( binding_context, url.url,
binding_context, url.url, SharedHandleState(std::move(read_grant), std::move(write_grant),
SharedHandleState(std::move(read_grant), std::move(write_grant), std::move(url.file_system)))),
std::move(url.file_system)))
.PassInterface()),
url.base_name); url.base_name);
} }
......
...@@ -122,10 +122,10 @@ class CONTENT_EXPORT NativeFileSystemManagerImpl ...@@ -122,10 +122,10 @@ class CONTENT_EXPORT NativeFileSystemManagerImpl
// Creates a new NativeFileSystemFileHandleImpl for a given url. Assumes the // Creates a new NativeFileSystemFileHandleImpl for a given url. Assumes the
// passed in URL is valid and represents a file. // passed in URL is valid and represents a file.
blink::mojom::NativeFileSystemFileHandlePtr CreateFileHandle( mojo::PendingRemote<blink::mojom::NativeFileSystemFileHandle>
const BindingContext& binding_context, CreateFileHandle(const BindingContext& binding_context,
const storage::FileSystemURL& url, const storage::FileSystemURL& url,
const SharedHandleState& handle_state); const SharedHandleState& handle_state);
// Creates a new NativeFileSystemDirectoryHandleImpl for a given url. Assumes // Creates a new NativeFileSystemDirectoryHandleImpl for a given url. Assumes
// the passed in URL is valid and represents a directory. // the passed in URL is valid and represents a directory.
...@@ -241,8 +241,8 @@ class CONTENT_EXPORT NativeFileSystemManagerImpl ...@@ -241,8 +241,8 @@ class CONTENT_EXPORT NativeFileSystemManagerImpl
// All the bindings and receivers for file and directory handles that have // All the bindings and receivers for file and directory handles that have
// references to them. // references to them.
mojo::StrongBindingSet<blink::mojom::NativeFileSystemFileHandle> mojo::UniqueReceiverSet<blink::mojom::NativeFileSystemFileHandle>
file_bindings_; file_receivers_;
mojo::StrongBindingSet<blink::mojom::NativeFileSystemDirectoryHandle> mojo::StrongBindingSet<blink::mojom::NativeFileSystemDirectoryHandle>
directory_bindings_; directory_bindings_;
mojo::UniqueReceiverSet<blink::mojom::NativeFileSystemFileWriter> mojo::UniqueReceiverSet<blink::mojom::NativeFileSystemFileWriter>
......
...@@ -126,7 +126,7 @@ TEST_F(NativeFileSystemManagerImplTest, CreateFileEntryFromPath_Permissions) { ...@@ -126,7 +126,7 @@ TEST_F(NativeFileSystemManagerImplTest, CreateFileEntryFromPath_Permissions) {
blink::mojom::NativeFileSystemEntryPtr entry = blink::mojom::NativeFileSystemEntryPtr entry =
manager_->CreateFileEntryFromPath(kBindingContext, kTestPath); manager_->CreateFileEntryFromPath(kBindingContext, kTestPath);
blink::mojom::NativeFileSystemFileHandlePtr handle( mojo::Remote<blink::mojom::NativeFileSystemFileHandle> handle(
std::move(entry->entry_handle->get_file())); std::move(entry->entry_handle->get_file()));
EXPECT_EQ(PermissionStatus::GRANTED, EXPECT_EQ(PermissionStatus::GRANTED,
...@@ -153,7 +153,7 @@ TEST_F(NativeFileSystemManagerImplTest, ...@@ -153,7 +153,7 @@ TEST_F(NativeFileSystemManagerImplTest,
blink::mojom::NativeFileSystemEntryPtr entry = blink::mojom::NativeFileSystemEntryPtr entry =
manager_->CreateWritableFileEntryFromPath(kBindingContext, kTestPath); manager_->CreateWritableFileEntryFromPath(kBindingContext, kTestPath);
blink::mojom::NativeFileSystemFileHandlePtr handle( mojo::Remote<blink::mojom::NativeFileSystemFileHandle> handle(
std::move(entry->entry_handle->get_file())); std::move(entry->entry_handle->get_file()));
EXPECT_EQ(PermissionStatus::GRANTED, EXPECT_EQ(PermissionStatus::GRANTED,
......
...@@ -12,7 +12,7 @@ import "third_party/blink/public/mojom/permissions/permission_status.mojom"; ...@@ -12,7 +12,7 @@ import "third_party/blink/public/mojom/permissions/permission_status.mojom";
// Union representing either a file or a directory handle. Used in APIs that // Union representing either a file or a directory handle. Used in APIs that
// can return arbitrary handles. // can return arbitrary handles.
union NativeFileSystemHandle { union NativeFileSystemHandle {
NativeFileSystemFileHandle file; pending_remote<NativeFileSystemFileHandle> file;
NativeFileSystemDirectoryHandle directory; NativeFileSystemDirectoryHandle directory;
}; };
...@@ -43,7 +43,7 @@ interface NativeFileSystemDirectoryHandle { ...@@ -43,7 +43,7 @@ interface NativeFileSystemDirectoryHandle {
// created. Returns an error if the operation fails, or a handle to the newly // created. Returns an error if the operation fails, or a handle to the newly
// created file if the operation succeeds. // created file if the operation succeeds.
GetFile(string basename, bool create) => GetFile(string basename, bool create) =>
(NativeFileSystemError result, NativeFileSystemFileHandle? file); (NativeFileSystemError result, pending_remote<NativeFileSystemFileHandle>? file);
// Returns a directory with the given |basename| that is a child of this // Returns a directory with the given |basename| that is a child of this
// directory. If no such directory exists, and |create| is true, the directory // directory. If no such directory exists, and |create| is true, the directory
......
...@@ -47,7 +47,8 @@ ScriptPromise NativeFileSystemDirectoryHandle::getFile( ...@@ -47,7 +47,8 @@ ScriptPromise NativeFileSystemDirectoryHandle::getFile(
WTF::Bind( WTF::Bind(
[](ScriptPromiseResolver* resolver, const String& name, [](ScriptPromiseResolver* resolver, const String& name,
NativeFileSystemErrorPtr result, NativeFileSystemErrorPtr result,
mojom::blink::NativeFileSystemFileHandlePtr handle) { mojo::PendingRemote<mojom::blink::NativeFileSystemFileHandle>
handle) {
ExecutionContext* context = resolver->GetExecutionContext(); ExecutionContext* context = resolver->GetExecutionContext();
if (!context) if (!context)
return; return;
...@@ -58,7 +59,7 @@ ScriptPromise NativeFileSystemDirectoryHandle::getFile( ...@@ -58,7 +59,7 @@ ScriptPromise NativeFileSystemDirectoryHandle::getFile(
resolver->Resolve(MakeGarbageCollected<NativeFileSystemFileHandle>( resolver->Resolve(MakeGarbageCollected<NativeFileSystemFileHandle>(
name, name,
RevocableInterfacePtr<mojom::blink::NativeFileSystemFileHandle>( RevocableInterfacePtr<mojom::blink::NativeFileSystemFileHandle>(
handle.PassInterface(), context->GetInterfaceInvalidator(), std::move(handle), context->GetInterfaceInvalidator(),
context->GetTaskRunner(TaskType::kMiscPlatformAPI)))); context->GetTaskRunner(TaskType::kMiscPlatformAPI))));
}, },
WrapPersistent(resolver), name)); WrapPersistent(resolver), name));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment