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 "chrome/browser/media/audio_stream_monitor.h" | 5 #include "chrome/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/public/browser/invalidate_type.h" | 9 #include "content/public/browser/invalidate_type.h" |
10 #include "content/public/browser/power_save_blocker.h" | |
10 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
11 | 12 |
12 DEFINE_WEB_CONTENTS_USER_DATA_KEY(AudioStreamMonitor); | 13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(AudioStreamMonitor); |
13 | 14 |
14 AudioStreamMonitor::AudioStreamMonitor(content::WebContents* contents) | 15 AudioStreamMonitor::AudioStreamMonitor(content::WebContents* contents) |
15 : web_contents_(contents), | 16 : web_contents_(contents), |
16 clock_(&default_tick_clock_), | 17 clock_(&default_tick_clock_), |
17 was_recently_audible_(false) { | 18 was_recently_audible_(false) { |
18 DCHECK(web_contents_); | 19 DCHECK(web_contents_); |
19 } | 20 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 const base::TimeTicks now = clock_->NowTicks(); | 71 const base::TimeTicks now = clock_->NowTicks(); |
71 const bool should_indicator_be_on = now < off_time; | 72 const bool should_indicator_be_on = now < off_time; |
72 | 73 |
73 if (should_indicator_be_on != indicator_was_on) { | 74 if (should_indicator_be_on != indicator_was_on) { |
74 was_recently_audible_ = should_indicator_be_on; | 75 was_recently_audible_ = should_indicator_be_on; |
75 web_contents_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 76 web_contents_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
76 } | 77 } |
77 | 78 |
78 if (!should_indicator_be_on) { | 79 if (!should_indicator_be_on) { |
79 off_timer_.Stop(); | 80 off_timer_.Stop(); |
81 blocker_.reset(); | |
80 } else if (!off_timer_.IsRunning()) { | 82 } else if (!off_timer_.IsRunning()) { |
83 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | |
miu
2014/08/25 19:34:52
Hmm...I'm wondering whether this is the right plac
DaleCurtis
2014/08/28 00:55:19
I also wonder about this, as now the code lives ac
miu
2014/08/28 04:11:58
My opinion: Either ASM needs to move into content,
DaleCurtis
2014/08/28 18:51:43
I think we should, the ASM stuff is pretty awesome
| |
84 if (!blocker_) { | |
85 blocker_ = content::PowerSaveBlocker::Create( | |
86 content::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | |
miu
2014/08/25 19:34:52
You meant "AppSuspension" and not "DisplaySleep" r
DaleCurtis
2014/08/28 00:55:19
Acknowledged.
| |
87 "Playing Audio"); | |
88 } | |
89 #endif | |
81 off_timer_.Start( | 90 off_timer_.Start( |
82 FROM_HERE, | 91 FROM_HERE, |
83 off_time - now, | 92 off_time - now, |
84 base::Bind(&AudioStreamMonitor::MaybeToggle, base::Unretained(this))); | 93 base::Bind(&AudioStreamMonitor::MaybeToggle, base::Unretained(this))); |
85 } | 94 } |
86 } | 95 } |
OLD | NEW |