Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1326)

Unified Diff: content/browser/android/media_players_observer.cc

Issue 896673003: Propagate audible state from player to the containing tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: AudioStreamMonitor and corresponding Android monitor now have common base class Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/android/media_players_observer.cc
diff --git a/content/browser/android/media_players_observer.cc b/content/browser/android/media_players_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e8b06ce8fdc0b9e9a4eac2f0bb704939e84c8095
--- /dev/null
+++ b/content/browser/android/media_players_observer.cc
@@ -0,0 +1,55 @@
+// Copyright 2015 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.
+
+#include "content/browser/android/media_players_observer.h"
+
+#include <climits>
no sievers 2015/02/25 21:22:03 nit: space after line 7
Tima Vaisburd 2015/02/28 03:16:05 Done.
+#include "content/public/browser/web_contents.h"
+
+namespace content {
+
+MediaPlayersObserver::MediaPlayersObserver(WebContents* web_contents)
+ : AudioStateProvider(web_contents) {
+}
+
+MediaPlayersObserver::~MediaPlayersObserver() {}
+
+
+// This audio state provider does not have a monitor
+AudioStreamMonitor* MediaPlayersObserver::audio_stream_monitor() {
+ return nullptr;
+}
+
+void MediaPlayersObserver::OnAudibleStateChanged(RenderFrameHost* rfh,
+ int player_id,
+ bool is_audible) {
+ audio_status_map_[Key(rfh, player_id)] = is_audible;
+ UpdateStatusAndNotify();
+}
+
+void MediaPlayersObserver::RemovePlayer(RenderFrameHost* rfh, int player_id) {
+ audio_status_map_.erase(Key(rfh, player_id));
no sievers 2015/02/25 21:22:03 Should this DCHECK() that the return value is one,
Tima Vaisburd 2015/02/28 03:16:05 Done.
+ UpdateStatusAndNotify();
+}
+
+void MediaPlayersObserver::RenderFrameDeleted(RenderFrameHost* rfh) {
+ StatusMap::iterator begin = audio_status_map_.lower_bound(Key(rfh, 0));
+ StatusMap::iterator end = audio_status_map_.upper_bound(Key(rfh, INT_MAX));
+ audio_status_map_.erase(begin, end);
+ UpdateStatusAndNotify();
+}
+
+void MediaPlayersObserver::UpdateStatusAndNotify() {
+ bool is_audible = false;
+ for (const auto& player_status : audio_status_map_) {
+ if (player_status.second) {
+ is_audible = true;
+ break; // at least one player is making noise
+ }
+ }
+
+ Notify(is_audible);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698