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"
10 #include "chromeos/dbus/power_manager/policy.pb.h"
14 FakePowerManagerClient::FakePowerManagerClient()
15 : num_request_restart_calls_(0),
16 num_request_shutdown_calls_(0),
17 num_set_policy_calls_(0),
18 num_set_is_projecting_calls_(0),
19 num_pending_suspend_readiness_callbacks_(0),
20 is_projecting_(false) {
23 FakePowerManagerClient::~FakePowerManagerClient() {
26 void FakePowerManagerClient::Init(dbus::Bus
* bus
) {
29 void FakePowerManagerClient::AddObserver(Observer
* observer
) {
30 observers_
.AddObserver(observer
);
33 void FakePowerManagerClient::RemoveObserver(Observer
* observer
) {
34 observers_
.RemoveObserver(observer
);
37 bool FakePowerManagerClient::HasObserver(const Observer
* observer
) const {
41 void FakePowerManagerClient::SetRenderProcessManagerDelegate(
42 base::WeakPtr
<RenderProcessManagerDelegate
> delegate
) {
43 render_process_manager_delegate_
= delegate
;
46 void FakePowerManagerClient::DecreaseScreenBrightness(bool allow_off
) {
49 void FakePowerManagerClient::IncreaseScreenBrightness() {
52 void FakePowerManagerClient::SetScreenBrightnessPercent(double percent
,
56 void FakePowerManagerClient::GetScreenBrightnessPercent(
57 const GetScreenBrightnessPercentCallback
& callback
) {
60 void FakePowerManagerClient::DecreaseKeyboardBrightness() {
63 void FakePowerManagerClient::IncreaseKeyboardBrightness() {
66 void FakePowerManagerClient::RequestStatusUpdate() {
69 void FakePowerManagerClient::RequestSuspend() {
72 void FakePowerManagerClient::RequestRestart() {
73 ++num_request_restart_calls_
;
76 void FakePowerManagerClient::RequestShutdown() {
77 ++num_request_shutdown_calls_
;
80 void FakePowerManagerClient::NotifyUserActivity(
81 power_manager::UserActivityType type
) {
84 void FakePowerManagerClient::NotifyVideoActivity(bool is_fullscreen
) {
87 void FakePowerManagerClient::SetPolicy(
88 const power_manager::PowerManagementPolicy
& policy
) {
90 ++num_set_policy_calls_
;
93 void FakePowerManagerClient::SetIsProjecting(bool is_projecting
) {
94 ++num_set_is_projecting_calls_
;
95 is_projecting_
= is_projecting
;
98 base::Closure
FakePowerManagerClient::GetSuspendReadinessCallback() {
99 ++num_pending_suspend_readiness_callbacks_
;
101 return base::Bind(&FakePowerManagerClient::HandleSuspendReadiness
,
102 base::Unretained(this));
105 int FakePowerManagerClient::GetNumPendingSuspendReadinessCallbacks() {
106 return num_pending_suspend_readiness_callbacks_
;
109 void FakePowerManagerClient::SendSuspendImminent() {
110 FOR_EACH_OBSERVER(Observer
, observers_
, SuspendImminent());
111 if (render_process_manager_delegate_
)
112 render_process_manager_delegate_
->SuspendImminent();
115 void FakePowerManagerClient::SendSuspendDone() {
116 if (render_process_manager_delegate_
)
117 render_process_manager_delegate_
->SuspendDone();
119 FOR_EACH_OBSERVER(Observer
, observers_
, SuspendDone(base::TimeDelta()));
122 void FakePowerManagerClient::SendDarkSuspendImminent() {
123 FOR_EACH_OBSERVER(Observer
, observers_
, DarkSuspendImminent());
126 void FakePowerManagerClient::SendPowerButtonEvent(
128 const base::TimeTicks
& timestamp
) {
129 FOR_EACH_OBSERVER(Observer
, observers_
,
130 PowerButtonEventReceived(down
, timestamp
));
133 void FakePowerManagerClient::HandleSuspendReadiness() {
134 CHECK(num_pending_suspend_readiness_callbacks_
> 0);
136 --num_pending_suspend_readiness_callbacks_
;
139 } // namespace chromeos