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

Side by Side 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: Addressed Ted's comments and compiled IsAudible() only under OS_ANDROID 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/android/audio_monitor_android.h"
6
7 #include <climits>
8 #include "content/public/browser/web_contents.h"
9
10 namespace content {
11
12 AudioMonitorAndroid::AudioMonitorAndroid(WebContents* web_contents)
13 : web_contents_(web_contents),
14 is_audible_(false) {
15 }
16
17 AudioMonitorAndroid::~AudioMonitorAndroid() {}
18
19 void AudioMonitorAndroid::OnAudibleStateChanged(RenderFrameHost* rfh,
20 int player_id,
21 bool is_audible) {
22 audio_status_map_[Key(rfh, player_id)] = is_audible;
23 UpdateStatusAndNotify();
24 }
25
26 void AudioMonitorAndroid::RemovePlayer(RenderFrameHost* rfh, int player_id) {
27 audio_status_map_.erase(Key(rfh, player_id));
28 UpdateStatusAndNotify();
29 }
30
31 void AudioMonitorAndroid::RenderFrameDeleted(RenderFrameHost* rfh) {
32 StatusMap::iterator begin = audio_status_map_.lower_bound(Key(rfh, 0));
33 StatusMap::iterator end = audio_status_map_.upper_bound(Key(rfh, INT_MAX));
34 audio_status_map_.erase(begin, end);
35 UpdateStatusAndNotify();
36 }
37
38 void AudioMonitorAndroid::UpdateStatusAndNotify() {
39 bool is_audible = false;
40 for (const auto& player_status : audio_status_map_) {
no sievers 2015/02/10 01:33:03 Does this really need a separate class for the imp
Tima Vaisburd 2015/02/11 03:34:05 It does not require a separate class, strictly spe
no sievers 2015/02/12 19:01:11 If you are arguing that way: Maybe we should make
41 if (player_status.second) {
42 is_audible = true;
43 break; // at least one player is making noise
44 }
45 }
46
47 if (is_audible_ != is_audible) {
48 is_audible_ = is_audible;
49 web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
50 }
51 }
52
53 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698