OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/callback.h" | |
12 #include "chrome/browser/chromeos/dbus/dbus_client_implementation_type.h" | |
13 | |
14 #include "chromeos/dbus/power_supply_status.h" | |
15 | |
16 namespace base { | |
17 class TimeTicks; | |
18 } | |
19 namespace dbus { | |
20 class Bus; | |
21 } | |
22 | |
23 namespace chromeos { | |
24 | |
25 // Callback used for processing the idle time. The int64 param is the number of | |
26 // seconds the user has been idle. | |
27 typedef base::Callback<void(int64)> CalculateIdleTimeCallback; | |
28 typedef base::Callback<void(void)> IdleNotificationCallback; | |
29 typedef base::Callback<void(uint32)> PowerStateRequestIdCallback; | |
30 | |
31 // Callback used for getting the current screen brightness. The param is in the | |
32 // range [0.0, 100.0]. | |
33 typedef base::Callback<void(double)> GetScreenBrightnessPercentCallback; | |
34 | |
35 // PowerManagerClient is used to communicate with the power manager. | |
36 class PowerManagerClient { | |
37 public: | |
38 // Interface for observing changes from the power manager. | |
39 class Observer { | |
40 public: | |
41 virtual ~Observer() {} | |
42 | |
43 // Called when the brightness is changed. | |
44 // |level| is of the range [0, 100]. | |
45 // |user_initiated| is true if the action is initiated by the user. | |
46 virtual void BrightnessChanged(int level, bool user_initiated) {} | |
47 | |
48 // Called when power supply polling takes place. |status| is a data | |
49 // structure that contains the current state of the power supply. | |
50 virtual void PowerChanged(const PowerSupplyStatus& status) {} | |
51 | |
52 // Called when the system resumes from suspend. | |
53 virtual void SystemResumed() {} | |
54 | |
55 // Called when the power button is pressed or released. | |
56 virtual void PowerButtonStateChanged(bool down, | |
57 const base::TimeTicks& timestamp) {} | |
58 | |
59 // Called when the lock button is pressed or released. | |
60 virtual void LockButtonStateChanged(bool down, | |
61 const base::TimeTicks& timestamp) {} | |
62 | |
63 // Called when the screen is locked. | |
64 virtual void LockScreen() {} | |
65 | |
66 // Called when the screen is unlocked. | |
67 virtual void UnlockScreen() {} | |
68 | |
69 // Called when the screen fails to unlock. | |
70 virtual void UnlockScreenFailed() {} | |
71 | |
72 // Called when we go idle for threshold time. | |
73 virtual void IdleNotify(int64 threshold_secs) {} | |
74 | |
75 // Called when we go from idle to active. | |
76 virtual void ActiveNotify() {} | |
77 }; | |
78 | |
79 enum UpdateRequestType { | |
80 UPDATE_INITIAL, // Initial update request. | |
81 UPDATE_USER, // User initialted update request. | |
82 UPDATE_POLL // Update requested by poll signal. | |
83 }; | |
84 | |
85 enum PowerStateOverrideType { | |
86 DISABLE_IDLE_DIM = 1, // Disable screen dimming on idle. | |
87 DISABLE_IDLE_BLANK = 2, // Disable screen blanking on idle. | |
88 DISABLE_IDLE_SUSPEND = 3, // Disable suspend on idle. | |
89 DISABLE_IDLE_LID_SUSPEND = 4, // Disable suspend on lid closed. | |
90 }; | |
91 | |
92 // Adds and removes the observer. | |
93 virtual void AddObserver(Observer* observer) = 0; | |
94 virtual void RemoveObserver(Observer* observer) = 0; | |
95 virtual bool HasObserver(Observer* observer) = 0; | |
96 | |
97 // Decreases the screen brightness. |allow_off| controls whether or not | |
98 // it's allowed to turn off the back light. | |
99 virtual void DecreaseScreenBrightness(bool allow_off) = 0; | |
100 | |
101 // Increases the screen brightness. | |
102 virtual void IncreaseScreenBrightness() = 0; | |
103 | |
104 // Set the screen brightness to |percent|, in the range [0.0, 100.0]. | |
105 // If |gradual| is true, the transition will be animated. | |
106 virtual void SetScreenBrightnessPercent(double percent, bool gradual) = 0; | |
107 | |
108 // Asynchronously gets the current screen brightness, in the range | |
109 // [0.0, 100.0]. | |
110 virtual void GetScreenBrightnessPercent( | |
111 const GetScreenBrightnessPercentCallback& callback) = 0; | |
112 | |
113 // Request for power supply status update. | |
114 virtual void RequestStatusUpdate(UpdateRequestType update_type) = 0; | |
115 | |
116 // Requests restart of the system. | |
117 virtual void RequestRestart() = 0; | |
118 | |
119 // Requests shutdown of the system. | |
120 virtual void RequestShutdown() = 0; | |
121 | |
122 // Notifies PowerManager that a user requested to lock the screen. | |
123 virtual void NotifyScreenLockRequested() = 0; | |
124 | |
125 // Notifies PowerManager that screen lock has been completed. | |
126 virtual void NotifyScreenLockCompleted() = 0; | |
127 | |
128 // Notifies PowerManager that a user unlocked the screen. | |
129 virtual void NotifyScreenUnlockRequested() = 0; | |
130 | |
131 // Notifies PowerManager that screen is unlocked. | |
132 virtual void NotifyScreenUnlockCompleted() = 0; | |
133 | |
134 // Idle management functions: | |
135 | |
136 // Calculates idle time asynchronously, after the idle time request has | |
137 // replied. It passes the idle time in seconds to |callback|. If it | |
138 // encounters some error, it passes -1 to |callback|. | |
139 virtual void CalculateIdleTime(const CalculateIdleTimeCallback& callback) = 0; | |
140 | |
141 // Requests notification for Idle at a certain threshold. | |
142 // NOTE: This notification is one shot, once the machine has been idle for | |
143 // threshold time, a notification will be sent and then that request will be | |
144 // removed from the notification queue. If you wish notifications the next | |
145 // time the machine goes idle for that much time, request again. | |
146 virtual void RequestIdleNotification(int64 threshold_secs) = 0; | |
147 | |
148 // Requests that the observers be notified in case of an Idle->Active event. | |
149 // NOTE: Like the previous request, this will also get triggered exactly once. | |
150 virtual void RequestActiveNotification() = 0; | |
151 | |
152 // Override the current power state on the machine. The overrides will be | |
153 // applied to the request ID specified. To specify a new request; use 0 as | |
154 // the request id and the method will call the provided callback with the | |
155 // new request ID for use with further calls. | |
156 // The overrides parameter will & out the PowerStateOverrideType types to | |
157 // allow specific selection of overrides. For example, to override just dim | |
158 // and suspending but leaving blanking in, set overrides to, | |
159 // DISABLE_IDLE_DIM | DISABLE_IDLE_SUSPEND. | |
160 virtual void RequestPowerStateOverrides( | |
161 uint32 request_id, | |
162 uint32 duration, | |
163 int overrides, | |
164 PowerStateRequestIdCallback callback) = 0; | |
165 | |
166 // Creates the instance. | |
167 static PowerManagerClient* Create(DBusClientImplementationType type, | |
168 dbus::Bus* bus); | |
169 | |
170 virtual ~PowerManagerClient(); | |
171 | |
172 protected: | |
173 // Create() should be used instead. | |
174 PowerManagerClient(); | |
175 | |
176 private: | |
177 DISALLOW_COPY_AND_ASSIGN(PowerManagerClient); | |
178 }; | |
179 | |
180 } // namespace chromeos | |
181 | |
182 #endif // CHROME_BROWSER_CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ | |
OLD | NEW |