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,
blink::mojom::NativeFileSystemErrorPtr get_child_url_result =
GetChildURL(basename, &child_url);
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;
}
if (GetReadPermissionStatus() != PermissionStatus::GRANTED) {
std::move(callback).Run(native_file_system_error::FromStatus(
NativeFileSystemStatus::kPermissionDenied),
nullptr);
mojo::NullRemote());
return;
}
......@@ -111,7 +112,7 @@ void NativeFileSystemDirectoryHandleImpl::GetFile(const std::string& basename,
std::move(callback).Run(
native_file_system_error::FromStatus(
NativeFileSystemStatus::kPermissionDenied),
nullptr);
mojo::NullRemote());
}),
std::move(callback));
} else {
......@@ -232,7 +233,7 @@ void NativeFileSystemDirectoryHandleImpl::DidGetFile(
if (result != base::File::FILE_OK) {
std::move(callback).Run(native_file_system_error::FromFileError(result),
nullptr);
mojo::NullRemote());
return;
}
......@@ -376,9 +377,7 @@ NativeFileSystemEntryPtr NativeFileSystemDirectoryHandleImpl::CreateEntry(
}
return NativeFileSystemEntry::New(
NativeFileSystemHandle::NewFile(
manager()
->CreateFileHandle(context(), url, handle_state())
.PassInterface()),
manager()->CreateFileHandle(context(), url, handle_state())),
basename);
}
......
......@@ -272,7 +272,7 @@ NativeFileSystemManagerImpl::CreateWritableFileEntryFromPath(
NativeFileSystemPermissionContext::UserAction::kSave);
}
blink::mojom::NativeFileSystemFileHandlePtr
mojo::PendingRemote<blink::mojom::NativeFileSystemFileHandle>
NativeFileSystemManagerImpl::CreateFileHandle(
const BindingContext& binding_context,
const storage::FileSystemURL& url,
......@@ -283,10 +283,10 @@ NativeFileSystemManagerImpl::CreateFileHandle(
handle_state.file_system.is_valid())
<< url.mount_type();
blink::mojom::NativeFileSystemFileHandlePtr result;
file_bindings_.AddBinding(std::make_unique<NativeFileSystemFileHandleImpl>(
this, binding_context, url, handle_state),
mojo::MakeRequest(&result));
mojo::PendingRemote<blink::mojom::NativeFileSystemFileHandle> result;
file_receivers_.Add(std::make_unique<NativeFileSystemFileHandleImpl>(
this, binding_context, url, handle_state),
result.InitWithNewPipeAndPassReceiver());
return result;
}
......@@ -595,12 +595,10 @@ NativeFileSystemManagerImpl::CreateFileEntryFromPathImpl(
}
return blink::mojom::NativeFileSystemEntry::New(
blink::mojom::NativeFileSystemHandle::NewFile(
CreateFileHandle(
binding_context, url.url,
SharedHandleState(std::move(read_grant), std::move(write_grant),
std::move(url.file_system)))
.PassInterface()),
blink::mojom::NativeFileSystemHandle::NewFile(CreateFileHandle(
binding_context, url.url,
SharedHandleState(std::move(read_grant), std::move(write_grant),
std::move(url.file_system)))),
url.base_name);
}
......
......@@ -122,10 +122,10 @@ class CONTENT_EXPORT NativeFileSystemManagerImpl
// Creates a new NativeFileSystemFileHandleImpl for a given url. Assumes the
// passed in URL is valid and represents a file.
blink::mojom::NativeFileSystemFileHandlePtr CreateFileHandle(
const BindingContext& binding_context,
const storage::FileSystemURL& url,
const SharedHandleState& handle_state);
mojo::PendingRemote<blink::mojom::NativeFileSystemFileHandle>
CreateFileHandle(const BindingContext& binding_context,
const storage::FileSystemURL& url,
const SharedHandleState& handle_state);
// Creates a new NativeFileSystemDirectoryHandleImpl for a given url. Assumes
// the passed in URL is valid and represents a directory.
......@@ -241,8 +241,8 @@ class CONTENT_EXPORT NativeFileSystemManagerImpl
// All the bindings and receivers for file and directory handles that have
// references to them.
mojo::StrongBindingSet<blink::mojom::NativeFileSystemFileHandle>
file_bindings_;
mojo::UniqueReceiverSet<blink::mojom::NativeFileSystemFileHandle>
file_receivers_;
mojo::StrongBindingSet<blink::mojom::NativeFileSystemDirectoryHandle>
directory_bindings_;
mojo::UniqueReceiverSet<blink::mojom::NativeFileSystemFileWriter>
......
......@@ -126,7 +126,7 @@ TEST_F(NativeFileSystemManagerImplTest, CreateFileEntryFromPath_Permissions) {
blink::mojom::NativeFileSystemEntryPtr entry =
manager_->CreateFileEntryFromPath(kBindingContext, kTestPath);
blink::mojom::NativeFileSystemFileHandlePtr handle(
mojo::Remote<blink::mojom::NativeFileSystemFileHandle> handle(
std::move(entry->entry_handle->get_file()));
EXPECT_EQ(PermissionStatus::GRANTED,
......@@ -153,7 +153,7 @@ TEST_F(NativeFileSystemManagerImplTest,
blink::mojom::NativeFileSystemEntryPtr entry =
manager_->CreateWritableFileEntryFromPath(kBindingContext, kTestPath);
blink::mojom::NativeFileSystemFileHandlePtr handle(
mojo::Remote<blink::mojom::NativeFileSystemFileHandle> handle(
std::move(entry->entry_handle->get_file()));
EXPECT_EQ(PermissionStatus::GRANTED,
......
......@@ -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
// can return arbitrary handles.
union NativeFileSystemHandle {
NativeFileSystemFileHandle file;
pending_remote<NativeFileSystemFileHandle> file;
NativeFileSystemDirectoryHandle directory;
};
......@@ -43,7 +43,7 @@ interface NativeFileSystemDirectoryHandle {
// created. Returns an error if the operation fails, or a handle to the newly
// created file if the operation succeeds.
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
// directory. If no such directory exists, and |create| is true, the directory
......
......@@ -47,7 +47,8 @@ ScriptPromise NativeFileSystemDirectoryHandle::getFile(
WTF::Bind(
[](ScriptPromiseResolver* resolver, const String& name,
NativeFileSystemErrorPtr result,
mojom::blink::NativeFileSystemFileHandlePtr handle) {
mojo::PendingRemote<mojom::blink::NativeFileSystemFileHandle>
handle) {
ExecutionContext* context = resolver->GetExecutionContext();
if (!context)
return;
......@@ -58,7 +59,7 @@ ScriptPromise NativeFileSystemDirectoryHandle::getFile(
resolver->Resolve(MakeGarbageCollected<NativeFileSystemFileHandle>(
name,
RevocableInterfacePtr<mojom::blink::NativeFileSystemFileHandle>(
handle.PassInterface(), context->GetInterfaceInvalidator(),
std::move(handle), context->GetInterfaceInvalidator(),
context->GetTaskRunner(TaskType::kMiscPlatformAPI))));
},
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