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 #ifndef CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_
10 #include "base/basictypes.h"
11 #include "base/macros.h"
12 #include "base/observer_list.h"
13 #include "chromeos/dbus/power_manager/policy.pb.h"
14 #include "chromeos/dbus/power_manager/suspend.pb.h"
15 #include "chromeos/dbus/power_manager_client.h"
19 // A fake implementation of PowerManagerClient. This remembers the policy passed
20 // to SetPolicy() and the user of this class can inspect the last set policy by
22 class FakePowerManagerClient
: public PowerManagerClient
{
24 FakePowerManagerClient();
25 ~FakePowerManagerClient() override
;
27 power_manager::PowerManagementPolicy
& policy() { return policy_
; }
28 int num_request_restart_calls() const { return num_request_restart_calls_
; }
29 int num_request_shutdown_calls() const { return num_request_shutdown_calls_
; }
30 int num_set_policy_calls() const { return num_set_policy_calls_
; }
31 int num_set_is_projecting_calls() const {
32 return num_set_is_projecting_calls_
;
34 bool is_projecting() const { return is_projecting_
; }
36 // PowerManagerClient overrides
37 void Init(dbus::Bus
* bus
) override
;
38 void AddObserver(Observer
* observer
) override
;
39 void RemoveObserver(Observer
* observer
) override
;
40 bool HasObserver(const Observer
* observer
) const override
;
41 void SetRenderProcessManagerDelegate(
42 base::WeakPtr
<RenderProcessManagerDelegate
> delegate
) override
;
43 void DecreaseScreenBrightness(bool allow_off
) override
;
44 void IncreaseScreenBrightness() override
;
45 void SetScreenBrightnessPercent(double percent
, bool gradual
) override
;
46 void GetScreenBrightnessPercent(
47 const GetScreenBrightnessPercentCallback
& callback
) override
;
48 void DecreaseKeyboardBrightness() override
;
49 void IncreaseKeyboardBrightness() override
;
50 void RequestStatusUpdate() override
;
51 void RequestSuspend() override
;
52 void RequestRestart() override
;
53 void RequestShutdown() override
;
54 void NotifyUserActivity(power_manager::UserActivityType type
) override
;
55 void NotifyVideoActivity(bool is_fullscreen
) override
;
56 void SetPolicy(const power_manager::PowerManagementPolicy
& policy
) override
;
57 void SetIsProjecting(bool is_projecting
) override
;
58 base::Closure
GetSuspendReadinessCallback() override
;
59 int GetNumPendingSuspendReadinessCallbacks() override
;
61 // Emulates the power manager announcing that the system is starting or
62 // completing a suspend attempt.
63 void SendSuspendImminent();
64 void SendSuspendDone();
65 void SendDarkSuspendImminent();
67 // Notifies observers that the power button has been pressed or released.
68 void SendPowerButtonEvent(bool down
, const base::TimeTicks
& timestamp
);
71 // Callback that will be run by asynchronous suspend delays to report
73 void HandleSuspendReadiness();
75 ObserverList
<Observer
> observers_
;
77 // Last policy passed to SetPolicy().
78 power_manager::PowerManagementPolicy policy_
;
80 // Number of times that various methods have been called.
81 int num_request_restart_calls_
;
82 int num_request_shutdown_calls_
;
83 int num_set_policy_calls_
;
84 int num_set_is_projecting_calls_
;
86 // Number of pending suspend readiness callbacks.
87 int num_pending_suspend_readiness_callbacks_
;
89 // Last projecting state set in SetIsProjecting().
92 // Delegate for managing power consumption of Chrome's renderer processes.
93 base::WeakPtr
<RenderProcessManagerDelegate
> render_process_manager_delegate_
;
95 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient
);
98 } // namespace chromeos
100 #endif // CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_