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,
int64_t offset,
int* request_id_out,
StatusCallback callback) {
mojo::Remote<mojom::blink::FileSystemCancellableOperation> op_remote;
HeapMojoRemote<mojom::blink::FileSystemCancellableOperation> op_remote(
GetSupplementable());
// See https://bit.ly/2S0zRAS for task types
mojo::PendingReceiver<mojom::blink::FileSystemCancellableOperation>
op_receiver = op_remote.BindNewPipeAndPassReceiver(
......@@ -341,7 +342,8 @@ void FileSystemDispatcher::Truncate(const KURL& path,
op_remote.set_disconnect_handler(
WTF::Bind(&FileSystemDispatcher::RemoveOperationRemote,
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(
path, offset, std::move(op_receiver),
WTF::Bind(&FileSystemDispatcher::DidTruncate, WrapWeakPersistent(this),
......@@ -365,7 +367,8 @@ void FileSystemDispatcher::Write(const KURL& path,
int* request_id_out,
const WriteCallback& success_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
scoped_refptr<base::SequencedTaskRunner> task_runner =
GetSupplementable()->GetTaskRunner(blink::TaskType::kMiscPlatformAPI);
......@@ -375,7 +378,8 @@ void FileSystemDispatcher::Write(const KURL& path,
op_remote.set_disconnect_handler(
WTF::Bind(&FileSystemDispatcher::RemoveOperationRemote,
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::PendingReceiver<mojom::blink::FileSystemOperationListener> receiver =
......@@ -419,9 +423,10 @@ void FileSystemDispatcher::Cancel(int request_id_to_cancel,
return;
}
cancellable_operations_.find(request_id_to_cancel)
->value->Cancel(WTF::Bind(&FileSystemDispatcher::DidCancel,
WrapWeakPersistent(this), std::move(callback),
request_id_to_cancel));
->value->Value()
->Cancel(WTF::Bind(&FileSystemDispatcher::DidCancel,
WrapWeakPersistent(this), std::move(callback),
request_id_to_cancel));
}
void FileSystemDispatcher::CreateSnapshotFile(
......@@ -448,6 +453,7 @@ void FileSystemDispatcher::CreateSnapshotFileSync(
void FileSystemDispatcher::Trace(Visitor* visitor) const {
visitor->Trace(file_system_manager_);
visitor->Trace(cancellable_operations_);
visitor->Trace(op_listeners_);
Supplement<ExecutionContext>::Trace(visitor);
}
......
......@@ -10,7 +10,9 @@
#include "mojo/public/cpp/bindings/pending_remote.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/platform/heap/disallow_new_wrapper.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_unique_receiver_set.h"
#include "third_party/blink/renderer/platform/supplementable.h"
......@@ -201,7 +203,9 @@ class FileSystemDispatcher : public GarbageCollected<FileSystemDispatcher>,
HeapMojoRemote<mojom::blink::FileSystemManager> file_system_manager_;
using OperationsMap =
HashMap<int, mojo::Remote<mojom::blink::FileSystemCancellableOperation>>;
HeapHashMap<int,
Member<DisallowNewWrapper<HeapMojoRemote<
mojom::blink::FileSystemCancellableOperation>>>>;
OperationsMap cancellable_operations_;
int next_operation_id_;
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