| 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 const double kUsbMinAcWatts = 24; |
| 18 } | 18 } |
| 19 | 19 |
| 20 FakePowerManagerClient::FakePowerManagerClient() | 20 FakePowerManagerClient::FakePowerManagerClient() |
| 21 : num_request_restart_calls_(0), | 21 : num_request_restart_calls_(0), |
| 22 num_request_shutdown_calls_(0), | 22 num_request_shutdown_calls_(0), |
| 23 num_set_policy_calls_(0), | 23 num_set_policy_calls_(0), |
| 24 num_set_is_projecting_calls_(0), | 24 num_set_is_projecting_calls_(0), |
| 25 num_pending_suspend_readiness_callbacks_(0), | 25 num_pending_suspend_readiness_callbacks_(0), |
| 26 is_projecting_(false), | 26 is_projecting_(false), |
| 27 backlights_forced_off_(false), |
| 27 weak_ptr_factory_(this) { | 28 weak_ptr_factory_(this) { |
| 28 } | 29 } |
| 29 | 30 |
| 30 FakePowerManagerClient::~FakePowerManagerClient() { | 31 FakePowerManagerClient::~FakePowerManagerClient() { |
| 31 } | 32 } |
| 32 | 33 |
| 33 void FakePowerManagerClient::Init(dbus::Bus* bus) { | 34 void FakePowerManagerClient::Init(dbus::Bus* bus) { |
| 34 props_.set_battery_percent(50); | 35 props_.set_battery_percent(50); |
| 35 props_.set_is_calculating_battery_time(false); | 36 props_.set_is_calculating_battery_time(false); |
| 36 props_.set_battery_state( | 37 props_.set_battery_state( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 !source.active_by_default() || source.max_power() < kUsbMinAcWatts | 128 !source.active_by_default() || source.max_power() < kUsbMinAcWatts |
| 128 ? power_manager::PowerSupplyProperties_ExternalPower_USB | 129 ? power_manager::PowerSupplyProperties_ExternalPower_USB |
| 129 : power_manager::PowerSupplyProperties_ExternalPower_AC); | 130 : power_manager::PowerSupplyProperties_ExternalPower_AC); |
| 130 break; | 131 break; |
| 131 } | 132 } |
| 132 } | 133 } |
| 133 | 134 |
| 134 NotifyObservers(); | 135 NotifyObservers(); |
| 135 } | 136 } |
| 136 | 137 |
| 138 void FakePowerManagerClient::SetBacklightsForcedOff(bool forced_off) { |
| 139 backlights_forced_off_ = forced_off; |
| 140 } |
| 141 |
| 142 void FakePowerManagerClient::GetBacklightsForcedOff( |
| 143 const GetBacklightsForcedOffCallback& callback) { |
| 144 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 145 FROM_HERE, base::Bind(callback, backlights_forced_off_)); |
| 146 } |
| 147 |
| 137 base::Closure FakePowerManagerClient::GetSuspendReadinessCallback() { | 148 base::Closure FakePowerManagerClient::GetSuspendReadinessCallback() { |
| 138 ++num_pending_suspend_readiness_callbacks_; | 149 ++num_pending_suspend_readiness_callbacks_; |
| 139 | 150 |
| 140 return base::Bind(&FakePowerManagerClient::HandleSuspendReadiness, | 151 return base::Bind(&FakePowerManagerClient::HandleSuspendReadiness, |
| 141 base::Unretained(this)); | 152 base::Unretained(this)); |
| 142 } | 153 } |
| 143 | 154 |
| 144 int FakePowerManagerClient::GetNumPendingSuspendReadinessCallbacks() { | 155 int FakePowerManagerClient::GetNumPendingSuspendReadinessCallbacks() { |
| 145 return num_pending_suspend_readiness_callbacks_; | 156 return num_pending_suspend_readiness_callbacks_; |
| 146 } | 157 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(props_)); | 197 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(props_)); |
| 187 } | 198 } |
| 188 | 199 |
| 189 void FakePowerManagerClient::HandleSuspendReadiness() { | 200 void FakePowerManagerClient::HandleSuspendReadiness() { |
| 190 CHECK(num_pending_suspend_readiness_callbacks_ > 0); | 201 CHECK(num_pending_suspend_readiness_callbacks_ > 0); |
| 191 | 202 |
| 192 --num_pending_suspend_readiness_callbacks_; | 203 --num_pending_suspend_readiness_callbacks_; |
| 193 } | 204 } |
| 194 | 205 |
| 195 } // namespace chromeos | 206 } // namespace chromeos |
| OLD | NEW |