Commit 3a2cf168 authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Chromium LUCI CQ

Cleanup mojo Receivers for media::mojom::MediaPlayer on disconnection

Since there might be more than one mojo Remote for this mojo interface
in the browser process at a given time (e.g. one for the regular media
session and another one for a PiP session), it would be good to make
sure we don't unnecessarily end up with unbound receivers in the set
owned by HTMLMediaElement when only one of those remotes are removed.

Thus, this CL adds the extra plumbing required in HeapMojoReceiverSet
to allow setting disconnect_handlers on the wrapped mojo::ReceiverSet
and uses it to make sure that unbound remotes on the browser process
for the media::mojom::MediaPlayer interface result in the associated
mojo receiver being removed in the renderer process.

Bug: 1039252
Change-Id: I7140345658d1b5c30b5aee437285b55251452390
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2595047Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Cr-Commit-Position: refs/heads/master@{#838000}
parent 3b83cf41
......@@ -4116,9 +4116,15 @@ bool HTMLMediaElement::IsInteractiveContent() const {
void HTMLMediaElement::BindMediaPlayerReceiver(
mojo::PendingReceiver<media::mojom::blink::MediaPlayer> receiver) {
media_player_receiver_set_.Add(
mojo::ReceiverId receiver_id = media_player_receiver_set_.Add(
std::move(receiver),
GetDocument().GetTaskRunner(TaskType::kInternalMedia));
media_player_receiver_set_.set_disconnect_handler(WTF::BindRepeating(
[](HTMLMediaElement* html_media_element, mojo::ReceiverId receiver_id) {
html_media_element->media_player_receiver_set_.Remove(receiver_id);
},
WrapWeakPersistent(this), receiver_id));
}
void HTMLMediaElement::Trace(Visitor* visitor) const {
......
......@@ -44,6 +44,16 @@ class HeapMojoReceiverSet {
HeapMojoReceiverSet& operator=(const HeapMojoReceiverSet&) = delete;
// Methods to redirect to mojo::ReceiverSet:
void set_disconnect_handler(base::RepeatingClosure handler) {
wrapper_->receiver_set().set_disconnect_handler(std::move(handler));
}
void set_disconnect_with_reason_handler(
mojo::RepeatingConnectionErrorWithReasonCallback handler) {
wrapper_->receiver_set().set_disconnect_with_reason_handler(
std::move(handler));
}
mojo::ReceiverId Add(mojo::PendingReceiver<Interface> receiver,
scoped_refptr<base::SequencedTaskRunner> task_runner) {
DCHECK(task_runner);
......
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