blob: 9b246a4d9205b13a094a199b5b2740ed69ac8798 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_
#define CHROME_BROWSER_CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
namespace dbus {
class Bus;
} // namespace
namespace chromeos {
// This is the local struct that is used in Chrome.
struct PowerSupplyStatus {
bool line_power_on;
bool battery_is_present;
bool battery_is_full;
// Time in seconds until the battery is empty or full, 0 for unknown.
int64 battery_seconds_to_empty;
int64 battery_seconds_to_full;
double battery_percentage;
PowerSupplyStatus();
std::string ToString() const;
};
// Callback used for processing the idle time. The int64 param is the number of
// seconds the user has been idle.
typedef base::Callback<void(int64)> CalculateIdleTimeCallback;
// PowerManagerClient is used to communicate with the power manager.
class PowerManagerClient {
public:
// Interface for observing changes from the power manager.
class Observer {
public:
virtual ~Observer() {}
// Called when the brightness is changed.
// |level| is of the range [0, 100].
// |user_initiated| is true if the action is initiated by the user.
virtual void BrightnessChanged(int level, bool user_initiated) {}
// Called when power supply polling takes place. |status| is a data
// structure that contains the current state of the power supply.
virtual void PowerChanged(const PowerSupplyStatus& status) {}
// Called when the system resumes from suspend.
virtual void SystemResumed() {}
// Called when the screen is locked.
virtual void LockScreen() {}
// Called when the screen is unlocked.
virtual void UnlockScreen() {}
// Called when the screen fails to unlock.
virtual void UnlockScreenFailed() {}
};
// Adds and removes the observer.
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
virtual bool HasObserver(Observer* observer) = 0;
// Decreases the screen brightness. |allow_off| controls whether or not
// it's allowed to turn off the back light.
virtual void DecreaseScreenBrightness(bool allow_off) = 0;
// Increases the screen brightness.
virtual void IncreaseScreenBrightness() = 0;
// UI initiated request for power supply status update.
virtual void RequestStatusUpdate() = 0;
// Requests restart of the system.
virtual void RequestRestart() = 0;
// Requests shutdown of the system.
virtual void RequestShutdown() = 0;
// Calculates idle time asynchronously, after the idle time request has
// replied. It passes the idle time in seconds to |callback|. If it
// encounters some error, it passes -1 to |callback|.
virtual void CalculateIdleTime(const CalculateIdleTimeCallback& callback) = 0;
// Notifies PowerManager that a user requested to lock the screen.
virtual void NotifyScreenLockRequested() = 0;
// Notifies PowerManager that screen lock has been completed.
virtual void NotifyScreenLockCompleted() = 0;
// Notifies PowerManager that a user unlocked the screen.
virtual void NotifyScreenUnlockRequested() = 0;
// Notifies PowerManager that screen is unlocked.
virtual void NotifyScreenUnlockCompleted() = 0;
// Creates the instance.
static PowerManagerClient* Create(dbus::Bus* bus);
virtual ~PowerManagerClient();
protected:
// Create() should be used instead.
PowerManagerClient();
private:
DISALLOW_COPY_AND_ASSIGN(PowerManagerClient);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_
|