1 // Copyright (c) 2012 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_POWER_MANAGER_CLIENT_H_
6 #define CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/dbus_client.h"
16 #include "chromeos/dbus/dbus_client_implementation_type.h"
17 #include "third_party/cros_system_api/dbus/service_constants.h"
19 namespace power_manager
{
20 class PowerManagementPolicy
;
21 class PowerSupplyProperties
;
26 // Callback used for getting the current screen brightness. The param is in the
27 // range [0.0, 100.0].
28 typedef base::Callback
<void(double)> GetScreenBrightnessPercentCallback
;
30 // PowerManagerClient is used to communicate with the power manager.
31 class CHROMEOS_EXPORT PowerManagerClient
: public DBusClient
{
33 // Interface for observing changes from the power manager.
36 virtual ~Observer() {}
38 // Called if the power manager process restarts.
39 virtual void PowerManagerRestarted() {}
41 // Called when the brightness is changed.
42 // |level| is of the range [0, 100].
43 // |user_initiated| is true if the action is initiated by the user.
44 virtual void BrightnessChanged(int level
, bool user_initiated
) {}
46 // Called when peripheral device battery status is received.
47 // |path| is the sysfs path for the battery of the peripheral device.
48 // |name| is the human readble name of the device.
49 // |level| within [0, 100] represents the device battery level and -1
50 // means an unknown level or device is disconnected.
51 virtual void PeripheralBatteryStatusReceived(const std::string
& path
,
52 const std::string
& name
,
55 // Called when updated information about the power supply is available.
56 // The status is automatically updated periodically, but
57 // RequestStatusUpdate() can be used to trigger an immediate update.
58 virtual void PowerChanged(
59 const power_manager::PowerSupplyProperties
& proto
) {}
61 // Called when the system is about to suspend. Suspend is deferred until
62 // all observers' implementations of this method have finished running.
64 // If an observer wishes to asynchronously delay suspend,
65 // PowerManagerClient::GetSuspendReadinessCallback() may be called from
66 // within SuspendImminent(). The returned callback must be called once
67 // the observer is ready for suspend.
68 virtual void SuspendImminent() {}
70 // Called when a suspend attempt (previously announced via
71 // SuspendImminent()) has completed. The system may not have actually
72 // suspended (if e.g. the user canceled the suspend attempt).
73 virtual void SuspendDone(const base::TimeDelta
& sleep_duration
) {}
75 // Called when the system is about to resuspend from a dark resume. Like
76 // SuspendImminent(), the suspend will be deferred until all observers have
77 // finished running and those observers that wish to asynchronously delay
78 // the suspend should call PowerManagerClient::GetSuspendReadinessCallback()
79 // from within this method. The returned callback should be run once the
80 // observer is ready for suspend.
81 virtual void DarkSuspendImminent() {}
83 // Called when the power button is pressed or released.
84 virtual void PowerButtonEventReceived(bool down
,
85 const base::TimeTicks
& timestamp
) {}
87 // Called when the device's lid is opened or closed.
88 virtual void LidEventReceived(bool open
,
89 const base::TimeTicks
& timestamp
) {}
91 // Called when the idle action will be performed after
92 // |time_until_idle_action|.
93 virtual void IdleActionImminent(
94 const base::TimeDelta
& time_until_idle_action
) {}
96 // Called after IdleActionImminent() when the inactivity timer is reset
97 // before the idle action has been performed.
98 virtual void IdleActionDeferred() {}
101 // Adds and removes the observer.
102 virtual void AddObserver(Observer
* observer
) = 0;
103 virtual void RemoveObserver(Observer
* observer
) = 0;
104 virtual bool HasObserver(const Observer
* observer
) const = 0;
106 // Interface for managing the power consumption of renderer processes.
107 class RenderProcessManagerDelegate
{
109 virtual ~RenderProcessManagerDelegate() {}
111 // Called when a suspend attempt is imminent but after all registered
112 // observers have reported readiness to suspend. This is only called for
113 // suspends from the fully powered on state and not for suspends from dark
115 virtual void SuspendImminent() = 0;
117 // Called when a previously announced suspend attempt has completed but
118 // before observers are notified about it.
119 virtual void SuspendDone() = 0;
122 // Sets the PowerManagerClient's RenderProcessManagerDelegate. There can only
124 virtual void SetRenderProcessManagerDelegate(
125 base::WeakPtr
<RenderProcessManagerDelegate
> delegate
) = 0;
127 // Decreases the screen brightness. |allow_off| controls whether or not
128 // it's allowed to turn off the back light.
129 virtual void DecreaseScreenBrightness(bool allow_off
) = 0;
131 // Increases the screen brightness.
132 virtual void IncreaseScreenBrightness() = 0;
134 // Set the screen brightness to |percent|, in the range [0.0, 100.0].
135 // If |gradual| is true, the transition will be animated.
136 virtual void SetScreenBrightnessPercent(double percent
, bool gradual
) = 0;
138 // Asynchronously gets the current screen brightness, in the range
140 virtual void GetScreenBrightnessPercent(
141 const GetScreenBrightnessPercentCallback
& callback
) = 0;
143 // Decreases the keyboard brightness.
144 virtual void DecreaseKeyboardBrightness() = 0;
146 // Increases the keyboard brightness.
147 virtual void IncreaseKeyboardBrightness() = 0;
149 // Requests an updated copy of the power status. Observer::PowerChanged()
150 // will be called asynchronously.
151 virtual void RequestStatusUpdate() = 0;
153 // Requests suspend of the system.
154 virtual void RequestSuspend() = 0;
156 // Requests restart of the system.
157 virtual void RequestRestart() = 0;
159 // Requests shutdown of the system.
160 virtual void RequestShutdown() = 0;
162 // Notifies the power manager that the user is active (i.e. generating input
164 virtual void NotifyUserActivity(power_manager::UserActivityType type
) = 0;
166 // Notifies the power manager that a video is currently playing. It also
167 // includes whether or not the containing window for the video is fullscreen.
168 virtual void NotifyVideoActivity(bool is_fullscreen
) = 0;
170 // Tells the power manager to begin using |policy|.
171 virtual void SetPolicy(
172 const power_manager::PowerManagementPolicy
& policy
) = 0;
174 // Tells powerd whether or not we are in a projecting mode. This is used to
175 // adjust idleness thresholds and derived, on this side, from the number of
176 // video outputs attached.
177 virtual void SetIsProjecting(bool is_projecting
) = 0;
179 // Returns a callback that can be called by an observer to report
180 // readiness for suspend. See Observer::SuspendImminent().
181 virtual base::Closure
GetSuspendReadinessCallback() = 0;
183 // Returns the number of callbacks returned by GetSuspendReadinessCallback()
184 // for the current suspend attempt but not yet called. Used by tests.
185 virtual int GetNumPendingSuspendReadinessCallbacks() = 0;
187 // Creates the instance.
188 static PowerManagerClient
* Create(DBusClientImplementationType type
);
190 virtual ~PowerManagerClient();
193 // Create() should be used instead.
194 PowerManagerClient();
197 DISALLOW_COPY_AND_ASSIGN(PowerManagerClient
);
200 } // namespace chromeos
202 #endif // CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_