| 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) |
| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 for (auto& observer : observers_) | 194 for (auto& observer : observers_) |
| 190 observer.PowerButtonEventReceived(down, timestamp); | 195 observer.PowerButtonEventReceived(down, timestamp); |
| 191 } | 196 } |
| 192 | 197 |
| 193 void FakePowerManagerClient::UpdatePowerProperties( | 198 void FakePowerManagerClient::UpdatePowerProperties( |
| 194 const power_manager::PowerSupplyProperties& power_props) { | 199 const power_manager::PowerSupplyProperties& power_props) { |
| 195 props_ = power_props; | 200 props_ = power_props; |
| 196 NotifyObservers(); | 201 NotifyObservers(); |
| 197 } | 202 } |
| 198 | 203 |
| 204 void FakePowerManagerClient::SendBrightnessChanged(int level, |
| 205 bool user_initiated) { |
| 206 for (auto& observer : observers_) |
| 207 observer.BrightnessChanged(level, user_initiated); |
| 208 } |
| 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 |