Commit 8d6554d3 authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Commit Bot

Migrate FileSystemDispatcher to use GC mojo wrappers.

No behavior change. This CL reduces potential risks of use-after-free
bugs. This CL is followup CL. FileSystemDispatcher was already
migrated before, but there were remaining mojo objects.

Bug: 1049056
Change-Id: Ib9933ee186ecca6d5cc73bf70a6d9a5ee429c010
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2211564Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771232}
parent c4387721
...@@ -331,7 +331,8 @@ void FileSystemDispatcher::Truncate(const KURL& path, ...@@ -331,7 +331,8 @@ void FileSystemDispatcher::Truncate(const KURL& path,
int64_t offset, int64_t offset,
int* request_id_out, int* request_id_out,
StatusCallback callback) { StatusCallback callback) {
mojo::Remote<mojom::blink::FileSystemCancellableOperation> op_remote; HeapMojoRemote<mojom::blink::FileSystemCancellableOperation> op_remote(
GetSupplementable());
// See https://bit.ly/2S0zRAS for task types // See https://bit.ly/2S0zRAS for task types
mojo::PendingReceiver<mojom::blink::FileSystemCancellableOperation> mojo::PendingReceiver<mojom::blink::FileSystemCancellableOperation>
op_receiver = op_remote.BindNewPipeAndPassReceiver( op_receiver = op_remote.BindNewPipeAndPassReceiver(
...@@ -341,7 +342,8 @@ void FileSystemDispatcher::Truncate(const KURL& path, ...@@ -341,7 +342,8 @@ void FileSystemDispatcher::Truncate(const KURL& path,
op_remote.set_disconnect_handler( op_remote.set_disconnect_handler(
WTF::Bind(&FileSystemDispatcher::RemoveOperationRemote, WTF::Bind(&FileSystemDispatcher::RemoveOperationRemote,
WrapWeakPersistent(this), operation_id)); WrapWeakPersistent(this), operation_id));
cancellable_operations_.insert(operation_id, std::move(op_remote)); cancellable_operations_.insert(operation_id,
WrapDisallowNew(std::move(op_remote)));
GetFileSystemManager().Truncate( GetFileSystemManager().Truncate(
path, offset, std::move(op_receiver), path, offset, std::move(op_receiver),
WTF::Bind(&FileSystemDispatcher::DidTruncate, WrapWeakPersistent(this), WTF::Bind(&FileSystemDispatcher::DidTruncate, WrapWeakPersistent(this),
...@@ -365,7 +367,8 @@ void FileSystemDispatcher::Write(const KURL& path, ...@@ -365,7 +367,8 @@ void FileSystemDispatcher::Write(const KURL& path,
int* request_id_out, int* request_id_out,
const WriteCallback& success_callback, const WriteCallback& success_callback,
StatusCallback error_callback) { StatusCallback error_callback) {
mojo::Remote<mojom::blink::FileSystemCancellableOperation> op_remote; HeapMojoRemote<mojom::blink::FileSystemCancellableOperation> op_remote(
GetSupplementable());
// See https://bit.ly/2S0zRAS for task types // See https://bit.ly/2S0zRAS for task types
scoped_refptr<base::SequencedTaskRunner> task_runner = scoped_refptr<base::SequencedTaskRunner> task_runner =
GetSupplementable()->GetTaskRunner(blink::TaskType::kMiscPlatformAPI); GetSupplementable()->GetTaskRunner(blink::TaskType::kMiscPlatformAPI);
...@@ -375,7 +378,8 @@ void FileSystemDispatcher::Write(const KURL& path, ...@@ -375,7 +378,8 @@ void FileSystemDispatcher::Write(const KURL& path,
op_remote.set_disconnect_handler( op_remote.set_disconnect_handler(
WTF::Bind(&FileSystemDispatcher::RemoveOperationRemote, WTF::Bind(&FileSystemDispatcher::RemoveOperationRemote,
WrapWeakPersistent(this), operation_id)); WrapWeakPersistent(this), operation_id));
cancellable_operations_.insert(operation_id, std::move(op_remote)); cancellable_operations_.insert(operation_id,
WrapDisallowNew(std::move(op_remote)));
mojo::PendingRemote<mojom::blink::FileSystemOperationListener> listener; mojo::PendingRemote<mojom::blink::FileSystemOperationListener> listener;
mojo::PendingReceiver<mojom::blink::FileSystemOperationListener> receiver = mojo::PendingReceiver<mojom::blink::FileSystemOperationListener> receiver =
...@@ -419,7 +423,8 @@ void FileSystemDispatcher::Cancel(int request_id_to_cancel, ...@@ -419,7 +423,8 @@ void FileSystemDispatcher::Cancel(int request_id_to_cancel,
return; return;
} }
cancellable_operations_.find(request_id_to_cancel) cancellable_operations_.find(request_id_to_cancel)
->value->Cancel(WTF::Bind(&FileSystemDispatcher::DidCancel, ->value->Value()
->Cancel(WTF::Bind(&FileSystemDispatcher::DidCancel,
WrapWeakPersistent(this), std::move(callback), WrapWeakPersistent(this), std::move(callback),
request_id_to_cancel)); request_id_to_cancel));
} }
...@@ -448,6 +453,7 @@ void FileSystemDispatcher::CreateSnapshotFileSync( ...@@ -448,6 +453,7 @@ void FileSystemDispatcher::CreateSnapshotFileSync(
void FileSystemDispatcher::Trace(Visitor* visitor) const { void FileSystemDispatcher::Trace(Visitor* visitor) const {
visitor->Trace(file_system_manager_); visitor->Trace(file_system_manager_);
visitor->Trace(cancellable_operations_);
visitor->Trace(op_listeners_); visitor->Trace(op_listeners_);
Supplement<ExecutionContext>::Trace(visitor); Supplement<ExecutionContext>::Trace(visitor);
} }
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/mojom/filesystem/file_system.mojom-blink.h" #include "third_party/blink/public/mojom/filesystem/file_system.mojom-blink.h"
#include "third_party/blink/renderer/modules/filesystem/file_system_callbacks.h" #include "third_party/blink/renderer/modules/filesystem/file_system_callbacks.h"
#include "third_party/blink/renderer/platform/heap/disallow_new_wrapper.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h" #include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_unique_receiver_set.h" #include "third_party/blink/renderer/platform/mojo/heap_mojo_unique_receiver_set.h"
#include "third_party/blink/renderer/platform/supplementable.h" #include "third_party/blink/renderer/platform/supplementable.h"
...@@ -201,7 +203,9 @@ class FileSystemDispatcher : public GarbageCollected<FileSystemDispatcher>, ...@@ -201,7 +203,9 @@ class FileSystemDispatcher : public GarbageCollected<FileSystemDispatcher>,
HeapMojoRemote<mojom::blink::FileSystemManager> file_system_manager_; HeapMojoRemote<mojom::blink::FileSystemManager> file_system_manager_;
using OperationsMap = using OperationsMap =
HashMap<int, mojo::Remote<mojom::blink::FileSystemCancellableOperation>>; HeapHashMap<int,
Member<DisallowNewWrapper<HeapMojoRemote<
mojom::blink::FileSystemCancellableOperation>>>>;
OperationsMap cancellable_operations_; OperationsMap cancellable_operations_;
int next_operation_id_; int next_operation_id_;
HeapMojoUniqueReceiverSet<mojom::blink::FileSystemOperationListener> HeapMojoUniqueReceiverSet<mojom::blink::FileSystemOperationListener>
......
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