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

Unified Diff: content/browser/android/audio_monitor_android.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: Created 5 years, 11 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/audio_monitor_android.cc
diff --git a/content/browser/android/audio_monitor_android.cc b/content/browser/android/audio_monitor_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a9ff36fd6085263bf06aede110c1a8f2fdd52159
--- /dev/null
+++ b/content/browser/android/audio_monitor_android.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 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/audio_monitor_android.h"
+
+#include <climits>
+#include "content/public/browser/web_contents.h"
+
+namespace content {
+
+AudioMonitorAndroid::AudioMonitorAndroid(WebContents* web_contents)
+ : web_contents_(web_contents)
+ , is_audible_(false) {
qinmin 2015/02/03 20:33:24 "," is normally in the previous line
Tima Vaisburd 2015/02/03 23:53:04 Done.
+}
+
+AudioMonitorAndroid::~AudioMonitorAndroid() {
+}
qinmin 2015/02/03 20:33:24 you can move "}" to previous line
Tima Vaisburd 2015/02/03 23:53:04 Done.
+
+bool AudioMonitorAndroid::IsAudible() const {
+ return is_audible_;
+}
+
+void AudioMonitorAndroid::OnAudibleStateChanged(RenderFrameHost* rfh,
+ int player_id,
+ bool is_audible) {
+ players_[Key(rfh, player_id)] = is_audible;
+ UpdateStatusAndNotify();
+}
+
+void AudioMonitorAndroid::RemovePlayer(RenderFrameHost* rfh, int player_id) {
+ players_.erase(Key(rfh, player_id));
+ UpdateStatusAndNotify();
+}
+
+void AudioMonitorAndroid::RenderFrameDeleted(RenderFrameHost* rfh) {
+ StatusMap::iterator begin = players_.lower_bound(Key(rfh, 0));
+ StatusMap::iterator end = players_.upper_bound(Key(rfh, INT_MAX));
+ players_.erase(begin, end);
+ UpdateStatusAndNotify();
+}
+
+void AudioMonitorAndroid::UpdateStatusAndNotify() {
+ int is_audible = false;
+ for (const auto& player : players_) {
+ if (player.second) {
+ is_audible = true;
+ break; // at least one player is making noise
+ }
+ }
+
+ if (is_audible_ != is_audible) {
+ is_audible_ = is_audible;
+ web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
+ }
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698