Chromium Code Reviews| Index: content/browser/android/audio_monitor_android.cc |
| diff --git a/content/browser/android/audio_monitor_android.cc b/content/browser/android/audio_monitor_android.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5f33da431377e38c10bf7497a1f0be0e9c3169ac |
| --- /dev/null |
| +++ b/content/browser/android/audio_monitor_android.cc |
| @@ -0,0 +1,53 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/android/audio_monitor_android.h" |
| + |
| +#include <climits> |
| +#include "content/public/browser/web_contents.h" |
| + |
| +namespace content { |
| + |
| +AudioMonitorAndroid::AudioMonitorAndroid(WebContents* web_contents) |
| + : web_contents_(web_contents), |
| + is_audible_(false) { |
|
qinmin
2015/02/04 03:27:54
nit: align this with web_contents_ above
Tima Vaisburd
2015/02/05 23:22:26
Done.
|
| +} |
| + |
| +AudioMonitorAndroid::~AudioMonitorAndroid() {} |
| + |
| +void AudioMonitorAndroid::OnAudibleStateChanged(RenderFrameHost* rfh, |
| + int player_id, |
| + bool is_audible) { |
| + audio_status_map_[Key(rfh, player_id)] = is_audible; |
| + UpdateStatusAndNotify(); |
| +} |
| + |
| +void AudioMonitorAndroid::RemovePlayer(RenderFrameHost* rfh, int player_id) { |
| + audio_status_map_.erase(Key(rfh, player_id)); |
| + UpdateStatusAndNotify(); |
| +} |
| + |
| +void AudioMonitorAndroid::RenderFrameDeleted(RenderFrameHost* rfh) { |
| + StatusMap::iterator begin = audio_status_map_.lower_bound(Key(rfh, 0)); |
| + StatusMap::iterator end = audio_status_map_.upper_bound(Key(rfh, INT_MAX)); |
| + audio_status_map_.erase(begin, end); |
| + UpdateStatusAndNotify(); |
| +} |
| + |
| +void AudioMonitorAndroid::UpdateStatusAndNotify() { |
| + int is_audible = false; |
|
qinmin
2015/02/04 03:27:54
bool?
Tima Vaisburd
2015/02/05 23:22:26
Done.
|
| + for (const auto& player_status : audio_status_map_) { |
| + if (player_status.second) { |
| + is_audible = true; |
| + break; // at least one player is making noise |
| + } |
| + } |
| + |
| + if (is_audible_ != is_audible) { |
| + is_audible_ = is_audible; |
| + web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| + } |
| +} |
| + |
| +} // namespace content |