Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: chromeos/dbus/fake_power_manager_client.cc

Issue 1206733002: ChromeOs Power Emulation Impl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated everying!!! Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
10 #include "base/thread_task_runner_handle.h"
9 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "components/device_event_log/device_event_log.h"
10 13
11 namespace chromeos { 14 namespace chromeos {
12 15
13 FakePowerManagerClient::FakePowerManagerClient() 16 FakePowerManagerClient::FakePowerManagerClient()
14 : num_request_restart_calls_(0), 17 : num_request_restart_calls_(0),
15 num_request_shutdown_calls_(0), 18 num_request_shutdown_calls_(0),
16 num_set_policy_calls_(0), 19 num_set_policy_calls_(0),
17 num_set_is_projecting_calls_(0), 20 num_set_is_projecting_calls_(0),
18 num_pending_suspend_readiness_callbacks_(0), 21 num_pending_suspend_readiness_callbacks_(0),
19 is_projecting_(false) { 22 is_projecting_(false),
23 weak_ptr_factory_(this) {
20 } 24 }
21 25
22 FakePowerManagerClient::~FakePowerManagerClient() { 26 FakePowerManagerClient::~FakePowerManagerClient() {
23 } 27 }
24 28
25 void FakePowerManagerClient::Init(dbus::Bus* bus) { 29 void FakePowerManagerClient::Init(dbus::Bus* bus) {
30 props_.set_battery_percent(50);
31 props_.set_is_calculating_battery_time(false);
32 props_.set_battery_state(
33 power_manager::PowerSupplyProperties_BatteryState_DISCHARGING);
34 props_.set_external_power(
35 power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED);
36 props_.set_battery_time_to_full_sec(0);
37 props_.set_battery_time_to_empty_sec(18000);
38 NotifyObservers();
oshima 2015/07/15 21:46:23 question to derat@. What is the expected behavior
Daniel Erat 2015/07/15 22:02:39 powerd emits the status when requested, and also a
mozartalouis 2015/07/15 22:10:30 Should we just remove it since chrome doesn't get
Daniel Erat 2015/07/15 22:18:50 yeah, it'd be best to match the real class's behav
mozartalouis 2015/07/15 22:29:20 Done.
26 } 39 }
27 40
28 void FakePowerManagerClient::AddObserver(Observer* observer) { 41 void FakePowerManagerClient::AddObserver(Observer* observer) {
29 observers_.AddObserver(observer); 42 observers_.AddObserver(observer);
30 } 43 }
31 44
32 void FakePowerManagerClient::RemoveObserver(Observer* observer) { 45 void FakePowerManagerClient::RemoveObserver(Observer* observer) {
33 observers_.RemoveObserver(observer); 46 observers_.RemoveObserver(observer);
34 } 47 }
35 48
36 bool FakePowerManagerClient::HasObserver(const Observer* observer) const { 49 bool FakePowerManagerClient::HasObserver(const Observer* observer) const {
37 return false; 50 return observers_.HasObserver(observer);
38 } 51 }
39 52
40 void FakePowerManagerClient::SetRenderProcessManagerDelegate( 53 void FakePowerManagerClient::SetRenderProcessManagerDelegate(
41 base::WeakPtr<RenderProcessManagerDelegate> delegate) { 54 base::WeakPtr<RenderProcessManagerDelegate> delegate) {
42 render_process_manager_delegate_ = delegate; 55 render_process_manager_delegate_ = delegate;
43 } 56 }
44 57
45 void FakePowerManagerClient::DecreaseScreenBrightness(bool allow_off) { 58 void FakePowerManagerClient::DecreaseScreenBrightness(bool allow_off) {
46 } 59 }
47 60
48 void FakePowerManagerClient::IncreaseScreenBrightness() { 61 void FakePowerManagerClient::IncreaseScreenBrightness() {
49 } 62 }
50 63
51 void FakePowerManagerClient::SetScreenBrightnessPercent(double percent, 64 void FakePowerManagerClient::SetScreenBrightnessPercent(double percent,
52 bool gradual) { 65 bool gradual) {
53 } 66 }
54 67
55 void FakePowerManagerClient::GetScreenBrightnessPercent( 68 void FakePowerManagerClient::GetScreenBrightnessPercent(
56 const GetScreenBrightnessPercentCallback& callback) { 69 const GetScreenBrightnessPercentCallback& callback) {
57 } 70 }
58 71
59 void FakePowerManagerClient::DecreaseKeyboardBrightness() { 72 void FakePowerManagerClient::DecreaseKeyboardBrightness() {
60 } 73 }
61 74
62 void FakePowerManagerClient::IncreaseKeyboardBrightness() { 75 void FakePowerManagerClient::IncreaseKeyboardBrightness() {
63 } 76 }
64 77
65 void FakePowerManagerClient::RequestStatusUpdate() { 78 void FakePowerManagerClient::RequestStatusUpdate() {
79 // RequestStatusUpdate() calls and notifies the observers
80 // asynchronously on a real device. On the fake implementation, we call
81 // observers in a posted task to emulate the same behavior.
82 base::ThreadTaskRunnerHandle::Get()->PostTask(
83 FROM_HERE, base::Bind(&FakePowerManagerClient::NotifyObservers,
84 weak_ptr_factory_.GetWeakPtr()));
66 } 85 }
67 86
68 void FakePowerManagerClient::RequestSuspend() { 87 void FakePowerManagerClient::RequestSuspend() {
69 } 88 }
70 89
71 void FakePowerManagerClient::RequestRestart() { 90 void FakePowerManagerClient::RequestRestart() {
72 ++num_request_restart_calls_; 91 ++num_request_restart_calls_;
73 } 92 }
74 93
75 void FakePowerManagerClient::RequestShutdown() { 94 void FakePowerManagerClient::RequestShutdown() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 FOR_EACH_OBSERVER(Observer, observers_, DarkSuspendImminent()); 141 FOR_EACH_OBSERVER(Observer, observers_, DarkSuspendImminent());
123 } 142 }
124 143
125 void FakePowerManagerClient::SendPowerButtonEvent( 144 void FakePowerManagerClient::SendPowerButtonEvent(
126 bool down, 145 bool down,
127 const base::TimeTicks& timestamp) { 146 const base::TimeTicks& timestamp) {
128 FOR_EACH_OBSERVER(Observer, observers_, 147 FOR_EACH_OBSERVER(Observer, observers_,
129 PowerButtonEventReceived(down, timestamp)); 148 PowerButtonEventReceived(down, timestamp));
130 } 149 }
131 150
151 void FakePowerManagerClient::UpdatePowerProperties(
152 const power_manager::PowerSupplyProperties& power_props) {
153 props_ = power_props;
154 NotifyObservers();
155 }
156
157 void FakePowerManagerClient::NotifyObservers() {
158 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(props_));
159 }
160
132 void FakePowerManagerClient::HandleSuspendReadiness() { 161 void FakePowerManagerClient::HandleSuspendReadiness() {
133 CHECK(num_pending_suspend_readiness_callbacks_ > 0); 162 CHECK(num_pending_suspend_readiness_callbacks_ > 0);
134 163
135 --num_pending_suspend_readiness_callbacks_; 164 --num_pending_suspend_readiness_callbacks_;
136 } 165 }
137 166
138 } // namespace chromeos 167 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698