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.
5 #include "content/browser/android/media_players_observer.h"
9 #include "base/logging.h"
10 #include "content/public/browser/web_contents.h"
14 MediaPlayersObserver::MediaPlayersObserver(WebContents
* web_contents
)
15 : AudioStateProvider(web_contents
) {
18 MediaPlayersObserver::~MediaPlayersObserver() {}
20 bool MediaPlayersObserver::IsAudioStateAvailable() const {
24 // This audio state provider does not have a monitor
25 AudioStreamMonitor
* MediaPlayersObserver::audio_stream_monitor() {
29 void MediaPlayersObserver::OnAudibleStateChanged(RenderFrameHost
* rfh
,
32 audio_status_map_
[Key(rfh
, player_id
)] = is_audible
;
33 UpdateStatusAndNotify();
36 void MediaPlayersObserver::RemovePlayer(RenderFrameHost
* rfh
, int player_id
) {
37 audio_status_map_
.erase(Key(rfh
, player_id
));
38 UpdateStatusAndNotify();
41 void MediaPlayersObserver::RenderFrameDeleted(RenderFrameHost
* rfh
) {
42 StatusMap::iterator begin
= audio_status_map_
.lower_bound(Key(rfh
, 0));
43 StatusMap::iterator end
= audio_status_map_
.upper_bound(Key(rfh
, INT_MAX
));
44 audio_status_map_
.erase(begin
, end
);
45 UpdateStatusAndNotify();
48 void MediaPlayersObserver::UpdateStatusAndNotify() {
49 for (const auto& player_status
: audio_status_map_
) {
50 if (player_status
.second
) {
51 Notify(true); // at least one player is making noise
59 } // namespace content