forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: Kentaro Hara <haraken@chromium.org> Cr-Commit-Position: refs/heads/master@{#743049}
- Loading branch information
Keishi Hattori
authored and
Commit Bot
committed
Feb 20, 2020
1 parent
e0723ae
commit 9b056af
Showing
4 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
third_party/blink/renderer/platform/mojo/heap_mojo_receiver_set.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// 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_ |