WebMediaPlayer{Android,Impl}: use RenderFrameObserver instead of ML::DestructionObserver/RenderViewObserver.
RenderThreadImpl is torn down before the main thread's MessageLoop is, and some
of WebMediaPlayerAndroid's dependencies require the render thread to still be
alive, so move its tear-down to earlier in the process.
This is the Android version of r240125 which fixed the same bug in
WebMediaPlayerImpl, but forgot that WebMediaPlayerAndroid is a fork.
Since RenderViewObserver is apparently out of favor nowadays, use RenderFrameObserver.
BUG=338393,304967,338481
[Previously committed PS#3 as r248115 and rolled back in r248128]
[email protected], [email protected], [email protected], [email protected]
Review URL: https://codereview.chromium.org/137243005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248321 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index d86c3975..57f355c 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -476,7 +476,10 @@
IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
OnJavaBridgeGetChannelHandle)
#endif
- IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification,
+ OnMediaPlayingNotification)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification,
+ OnMediaPausedNotification)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
OnFirstVisuallyNonEmptyPaint)
IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
@@ -2402,36 +2405,36 @@
DidUpdateFaviconURL(page_id, candidates));
}
-void WebContentsImpl::OnMediaNotification(int64 player_cookie,
- bool has_video,
- bool has_audio,
- bool is_playing) {
+void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
+ bool has_video,
+ bool has_audio) {
+// Chrome OS does its own detection of audio and video.
+#if !defined(OS_CHROMEOS)
+ scoped_ptr<PowerSaveBlocker> blocker;
+ if (has_video) {
+ blocker = PowerSaveBlocker::Create(
+ PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
+#if defined(OS_ANDROID)
+ static_cast<PowerSaveBlockerImpl*>(blocker.get())
+ ->InitDisplaySleepBlocker(GetView()->GetNativeView());
+#endif
+ } else if (has_audio) {
+ blocker = PowerSaveBlocker::Create(
+ PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
+ }
+
+ if (blocker) {
+ power_save_blockers_[render_view_message_source_][player_cookie] =
+ blocker.release();
+ }
+#endif // !defined(OS_CHROMEOS)
+}
+
+void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
// Chrome OS does its own detection of audio and video.
#if !defined(OS_CHROMEOS)
- if (is_playing) {
- scoped_ptr<PowerSaveBlocker> blocker;
- if (has_video) {
- blocker = PowerSaveBlocker::Create(
- PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
- "Playing video");
-#if defined(OS_ANDROID)
- static_cast<PowerSaveBlockerImpl*>(blocker.get())->
- InitDisplaySleepBlocker(GetView()->GetNativeView());
-#endif
- } else if (has_audio) {
- blocker = PowerSaveBlocker::Create(
- PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
- "Playing audio");
- }
-
- if (blocker) {
- power_save_blockers_[render_view_message_source_][player_cookie] =
- blocker.release();
- }
- } else {
- delete power_save_blockers_[render_view_message_source_][player_cookie];
- power_save_blockers_[render_view_message_source_].erase(player_cookie);
- }
+ delete power_save_blockers_[render_view_message_source_][player_cookie];
+ power_save_blockers_[render_view_message_source_].erase(player_cookie);
#endif // !defined(OS_CHROMEOS)
}