| 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 // Whether there is a battery present. | |
| 42 bool battery_is_present() const; | |
| 43 | |
| 44 // The amount of time until battery is empty. | |
| 45 base::TimeDelta battery_time_to_empty() const; | |
| 46 | |
| 47 // The amount of time until battery is full. | |
| 48 base::TimeDelta battery_time_to_full() const; | |
| 49 | |
| 50 private: | |
| 51 friend struct DefaultSingletonTraits<CrosPowerLibrary>; | |
| 52 | |
| 53 CrosPowerLibrary(); | |
| 54 ~CrosPowerLibrary(); | |
| 55 | |
| 56 // This method is called when there's a change in power status. | |
| 57 // This method is called on a background thread. | |
| 58 static void PowerStatusChangedHandler(void* object, | |
| 59 const chromeos::PowerStatus& status); | |
| 60 | |
| 61 // This methods starts the monitoring of power changes. | |
| 62 void Init(); | |
| 63 | |
| 64 // Called by the handler to update the power status. | |
| 65 // This will notify all the Observers. | |
| 66 void UpdatePowerStatus(const chromeos::PowerStatus& status); | |
| 67 | |
| 68 ObserverList<Observer> observers_; | |
| 69 | |
| 70 // A reference to the battery power api, to allow callbacks when the battery | |
| 71 // status changes. | |
| 72 chromeos::PowerStatusConnection power_status_connection_; | |
| 73 | |
| 74 // The latest power status. | |
| 75 chromeos::PowerStatus status_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(CrosPowerLibrary); | |
| 78 }; | |
| 79 | |
| 80 #endif // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ | |
| OLD | NEW |