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..a9ff36fd6085263bf06aede110c1a8f2fdd52159 |
| --- /dev/null |
| +++ b/content/browser/android/audio_monitor_android.cc |
| @@ -0,0 +1,58 @@ |
| +// 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/03 20:33:24
"," is normally in the previous line
Tima Vaisburd
2015/02/03 23:53:04
Done.
|
| +} |
| + |
| +AudioMonitorAndroid::~AudioMonitorAndroid() { |
| +} |
|
qinmin
2015/02/03 20:33:24
you can move "}" to previous line
Tima Vaisburd
2015/02/03 23:53:04
Done.
|
| + |
| +bool AudioMonitorAndroid::IsAudible() const { |
| + return is_audible_; |
| +} |
| + |
| +void AudioMonitorAndroid::OnAudibleStateChanged(RenderFrameHost* rfh, |
| + int player_id, |
| + bool is_audible) { |
| + players_[Key(rfh, player_id)] = is_audible; |
| + UpdateStatusAndNotify(); |
| +} |
| + |
| +void AudioMonitorAndroid::RemovePlayer(RenderFrameHost* rfh, int player_id) { |
| + players_.erase(Key(rfh, player_id)); |
| + UpdateStatusAndNotify(); |
| +} |
| + |
| +void AudioMonitorAndroid::RenderFrameDeleted(RenderFrameHost* rfh) { |
| + StatusMap::iterator begin = players_.lower_bound(Key(rfh, 0)); |
| + StatusMap::iterator end = players_.upper_bound(Key(rfh, INT_MAX)); |
| + players_.erase(begin, end); |
| + UpdateStatusAndNotify(); |
| +} |
| + |
| +void AudioMonitorAndroid::UpdateStatusAndNotify() { |
| + int is_audible = false; |
| + for (const auto& player : players_) { |
| + if (player.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 |