[Chromecast] Use channel-associated MediaLoadDeferrer interface
This CL replaces uses of MediaLoadDeferrer interface with
channel-associated methods. This is used to avoid race conditions
in Chromecast builds because we want to make sure MediaLoad state
is updated before any media element is run.
BUG=internal b/74121154
TEST= media_load_deferrer interface connect correctly
Change-Id: Icc69e62f8fea0b13a2d79f0c52428b480d171823
Reviewed-on: https://chromium-review.googlesource.com/1070492
Commit-Queue: Jiawei Li <lijiawei@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Luke Halliwell <halliwell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562503}
diff --git a/chromecast/renderer/DEPS b/chromecast/renderer/DEPS
index 89ffb09..cb91a00 100644
--- a/chromecast/renderer/DEPS
+++ b/chromecast/renderer/DEPS
@@ -14,6 +14,5 @@
"+media/renderers",
"+mojo/public",
"+services/service_manager/public",
- "+third_party/blink/public/platform",
- "+third_party/blink/public/web",
+ "+third_party/blink/public",
]
diff --git a/chromecast/renderer/cast_media_load_deferrer.cc b/chromecast/renderer/cast_media_load_deferrer.cc
index ab688a6e..1da4a61 100644
--- a/chromecast/renderer/cast_media_load_deferrer.cc
+++ b/chromecast/renderer/cast_media_load_deferrer.cc
@@ -9,6 +9,9 @@
#include "base/callback.h"
#include "base/logging.h"
+#include "content/public/renderer/render_frame.h"
+#include "mojo/public/cpp/bindings/associated_binding_set.h"
+#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
namespace chromecast {
@@ -16,9 +19,10 @@
: content::RenderFrameObserver(render_frame),
content::RenderFrameObserverTracker<CastMediaLoadDeferrer>(render_frame),
render_frame_action_blocked_(false) {
- registry_.AddInterface(
- base::BindRepeating(&CastMediaLoadDeferrer::OnMediaLoadDeferrerRequest,
- base::Unretained(this)));
+ render_frame->GetAssociatedInterfaceRegistry()->AddInterface(
+ base::BindRepeating(
+ &CastMediaLoadDeferrer::OnMediaLoadDeferrerAssociatedRequest,
+ base::Unretained(this)));
}
CastMediaLoadDeferrer::~CastMediaLoadDeferrer() {
@@ -30,11 +34,6 @@
delete this;
}
-void CastMediaLoadDeferrer::OnInterfaceRequestForFrame(
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle* interface_pipe) {
- registry_.TryBindInterface(interface_name, interface_pipe);
-}
bool CastMediaLoadDeferrer::RunWhenInForeground(base::OnceClosure closure) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -66,8 +65,8 @@
LOG(INFO) << "Render frame actions are unblocked.";
}
-void CastMediaLoadDeferrer::OnMediaLoadDeferrerRequest(
- chromecast::shell::mojom::MediaLoadDeferrerRequest request) {
+void CastMediaLoadDeferrer::OnMediaLoadDeferrerAssociatedRequest(
+ chromecast::shell::mojom::MediaLoadDeferrerAssociatedRequest request) {
bindings_.AddBinding(this, std::move(request));
}
diff --git a/chromecast/renderer/cast_media_load_deferrer.h b/chromecast/renderer/cast_media_load_deferrer.h
index 9054244..2ef879d1 100644
--- a/chromecast/renderer/cast_media_load_deferrer.h
+++ b/chromecast/renderer/cast_media_load_deferrer.h
@@ -13,7 +13,7 @@
#include "chromecast/common/mojom/media_load_deferrer.mojom.h"
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_frame_observer_tracker.h"
-#include "mojo/public/cpp/bindings/binding_set.h"
+#include "mojo/public/cpp/bindings/associated_binding_set.h"
#include "services/service_manager/public/cpp/binder_registry.h"
namespace content {
@@ -31,7 +31,6 @@
public content::RenderFrameObserverTracker<CastMediaLoadDeferrer> {
public:
explicit CastMediaLoadDeferrer(content::RenderFrame* render_frame);
- ~CastMediaLoadDeferrer() override;
// Runs |closure| if the page/frame is switched to foreground. Returns true if
// the running of |closure| is deferred (not yet in foreground); false
@@ -39,24 +38,23 @@
bool RunWhenInForeground(base::OnceClosure closure);
private:
+ ~CastMediaLoadDeferrer() override;
+
// content::RenderFrameObserver implementation:
void OnDestruct() override;
- void OnInterfaceRequestForFrame(
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle* interface_pipe) override;
// MediaLoadDeferrer implementation
void UpdateMediaLoadStatus(bool blocked) override;
- void OnMediaLoadDeferrerRequest(
- chromecast::shell::mojom::MediaLoadDeferrerRequest request);
+ void OnMediaLoadDeferrerAssociatedRequest(
+ chromecast::shell::mojom::MediaLoadDeferrerAssociatedRequest request);
bool render_frame_action_blocked_;
+
std::vector<base::OnceClosure> pending_closures_;
- mojo::BindingSet<chromecast::shell::mojom::MediaLoadDeferrer> bindings_;
-
- service_manager::BinderRegistry registry_;
+ mojo::AssociatedBindingSet<chromecast::shell::mojom::MediaLoadDeferrer>
+ bindings_;
SEQUENCE_CHECKER(sequence_checker_);