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

Side by Side 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 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/media_players_observer.h"
6
7 #include <climits>
no sievers 2015/02/25 21:22:03 nit: space after line 7
Tima Vaisburd 2015/02/28 03:16:05 Done.
8 #include "content/public/browser/web_contents.h"
9
10 namespace content {
11
12 MediaPlayersObserver::MediaPlayersObserver(WebContents* web_contents)
13 : AudioStateProvider(web_contents) {
14 }
15
16 MediaPlayersObserver::~MediaPlayersObserver() {}
17
18
19 // This audio state provider does not have a monitor
20 AudioStreamMonitor* MediaPlayersObserver::audio_stream_monitor() {
21 return nullptr;
22 }
23
24 void MediaPlayersObserver::OnAudibleStateChanged(RenderFrameHost* rfh,
25 int player_id,
26 bool is_audible) {
27 audio_status_map_[Key(rfh, player_id)] = is_audible;
28 UpdateStatusAndNotify();
29 }
30
31 void MediaPlayersObserver::RemovePlayer(RenderFrameHost* rfh, int player_id) {
32 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.
33 UpdateStatusAndNotify();
34 }
35
36 void MediaPlayersObserver::RenderFrameDeleted(RenderFrameHost* rfh) {
37 StatusMap::iterator begin = audio_status_map_.lower_bound(Key(rfh, 0));
38 StatusMap::iterator end = audio_status_map_.upper_bound(Key(rfh, INT_MAX));
39 audio_status_map_.erase(begin, end);
40 UpdateStatusAndNotify();
41 }
42
43 void MediaPlayersObserver::UpdateStatusAndNotify() {
44 bool is_audible = false;
45 for (const auto& player_status : audio_status_map_) {
46 if (player_status.second) {
47 is_audible = true;
48 break; // at least one player is making noise
49 }
50 }
51
52 Notify(is_audible);
53 }
54
55 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698