Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / android / media_players_observer.cc
blobc2771307571c51d7bc3946e7ec8e77646e4c6346
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"
7 #include <climits>
9 #include "base/logging.h"
10 #include "content/public/browser/web_contents.h"
12 namespace content {
14 MediaPlayersObserver::MediaPlayersObserver(WebContents* web_contents)
15 : AudioStateProvider(web_contents) {
18 MediaPlayersObserver::~MediaPlayersObserver() {}
20 bool MediaPlayersObserver::IsAudioStateAvailable() const {
21 return true;
24 // This audio state provider does not have a monitor
25 AudioStreamMonitor* MediaPlayersObserver::audio_stream_monitor() {
26 return nullptr;
29 void MediaPlayersObserver::OnAudibleStateChanged(RenderFrameHost* rfh,
30 int player_id,
31 bool is_audible) {
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
52 return;
56 Notify(false);
59 } // namespace content