OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/media/audio_stream_monitor.h" | 5 #include "content/browser/media/audio_stream_monitor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 if (power_dbfs >= kSilenceThresholdDBFS) { | 145 if (power_dbfs >= kSilenceThresholdDBFS) { |
146 last_blurt_time_ = clock_->NowTicks(); | 146 last_blurt_time_ = clock_->NowTicks(); |
147 is_audible_ = true; | 147 is_audible_ = true; |
148 MaybeToggle(); | 148 MaybeToggle(); |
149 break; // No need to poll remaining streams. | 149 break; // No need to poll remaining streams. |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 if (is_audible_ != was_audible) | 153 if (is_audible_ != was_audible) |
154 web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); | 154 web_contents_->OnAudioStateChanged(is_audible_); |
155 } | 155 } |
156 | 156 |
157 void AudioStreamMonitor::MaybeToggle() { | 157 void AudioStreamMonitor::MaybeToggle() { |
158 const bool indicator_was_on = was_recently_audible_; | 158 const bool indicator_was_on = was_recently_audible_; |
159 const base::TimeTicks off_time = | 159 const base::TimeTicks off_time = |
160 last_blurt_time_ + base::TimeDelta::FromMilliseconds(kHoldOnMilliseconds); | 160 last_blurt_time_ + base::TimeDelta::FromMilliseconds(kHoldOnMilliseconds); |
161 const base::TimeTicks now = clock_->NowTicks(); | 161 const base::TimeTicks now = clock_->NowTicks(); |
162 const bool should_indicator_be_on = now < off_time; | 162 const bool should_indicator_be_on = now < off_time; |
163 | 163 |
164 if (should_indicator_be_on != indicator_was_on) { | 164 if (should_indicator_be_on != indicator_was_on) { |
165 was_recently_audible_ = should_indicator_be_on; | 165 was_recently_audible_ = should_indicator_be_on; |
166 web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); | 166 web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
167 } | 167 } |
168 | 168 |
169 if (!should_indicator_be_on) { | 169 if (!should_indicator_be_on) { |
170 off_timer_.Stop(); | 170 off_timer_.Stop(); |
171 } else if (!off_timer_.IsRunning()) { | 171 } else if (!off_timer_.IsRunning()) { |
172 off_timer_.Start( | 172 off_timer_.Start( |
173 FROM_HERE, | 173 FROM_HERE, |
174 off_time - now, | 174 off_time - now, |
175 base::Bind(&AudioStreamMonitor::MaybeToggle, base::Unretained(this))); | 175 base::Bind(&AudioStreamMonitor::MaybeToggle, base::Unretained(this))); |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 } // namespace content | 179 } // namespace content |
OLD | NEW |