OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_POWER_LIBRARY_H_ |
6 #define CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POWER_LIBRARY_H_ |
7 | 7 |
8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
9 #include "base/singleton.h" | 9 #include "base/singleton.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "third_party/cros/chromeos_power.h" | 11 #include "third_party/cros/chromeos_power.h" |
12 | 12 |
| 13 namespace chromeos { |
| 14 |
13 // This class handles the interaction with the ChromeOS power library APIs. | 15 // This class handles the interaction with the ChromeOS power library APIs. |
14 // Classes can add themselves as observers. Users can get an instance of this | 16 // Classes can add themselves as observers. Users can get an instance of this |
15 // library class like this: CrosPowerLibrary::Get() | 17 // library class like this: PowerLibrary::Get() |
16 class CrosPowerLibrary { | 18 class PowerLibrary { |
17 public: | 19 public: |
18 class Observer { | 20 class Observer { |
19 public: | 21 public: |
20 virtual void PowerChanged(CrosPowerLibrary* obj) = 0; | 22 virtual void PowerChanged(PowerLibrary* obj) = 0; |
21 }; | 23 }; |
22 | 24 |
23 // This gets the singleton CrosPowerLibrary | 25 // This gets the singleton PowerLibrary |
24 static CrosPowerLibrary* Get(); | 26 static PowerLibrary* Get(); |
25 | 27 |
26 // Returns true if the ChromeOS library was loaded. | 28 // Returns true if the ChromeOS library was loaded. |
27 static bool loaded(); | 29 static bool loaded(); |
28 | 30 |
29 void AddObserver(Observer* observer); | 31 void AddObserver(Observer* observer); |
30 void RemoveObserver(Observer* observer); | 32 void RemoveObserver(Observer* observer); |
31 | 33 |
32 // Whether or not the line power is connected. | 34 // Whether or not the line power is connected. |
33 bool line_power_on() const; | 35 bool line_power_on() const; |
34 | 36 |
35 // Whether or not the battery is fully charged.. | 37 // Whether or not the battery is fully charged.. |
36 bool battery_fully_charged() const; | 38 bool battery_fully_charged() const; |
37 | 39 |
38 // The percentage (0-100) of remaining battery. | 40 // The percentage (0-100) of remaining battery. |
39 double battery_percentage() const; | 41 double battery_percentage() const; |
40 | 42 |
41 // Whether there is a battery present. | 43 // Whether there is a battery present. |
42 bool battery_is_present() const; | 44 bool battery_is_present() const; |
43 | 45 |
44 // The amount of time until battery is empty. | 46 // The amount of time until battery is empty. |
45 base::TimeDelta battery_time_to_empty() const; | 47 base::TimeDelta battery_time_to_empty() const; |
46 | 48 |
47 // The amount of time until battery is full. | 49 // The amount of time until battery is full. |
48 base::TimeDelta battery_time_to_full() const; | 50 base::TimeDelta battery_time_to_full() const; |
49 | 51 |
50 private: | 52 private: |
51 friend struct DefaultSingletonTraits<CrosPowerLibrary>; | 53 friend struct DefaultSingletonTraits<PowerLibrary>; |
52 | 54 |
53 CrosPowerLibrary(); | 55 PowerLibrary(); |
54 ~CrosPowerLibrary(); | 56 ~PowerLibrary(); |
55 | 57 |
56 // This method is called when there's a change in power status. | 58 // This method is called when there's a change in power status. |
57 // This method is called on a background thread. | 59 // This method is called on a background thread. |
58 static void PowerStatusChangedHandler(void* object, | 60 static void PowerStatusChangedHandler(void* object, |
59 const chromeos::PowerStatus& status); | 61 const chromeos::PowerStatus& status); |
60 | 62 |
61 // This methods starts the monitoring of power changes. | 63 // This methods starts the monitoring of power changes. |
62 void Init(); | 64 void Init(); |
63 | 65 |
64 // Called by the handler to update the power status. | 66 // Called by the handler to update the power status. |
65 // This will notify all the Observers. | 67 // This will notify all the Observers. |
66 void UpdatePowerStatus(const chromeos::PowerStatus& status); | 68 void UpdatePowerStatus(const chromeos::PowerStatus& status); |
67 | 69 |
68 ObserverList<Observer> observers_; | 70 ObserverList<Observer> observers_; |
69 | 71 |
70 // A reference to the battery power api, to allow callbacks when the battery | 72 // A reference to the battery power api, to allow callbacks when the battery |
71 // status changes. | 73 // status changes. |
72 chromeos::PowerStatusConnection power_status_connection_; | 74 chromeos::PowerStatusConnection power_status_connection_; |
73 | 75 |
74 // The latest power status. | 76 // The latest power status. |
75 chromeos::PowerStatus status_; | 77 chromeos::PowerStatus status_; |
76 | 78 |
77 DISALLOW_COPY_AND_ASSIGN(CrosPowerLibrary); | 79 DISALLOW_COPY_AND_ASSIGN(PowerLibrary); |
78 }; | 80 }; |
79 | 81 |
80 #endif // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ | 82 } // namespace chromeos |
| 83 |
| 84 #endif // CHROME_BROWSER_CHROMEOS_POWER_LIBRARY_H_ |
OLD | NEW |