OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chromeos/dbus/fake_power_manager_client.h" | 5 #include "chromeos/dbus/fake_power_manager_client.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 "base/location.h" | 9 #include "base/location.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 | 12 |
13 namespace chromeos { | 13 namespace chromeos { |
14 | 14 |
15 namespace { | 15 namespace { |
16 // Minimum power for a USB power source to be classified as AC. | 16 // Minimum power for a USB power source to be classified as AC. |
17 const double kUsbMinAcWatts = 24; | 17 constexpr double kUsbMinAcWatts = 24; |
18 | |
19 // A non-zero brightness used for test. | |
20 constexpr int kNonZeroBrightnessForTest = 10; | |
18 } | 21 } |
19 | 22 |
20 FakePowerManagerClient::FakePowerManagerClient() | 23 FakePowerManagerClient::FakePowerManagerClient() |
21 : num_request_restart_calls_(0), | 24 : num_request_restart_calls_(0), |
22 num_request_shutdown_calls_(0), | 25 num_request_shutdown_calls_(0), |
23 num_set_policy_calls_(0), | 26 num_set_policy_calls_(0), |
24 num_set_is_projecting_calls_(0), | 27 num_set_is_projecting_calls_(0), |
25 num_pending_suspend_readiness_callbacks_(0), | 28 num_pending_suspend_readiness_callbacks_(0), |
26 is_projecting_(false), | 29 is_projecting_(false), |
27 backlights_forced_off_(false), | 30 backlights_forced_off_(false), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 : power_manager::PowerSupplyProperties_ExternalPower_AC); | 133 : power_manager::PowerSupplyProperties_ExternalPower_AC); |
131 break; | 134 break; |
132 } | 135 } |
133 } | 136 } |
134 | 137 |
135 NotifyObservers(); | 138 NotifyObservers(); |
136 } | 139 } |
137 | 140 |
138 void FakePowerManagerClient::SetBacklightsForcedOff(bool forced_off) { | 141 void FakePowerManagerClient::SetBacklightsForcedOff(bool forced_off) { |
139 backlights_forced_off_ = forced_off; | 142 backlights_forced_off_ = forced_off; |
143 forced_off ? SendBrightnessChanged(0, true) | |
Daniel Erat
2016/11/10 22:48:55
please don't call SendBrightnessChanged from here;
Qiang(Joe) Xu
2016/11/11 04:39:23
done by moving to tests.
| |
144 : SendBrightnessChanged(kNonZeroBrightnessForTest, true); | |
140 } | 145 } |
141 | 146 |
142 void FakePowerManagerClient::GetBacklightsForcedOff( | 147 void FakePowerManagerClient::GetBacklightsForcedOff( |
143 const GetBacklightsForcedOffCallback& callback) { | 148 const GetBacklightsForcedOffCallback& callback) { |
144 base::ThreadTaskRunnerHandle::Get()->PostTask( | 149 base::ThreadTaskRunnerHandle::Get()->PostTask( |
145 FROM_HERE, base::Bind(callback, backlights_forced_off_)); | 150 FROM_HERE, base::Bind(callback, backlights_forced_off_)); |
146 } | 151 } |
147 | 152 |
148 base::Closure FakePowerManagerClient::GetSuspendReadinessCallback() { | 153 base::Closure FakePowerManagerClient::GetSuspendReadinessCallback() { |
149 ++num_pending_suspend_readiness_callbacks_; | 154 ++num_pending_suspend_readiness_callbacks_; |
(...skipping 26 matching lines...) Expand all Loading... | |
176 | 181 |
177 for (auto& observer : observers_) | 182 for (auto& observer : observers_) |
178 observer.SuspendDone(base::TimeDelta()); | 183 observer.SuspendDone(base::TimeDelta()); |
179 } | 184 } |
180 | 185 |
181 void FakePowerManagerClient::SendDarkSuspendImminent() { | 186 void FakePowerManagerClient::SendDarkSuspendImminent() { |
182 for (auto& observer : observers_) | 187 for (auto& observer : observers_) |
183 observer.DarkSuspendImminent(); | 188 observer.DarkSuspendImminent(); |
184 } | 189 } |
185 | 190 |
191 void FakePowerManagerClient::SendBrightnessChanged(int level, | |
192 bool user_initiated) { | |
193 for (auto& observer : observers_) | |
194 observer.BrightnessChanged(level, user_initiated); | |
195 } | |
196 | |
186 void FakePowerManagerClient::SendPowerButtonEvent( | 197 void FakePowerManagerClient::SendPowerButtonEvent( |
187 bool down, | 198 bool down, |
188 const base::TimeTicks& timestamp) { | 199 const base::TimeTicks& timestamp) { |
189 for (auto& observer : observers_) | 200 for (auto& observer : observers_) |
190 observer.PowerButtonEventReceived(down, timestamp); | 201 observer.PowerButtonEventReceived(down, timestamp); |
191 } | 202 } |
192 | 203 |
193 void FakePowerManagerClient::UpdatePowerProperties( | 204 void FakePowerManagerClient::UpdatePowerProperties( |
194 const power_manager::PowerSupplyProperties& power_props) { | 205 const power_manager::PowerSupplyProperties& power_props) { |
195 props_ = power_props; | 206 props_ = power_props; |
196 NotifyObservers(); | 207 NotifyObservers(); |
197 } | 208 } |
198 | 209 |
199 void FakePowerManagerClient::NotifyObservers() { | 210 void FakePowerManagerClient::NotifyObservers() { |
200 for (auto& observer : observers_) | 211 for (auto& observer : observers_) |
201 observer.PowerChanged(props_); | 212 observer.PowerChanged(props_); |
202 } | 213 } |
203 | 214 |
204 void FakePowerManagerClient::HandleSuspendReadiness() { | 215 void FakePowerManagerClient::HandleSuspendReadiness() { |
205 CHECK(num_pending_suspend_readiness_callbacks_ > 0); | 216 CHECK(num_pending_suspend_readiness_callbacks_ > 0); |
206 | 217 |
207 --num_pending_suspend_readiness_callbacks_; | 218 --num_pending_suspend_readiness_callbacks_; |
208 } | 219 } |
209 | 220 |
210 } // namespace chromeos | 221 } // namespace chromeos |
OLD | NEW |