| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ |
| 7 |
| 8 #include "base/observer_list.h" |
| 9 #include "base/singleton.h" |
| 10 #include "base/time.h" |
| 11 #include "third_party/cros/chromeos_power.h" |
| 12 |
| 13 // 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 |
| 15 // library class like this: CrosPowerLibrary::Get() |
| 16 class CrosPowerLibrary { |
| 17 public: |
| 18 class Observer { |
| 19 public: |
| 20 virtual void PowerChanged(CrosPowerLibrary* obj) = 0; |
| 21 }; |
| 22 |
| 23 // This gets the singleton CrosPowerLibrary |
| 24 static CrosPowerLibrary* Get(); |
| 25 |
| 26 // Returns true if the ChromeOS library was loaded. |
| 27 static bool loaded(); |
| 28 |
| 29 void AddObserver(Observer* observer); |
| 30 void RemoveObserver(Observer* observer); |
| 31 |
| 32 // Whether or not the line power is connected. |
| 33 bool line_power_on() const; |
| 34 |
| 35 // Whether or not the battery is fully charged.. |
| 36 bool battery_fully_charged() const; |
| 37 |
| 38 // The percentage (0-100) of remaining battery. |
| 39 double battery_percentage() const; |
| 40 |
| 41 // The amount of time until battery is empty. |
| 42 base::TimeDelta battery_time_to_empty() const; |
| 43 |
| 44 // The amount of time until battery is full. |
| 45 base::TimeDelta battery_time_to_full() const; |
| 46 |
| 47 private: |
| 48 friend struct DefaultSingletonTraits<CrosPowerLibrary>; |
| 49 |
| 50 CrosPowerLibrary(); |
| 51 ~CrosPowerLibrary(); |
| 52 |
| 53 // This method is called when there's a change in power status. |
| 54 // This will notify all the Observers. |
| 55 static void PowerStatusChangedHandler(void* object, |
| 56 const chromeos::PowerStatus& status); |
| 57 |
| 58 ObserverList<Observer> observers_; |
| 59 |
| 60 // A reference to the battery power api, to allow callbacks when the battery |
| 61 // status changes. |
| 62 chromeos::PowerStatusConnection power_status_connection_; |
| 63 |
| 64 // The latest power status. |
| 65 chromeos::PowerStatus status_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(CrosPowerLibrary); |
| 68 }; |
| 69 |
| 70 #endif // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ |
| OLD | NEW |