Commit a3f2827e 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.

Bug: 1049056
Change-Id: I2a4e8323ce14e7f557ff2de93192a0061e879cab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2136570Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756594}
parent d7a01422
......@@ -73,7 +73,10 @@ class FileSystemDispatcher::ReadDirectoryListener
};
FileSystemDispatcher::FileSystemDispatcher(ExecutionContext& context)
: Supplement<ExecutionContext>(context), next_operation_id_(1) {}
: Supplement<ExecutionContext>(context),
file_system_manager_(&context),
next_operation_id_(1),
op_listeners_(&context) {}
// static
const char FileSystemDispatcher::kSupplementName[] = "FileSystemDispatcher";
......@@ -93,7 +96,7 @@ FileSystemDispatcher& FileSystemDispatcher::From(ExecutionContext* context) {
FileSystemDispatcher::~FileSystemDispatcher() = default;
mojom::blink::FileSystemManager& FileSystemDispatcher::GetFileSystemManager() {
if (!file_system_manager_) {
if (!file_system_manager_.is_bound()) {
// See https://bit.ly/2S0zRAS for task types
mojo::PendingReceiver<mojom::blink::FileSystemManager> receiver =
file_system_manager_.BindNewPipeAndPassReceiver(
......@@ -103,7 +106,7 @@ mojom::blink::FileSystemManager& FileSystemDispatcher::GetFileSystemManager() {
GetSupplementable()->GetBrowserInterfaceBroker().GetInterface(
std::move(receiver));
}
DCHECK(file_system_manager_);
DCHECK(file_system_manager_.is_bound());
return *file_system_manager_.get();
}
......@@ -443,6 +446,12 @@ void FileSystemDispatcher::CreateSnapshotFileSync(
std::move(listener));
}
void FileSystemDispatcher::Trace(Visitor* visitor) {
visitor->Trace(file_system_manager_);
visitor->Trace(op_listeners_);
Supplement<ExecutionContext>::Trace(visitor);
}
void FileSystemDispatcher::DidOpenFileSystem(
std::unique_ptr<FileSystemCallbacks> callbacks,
const String& name,
......
......@@ -8,11 +8,12 @@
#include <memory>
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/unique_receiver_set.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/handle.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_wrapper_mode.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace WTF {
......@@ -144,6 +145,8 @@ class FileSystemDispatcher : public GarbageCollected<FileSystemDispatcher>,
const KURL& file_path,
std::unique_ptr<SnapshotFileCallbackBase> callbacks);
void Trace(Visitor*) override;
private:
class WriteListener;
class ReadDirectoryListener;
......@@ -197,12 +200,17 @@ class FileSystemDispatcher : public GarbageCollected<FileSystemDispatcher>,
void Prefinalize();
mojo::Remote<mojom::blink::FileSystemManager> file_system_manager_;
HeapMojoRemote<mojom::blink::FileSystemManager,
HeapMojoWrapperMode::kWithoutContextObserver>
file_system_manager_;
using OperationsMap =
HashMap<int, mojo::Remote<mojom::blink::FileSystemCancellableOperation>>;
OperationsMap cancellable_operations_;
int next_operation_id_;
mojo::UniqueReceiverSet<mojom::blink::FileSystemOperationListener>
HeapMojoUniqueReceiverSet<
mojom::blink::FileSystemOperationListener,
std::default_delete<mojom::blink::FileSystemOperationListener>,
HeapMojoWrapperMode::kWithoutContextObserver>
op_listeners_;
};
......
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