Commit 9b056aff authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

Introduce HeapMojoReceiverSet and use it for ManifestManager

Introduces HeapMojoReceiverSet which is a wrapper around mojo::ReceiverSet.
And uses it for ManifestManager.

Bug: 1052319
Change-Id: I683567f0352c9b60811263a662bda85e31299426
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2063615
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743049}
parent e0723ae5
...@@ -52,7 +52,8 @@ ManifestManager::ManifestManager(LocalFrame& frame) ...@@ -52,7 +52,8 @@ ManifestManager::ManifestManager(LocalFrame& frame)
: Supplement<LocalFrame>(frame), : Supplement<LocalFrame>(frame),
ExecutionContextLifecycleObserver(frame.GetDocument()), ExecutionContextLifecycleObserver(frame.GetDocument()),
may_have_manifest_(false), may_have_manifest_(false),
manifest_dirty_(true) { manifest_dirty_(true),
receivers_(GetExecutionContext()) {
if (frame.IsMainFrame()) { if (frame.IsMainFrame()) {
manifest_change_notifier_ = manifest_change_notifier_ =
MakeGarbageCollected<ManifestChangeNotifier>(frame); MakeGarbageCollected<ManifestChangeNotifier>(frame);
...@@ -256,7 +257,10 @@ bool ManifestManager::ManifestUseCredentials() const { ...@@ -256,7 +257,10 @@ bool ManifestManager::ManifestUseCredentials() const {
void ManifestManager::BindReceiver( void ManifestManager::BindReceiver(
mojo::PendingReceiver<mojom::blink::ManifestManager> receiver) { mojo::PendingReceiver<mojom::blink::ManifestManager> receiver) {
receivers_.Add(this, std::move(receiver)); receivers_.Add(
this, std::move(receiver),
GetSupplementable()->GetDocument()->ToExecutionContext()->GetTaskRunner(
TaskType::kNetworking));
} }
void ManifestManager::ContextDestroyed() { void ManifestManager::ContextDestroyed() {
...@@ -267,17 +271,12 @@ void ManifestManager::ContextDestroyed() { ...@@ -267,17 +271,12 @@ void ManifestManager::ContextDestroyed() {
// will be aware of the RenderFrame dying and should act on that. Consumers // will be aware of the RenderFrame dying and should act on that. Consumers
// in the renderer process should be correctly notified. // in the renderer process should be correctly notified.
ResolveCallbacks(ResolveStateFailure); ResolveCallbacks(ResolveStateFailure);
receivers_.Clear();
}
void ManifestManager::Prefinalize() {
receivers_.Clear();
} }
void ManifestManager::Trace(Visitor* visitor) { void ManifestManager::Trace(Visitor* visitor) {
visitor->Trace(fetcher_); visitor->Trace(fetcher_);
visitor->Trace(manifest_change_notifier_); visitor->Trace(manifest_change_notifier_);
visitor->Trace(receivers_);
Supplement<LocalFrame>::Trace(visitor); Supplement<LocalFrame>::Trace(visitor);
ExecutionContextLifecycleObserver::Trace(visitor); ExecutionContextLifecycleObserver::Trace(visitor);
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/member.h" #include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_receiver_set.h"
#include "third_party/blink/renderer/platform/supplementable.h" #include "third_party/blink/renderer/platform/supplementable.h"
namespace blink { namespace blink {
...@@ -36,7 +37,6 @@ class MODULES_EXPORT ManifestManager ...@@ -36,7 +37,6 @@ class MODULES_EXPORT ManifestManager
public mojom::blink::ManifestManager, public mojom::blink::ManifestManager,
public ExecutionContextLifecycleObserver { public ExecutionContextLifecycleObserver {
USING_GARBAGE_COLLECTED_MIXIN(ManifestManager); USING_GARBAGE_COLLECTED_MIXIN(ManifestManager);
USING_PRE_FINALIZER(ManifestManager, Prefinalize);
public: public:
static const char kSupplementName[]; static const char kSupplementName[];
...@@ -86,8 +86,6 @@ class MODULES_EXPORT ManifestManager ...@@ -86,8 +86,6 @@ class MODULES_EXPORT ManifestManager
void BindReceiver( void BindReceiver(
mojo::PendingReceiver<mojom::blink::ManifestManager> receiver); mojo::PendingReceiver<mojom::blink::ManifestManager> receiver);
void Prefinalize();
friend class ManifestManagerTest; friend class ManifestManagerTest;
Member<ManifestFetcher> fetcher_; Member<ManifestFetcher> fetcher_;
...@@ -113,7 +111,7 @@ class MODULES_EXPORT ManifestManager ...@@ -113,7 +111,7 @@ class MODULES_EXPORT ManifestManager
Vector<InternalRequestManifestCallback> pending_callbacks_; Vector<InternalRequestManifestCallback> pending_callbacks_;
mojo::ReceiverSet<mojom::blink::ManifestManager> receivers_; HeapMojoReceiverSet<mojom::blink::ManifestManager> receivers_;
DISALLOW_COPY_AND_ASSIGN(ManifestManager); DISALLOW_COPY_AND_ASSIGN(ManifestManager);
}; };
......
...@@ -1225,6 +1225,8 @@ jumbo_component("platform") { ...@@ -1225,6 +1225,8 @@ jumbo_component("platform") {
"mojo/fetch_api_request_headers_mojom_traits.h", "mojo/fetch_api_request_headers_mojom_traits.h",
"mojo/heap_mojo_receiver.h", "mojo/heap_mojo_receiver.h",
"mojo/heap_mojo_receiver.h", "mojo/heap_mojo_receiver.h",
"mojo/heap_mojo_receiver_set.h",
"mojo/heap_mojo_receiver_set.h",
"mojo/heap_mojo_remote.h", "mojo/heap_mojo_remote.h",
"mojo/heap_mojo_remote.h", "mojo/heap_mojo_remote.h",
"mojo/kurl_mojom_traits.h", "mojo/kurl_mojom_traits.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_HEAP_MOJO_RECEIVER_SET_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_HEAP_MOJO_RECEIVER_SET_H_
#include "mojo/public/cpp/bindings/receiver.h"
#include "third_party/blink/renderer/platform/context_lifecycle_observer.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
namespace blink {
// HeapMojoReceiverSet is a wrapper for mojo::ReceiverSet to be owned by a
// garbage-collected object. Blink is expected to use HeapMojoReceiverSet by
// default. HeapMojoReceiverSet must be associated with context.
// HeapMojoReceiverSet's constructor takes context as a mandatory parameter.
// HeapMojoReceiverSet resets the mojo connection when 1) the owner object is
// garbage-collected or 2) the associated ExecutionContext is detached.
template <typename Interface>
class HeapMojoReceiverSet {
DISALLOW_NEW();
public:
using ImplPointerType = typename mojo::Receiver<Interface>::ImplPointerType;
explicit HeapMojoReceiverSet(ContextLifecycleNotifier* context)
: wrapper_(MakeGarbageCollected<Wrapper>(context)) {}
// Methods to redirect to mojo::ReceiverSet:
mojo::ReceiverId Add(ImplPointerType impl,
mojo::PendingReceiver<Interface> receiver,
scoped_refptr<base::SequencedTaskRunner> task_runner) {
return wrapper_->receiver_set().Add(std::move(impl), std::move(receiver));
}
void Clear() { wrapper_->receiver_set().Clear(); }
void Trace(Visitor* visitor) { visitor->Trace(wrapper_); }
private:
// Garbage collected wrapper class to add a prefinalizer.
class Wrapper final : public GarbageCollected<Wrapper>,
public ContextLifecycleObserver {
USING_PRE_FINALIZER(Wrapper, Dispose);
USING_GARBAGE_COLLECTED_MIXIN(Wrapper);
public:
explicit Wrapper(ContextLifecycleNotifier* notifier) {
SetContextLifecycleNotifier(notifier);
}
void Trace(Visitor* visitor) override {
ContextLifecycleObserver::Trace(visitor);
}
void Dispose() { receiver_set_.Clear(); }
mojo::ReceiverSet<Interface>& receiver_set() { return receiver_set_; }
// ContextLifecycleObserver methods
void ContextDestroyed() override { receiver_set_.Clear(); }
private:
mojo::ReceiverSet<Interface> receiver_set_;
};
Member<Wrapper> wrapper_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_HEAP_MOJO_RECEIVER_SET_H_
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