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
3 // found in the LICENSE file.
5 #include "chromeos/dbus/fake_power_manager_client.h"
8 #include "base/bind_helpers.h"
9 #include "base/time/time.h"
13 FakePowerManagerClient::FakePowerManagerClient()
14 : num_request_restart_calls_(0),
15 num_request_shutdown_calls_(0),
16 num_set_policy_calls_(0),
17 num_set_is_projecting_calls_(0),
18 num_pending_suspend_readiness_callbacks_(0),
19 is_projecting_(false) {
22 FakePowerManagerClient::~FakePowerManagerClient() {
25 void FakePowerManagerClient::Init(dbus::Bus
* bus
) {
28 void FakePowerManagerClient::AddObserver(Observer
* observer
) {
29 observers_
.AddObserver(observer
);
32 void FakePowerManagerClient::RemoveObserver(Observer
* observer
) {
33 observers_
.RemoveObserver(observer
);
36 bool FakePowerManagerClient::HasObserver(const Observer
* observer
) const {
40 void FakePowerManagerClient::SetRenderProcessManagerDelegate(
41 base::WeakPtr
<RenderProcessManagerDelegate
> delegate
) {
42 render_process_manager_delegate_
= delegate
;
45 void FakePowerManagerClient::DecreaseScreenBrightness(bool allow_off
) {
48 void FakePowerManagerClient::IncreaseScreenBrightness() {
51 void FakePowerManagerClient::SetScreenBrightnessPercent(double percent
,
55 void FakePowerManagerClient::GetScreenBrightnessPercent(
56 const GetScreenBrightnessPercentCallback
& callback
) {
59 void FakePowerManagerClient::DecreaseKeyboardBrightness() {
62 void FakePowerManagerClient::IncreaseKeyboardBrightness() {
65 void FakePowerManagerClient::RequestStatusUpdate() {
68 void FakePowerManagerClient::RequestSuspend() {
71 void FakePowerManagerClient::RequestRestart() {
72 ++num_request_restart_calls_
;
75 void FakePowerManagerClient::RequestShutdown() {
76 ++num_request_shutdown_calls_
;
79 void FakePowerManagerClient::NotifyUserActivity(
80 power_manager::UserActivityType type
) {
83 void FakePowerManagerClient::NotifyVideoActivity(bool is_fullscreen
) {
86 void FakePowerManagerClient::SetPolicy(
87 const power_manager::PowerManagementPolicy
& policy
) {
89 ++num_set_policy_calls_
;
92 void FakePowerManagerClient::SetIsProjecting(bool is_projecting
) {
93 ++num_set_is_projecting_calls_
;
94 is_projecting_
= is_projecting
;
97 base::Closure
FakePowerManagerClient::GetSuspendReadinessCallback() {
98 ++num_pending_suspend_readiness_callbacks_
;
100 return base::Bind(&FakePowerManagerClient::HandleSuspendReadiness
,
101 base::Unretained(this));
104 int FakePowerManagerClient::GetNumPendingSuspendReadinessCallbacks() {
105 return num_pending_suspend_readiness_callbacks_
;
108 void FakePowerManagerClient::SendSuspendImminent() {
109 FOR_EACH_OBSERVER(Observer
, observers_
, SuspendImminent());
110 if (render_process_manager_delegate_
)
111 render_process_manager_delegate_
->SuspendImminent();
114 void FakePowerManagerClient::SendSuspendDone() {
115 if (render_process_manager_delegate_
)
116 render_process_manager_delegate_
->SuspendDone();
118 FOR_EACH_OBSERVER(Observer
, observers_
, SuspendDone(base::TimeDelta()));
121 void FakePowerManagerClient::SendDarkSuspendImminent() {
122 FOR_EACH_OBSERVER(Observer
, observers_
, DarkSuspendImminent());
125 void FakePowerManagerClient::SendPowerButtonEvent(
127 const base::TimeTicks
& timestamp
) {
128 FOR_EACH_OBSERVER(Observer
, observers_
,
129 PowerButtonEventReceived(down
, timestamp
));
132 void FakePowerManagerClient::HandleSuspendReadiness() {
133 CHECK(num_pending_suspend_readiness_callbacks_
> 0);
135 --num_pending_suspend_readiness_callbacks_
;
138 } // namespace chromeos