OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ |
6 #define CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
| 9 // TODO(sque): Move to chrome/browser/chromeos/system, crosbug.com/16558 |
| 10 |
9 #include "base/callback.h" | 11 #include "base/callback.h" |
10 | 12 |
11 namespace base { | 13 namespace base { |
12 class TimeDelta; | 14 class TimeDelta; |
13 } | 15 } |
14 | 16 |
15 namespace chromeos { | 17 namespace chromeos { |
16 | 18 |
17 typedef base::Callback<void(int64_t)> CalculateIdleTimeCallback; | 19 typedef base::Callback<void(int64_t)> CalculateIdleTimeCallback; |
18 | 20 |
| 21 struct PowerSupplyStatus { |
| 22 bool line_power_on; |
| 23 |
| 24 bool battery_is_present; |
| 25 bool battery_is_full; |
| 26 |
| 27 // Time in seconds until the battery is empty or full, 0 for unknown. |
| 28 int64 battery_seconds_to_empty; |
| 29 int64 battery_seconds_to_full; |
| 30 |
| 31 double battery_percentage; |
| 32 }; |
| 33 |
19 // This interface defines interaction with the ChromeOS power library APIs. | 34 // This interface defines interaction with the ChromeOS power library APIs. |
20 // Classes can add themselves as observers. Users can get an instance of this | 35 // Classes can add themselves as observers. Users can get an instance of this |
21 // library class like this: chromeos::CrosLibrary::Get()->GetPowerLibrary() | 36 // library class like this: chromeos::CrosLibrary::Get()->GetPowerLibrary() |
22 class PowerLibrary { | 37 class PowerLibrary { |
23 public: | 38 public: |
24 class Observer { | 39 class Observer { |
25 public: | 40 public: |
26 virtual void PowerChanged(PowerLibrary* obj) = 0; | 41 virtual void PowerChanged(const PowerSupplyStatus& status) = 0; |
27 virtual void SystemResumed() = 0; | 42 virtual void SystemResumed() = 0; |
28 | 43 |
29 protected: | 44 protected: |
30 virtual ~Observer() {} | 45 virtual ~Observer() {} |
31 }; | 46 }; |
32 | 47 |
33 virtual ~PowerLibrary() {} | 48 virtual ~PowerLibrary() {} |
34 | 49 |
35 virtual void Init() = 0; | 50 virtual void Init() = 0; |
36 | 51 |
37 virtual void AddObserver(Observer* observer) = 0; | 52 virtual void AddObserver(Observer* observer) = 0; |
38 virtual void RemoveObserver(Observer* observer) = 0; | 53 virtual void RemoveObserver(Observer* observer) = 0; |
39 | 54 |
40 // Whether or not the line power is connected. | |
41 virtual bool IsLinePowerOn() const = 0; | |
42 | |
43 // Whether or not the battery is fully charged. | |
44 virtual bool IsBatteryFullyCharged() const = 0; | |
45 | |
46 // The percentage [0-100] of remaining battery. | |
47 virtual double GetBatteryPercentage() const = 0; | |
48 | |
49 // Whether there is a battery present. | |
50 virtual bool IsBatteryPresent() const = 0; | |
51 | |
52 // The amount of time until battery is empty. | |
53 virtual base::TimeDelta GetBatteryTimeToEmpty() const = 0; | |
54 | |
55 // The amount of time until battery is full. | |
56 virtual base::TimeDelta GetBatteryTimeToFull() const = 0; | |
57 | |
58 // Calculates idle time asynchronously. If it encounters some error, | 55 // Calculates idle time asynchronously. If it encounters some error, |
59 // it returns -1. | 56 // it returns -1. |
60 virtual void CalculateIdleTime(CalculateIdleTimeCallback* callback) = 0; | 57 virtual void CalculateIdleTime(CalculateIdleTimeCallback* callback) = 0; |
61 | 58 |
62 // Enable/disable screen lock for current session. | 59 // Enable/disable screen lock for current session. |
63 virtual void EnableScreenLock(bool enable) = 0; | 60 virtual void EnableScreenLock(bool enable) = 0; |
64 | 61 |
65 // Requests restart of the system. | 62 // Requests restart of the system. |
66 virtual void RequestRestart() = 0; | 63 virtual void RequestRestart() = 0; |
67 | 64 |
68 // Requests shutdown of the system. | 65 // Requests shutdown of the system. |
69 virtual void RequestShutdown() = 0; | 66 virtual void RequestShutdown() = 0; |
70 | 67 |
71 // UI initiated request for status update. | 68 // UI initiated request for status update. |
72 virtual void RequestStatusUpdate() = 0; | 69 virtual void RequestStatusUpdate() = 0; |
73 | 70 |
74 // Factory function, creates a new instance and returns ownership. | 71 // Factory function, creates a new instance and returns ownership. |
75 // For normal usage, access the singleton via CrosLibrary::Get(). | 72 // For normal usage, access the singleton via CrosLibrary::Get(). |
76 static PowerLibrary* GetImpl(bool stub); | 73 static PowerLibrary* GetImpl(bool stub); |
77 }; | 74 }; |
78 | 75 |
79 } // namespace chromeos | 76 } // namespace chromeos |
80 | 77 |
81 #endif // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ | 78 #endif // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ |
OLD | NEW |