OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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) { | |
qinmin
2015/02/03 20:33:24
"," is normally in the previous line
Tima Vaisburd
2015/02/03 23:53:04
Done.
| |
15 } | |
16 | |
17 AudioMonitorAndroid::~AudioMonitorAndroid() { | |
18 } | |
qinmin
2015/02/03 20:33:24
you can move "}" to previous line
Tima Vaisburd
2015/02/03 23:53:04
Done.
| |
19 | |
20 bool AudioMonitorAndroid::IsAudible() const { | |
21 return is_audible_; | |
22 } | |
23 | |
24 void AudioMonitorAndroid::OnAudibleStateChanged(RenderFrameHost* rfh, | |
25 int player_id, | |
26 bool is_audible) { | |
27 players_[Key(rfh, player_id)] = is_audible; | |
28 UpdateStatusAndNotify(); | |
29 } | |
30 | |
31 void AudioMonitorAndroid::RemovePlayer(RenderFrameHost* rfh, int player_id) { | |
32 players_.erase(Key(rfh, player_id)); | |
33 UpdateStatusAndNotify(); | |
34 } | |
35 | |
36 void AudioMonitorAndroid::RenderFrameDeleted(RenderFrameHost* rfh) { | |
37 StatusMap::iterator begin = players_.lower_bound(Key(rfh, 0)); | |
38 StatusMap::iterator end = players_.upper_bound(Key(rfh, INT_MAX)); | |
39 players_.erase(begin, end); | |
40 UpdateStatusAndNotify(); | |
41 } | |
42 | |
43 void AudioMonitorAndroid::UpdateStatusAndNotify() { | |
44 int is_audible = false; | |
45 for (const auto& player : players_) { | |
46 if (player.second) { | |
47 is_audible = true; | |
48 break; // at least one player is making noise | |
49 } | |
50 } | |
51 | |
52 if (is_audible_ != is_audible) { | |
53 is_audible_ = is_audible; | |
54 web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); | |
55 } | |
56 } | |
57 | |
58 } // namespace content | |
OLD | NEW |