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 ...@@ -73,7 +73,10 @@ class FileSystemDispatcher::ReadDirectoryListener
}; };
FileSystemDispatcher::FileSystemDispatcher(ExecutionContext& context) 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 // static
const char FileSystemDispatcher::kSupplementName[] = "FileSystemDispatcher"; const char FileSystemDispatcher::kSupplementName[] = "FileSystemDispatcher";
...@@ -93,7 +96,7 @@ FileSystemDispatcher& FileSystemDispatcher::From(ExecutionContext* context) { ...@@ -93,7 +96,7 @@ FileSystemDispatcher& FileSystemDispatcher::From(ExecutionContext* context) {
FileSystemDispatcher::~FileSystemDispatcher() = default; FileSystemDispatcher::~FileSystemDispatcher() = default;
mojom::blink::FileSystemManager& FileSystemDispatcher::GetFileSystemManager() { mojom::blink::FileSystemManager& FileSystemDispatcher::GetFileSystemManager() {
if (!file_system_manager_) { if (!file_system_manager_.is_bound()) {
// See https://bit.ly/2S0zRAS for task types // See https://bit.ly/2S0zRAS for task types
mojo::PendingReceiver<mojom::blink::FileSystemManager> receiver = mojo::PendingReceiver<mojom::blink::FileSystemManager> receiver =
file_system_manager_.BindNewPipeAndPassReceiver( file_system_manager_.BindNewPipeAndPassReceiver(
...@@ -103,7 +106,7 @@ mojom::blink::FileSystemManager& FileSystemDispatcher::GetFileSystemManager() { ...@@ -103,7 +106,7 @@ mojom::blink::FileSystemManager& FileSystemDispatcher::GetFileSystemManager() {
GetSupplementable()->GetBrowserInterfaceBroker().GetInterface( GetSupplementable()->GetBrowserInterfaceBroker().GetInterface(
std::move(receiver)); std::move(receiver));
} }
DCHECK(file_system_manager_); DCHECK(file_system_manager_.is_bound());
return *file_system_manager_.get(); return *file_system_manager_.get();
} }
...@@ -443,6 +446,12 @@ void FileSystemDispatcher::CreateSnapshotFileSync( ...@@ -443,6 +446,12 @@ void FileSystemDispatcher::CreateSnapshotFileSync(
std::move(listener)); std::move(listener));
} }
void FileSystemDispatcher::Trace(Visitor* visitor) {
visitor->Trace(file_system_manager_);
visitor->Trace(op_listeners_);
Supplement<ExecutionContext>::Trace(visitor);
}
void FileSystemDispatcher::DidOpenFileSystem( void FileSystemDispatcher::DidOpenFileSystem(
std::unique_ptr<FileSystemCallbacks> callbacks, std::unique_ptr<FileSystemCallbacks> callbacks,
const String& name, const String& name,
......
...@@ -8,11 +8,12 @@ ...@@ -8,11 +8,12 @@
#include <memory> #include <memory>
#include "mojo/public/cpp/bindings/pending_remote.h" #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/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/handle.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" #include "third_party/blink/renderer/platform/supplementable.h"
namespace WTF { namespace WTF {
...@@ -144,6 +145,8 @@ class FileSystemDispatcher : public GarbageCollected<FileSystemDispatcher>, ...@@ -144,6 +145,8 @@ class FileSystemDispatcher : public GarbageCollected<FileSystemDispatcher>,
const KURL& file_path, const KURL& file_path,
std::unique_ptr<SnapshotFileCallbackBase> callbacks); std::unique_ptr<SnapshotFileCallbackBase> callbacks);
void Trace(Visitor*) override;
private: private:
class WriteListener; class WriteListener;
class ReadDirectoryListener; class ReadDirectoryListener;
...@@ -197,12 +200,17 @@ class FileSystemDispatcher : public GarbageCollected<FileSystemDispatcher>, ...@@ -197,12 +200,17 @@ class FileSystemDispatcher : public GarbageCollected<FileSystemDispatcher>,
void Prefinalize(); void Prefinalize();
mojo::Remote<mojom::blink::FileSystemManager> file_system_manager_; HeapMojoRemote<mojom::blink::FileSystemManager,
HeapMojoWrapperMode::kWithoutContextObserver>
file_system_manager_;
using OperationsMap = using OperationsMap =
HashMap<int, mojo::Remote<mojom::blink::FileSystemCancellableOperation>>; HashMap<int, mojo::Remote<mojom::blink::FileSystemCancellableOperation>>;
OperationsMap cancellable_operations_; OperationsMap cancellable_operations_;
int next_operation_id_; int next_operation_id_;
mojo::UniqueReceiverSet<mojom::blink::FileSystemOperationListener> HeapMojoUniqueReceiverSet<
mojom::blink::FileSystemOperationListener,
std::default_delete<mojom::blink::FileSystemOperationListener>,
HeapMojoWrapperMode::kWithoutContextObserver>
op_listeners_; 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