| 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_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 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 virtual double battery_percentage() const = 0; | 35 virtual double battery_percentage() const = 0; |
| 36 | 36 |
| 37 // Whether there is a battery present. | 37 // Whether there is a battery present. |
| 38 virtual bool battery_is_present() const = 0; | 38 virtual bool battery_is_present() const = 0; |
| 39 | 39 |
| 40 // The amount of time until battery is empty. | 40 // The amount of time until battery is empty. |
| 41 virtual base::TimeDelta battery_time_to_empty() const = 0; | 41 virtual base::TimeDelta battery_time_to_empty() const = 0; |
| 42 | 42 |
| 43 // The amount of time until battery is full. | 43 // The amount of time until battery is full. |
| 44 virtual base::TimeDelta battery_time_to_full() const = 0; | 44 virtual base::TimeDelta battery_time_to_full() const = 0; |
| 45 }; | |
| 46 | 45 |
| 47 | 46 // Get library implementation. |
| 48 // This class handles the interaction with the ChromeOS power library APIs. | 47 static PowerLibrary* GetImpl(bool stub); |
| 49 // Classes can add themselves as observers. Users can get an instance of this | |
| 50 // library class like this: PowerLibrary::Get() | |
| 51 class PowerLibraryImpl : public PowerLibrary { | |
| 52 public: | |
| 53 PowerLibraryImpl(); | |
| 54 virtual ~PowerLibraryImpl(); | |
| 55 | |
| 56 // PowerLibrary overrides. | |
| 57 virtual void AddObserver(Observer* observer); | |
| 58 virtual void RemoveObserver(Observer* observer); | |
| 59 | |
| 60 // Whether or not the line power is connected. | |
| 61 virtual bool line_power_on() const; | |
| 62 | |
| 63 // Whether or not the battery is fully charged.. | |
| 64 virtual bool battery_fully_charged() const; | |
| 65 | |
| 66 // The percentage (0-100) of remaining battery. | |
| 67 virtual double battery_percentage() const; | |
| 68 | |
| 69 // Whether there is a battery present. | |
| 70 virtual bool battery_is_present() const; | |
| 71 | |
| 72 // The amount of time until battery is empty. | |
| 73 virtual base::TimeDelta battery_time_to_empty() const; | |
| 74 | |
| 75 // The amount of time until battery is full. | |
| 76 virtual base::TimeDelta battery_time_to_full() const; | |
| 77 | |
| 78 private: | |
| 79 | |
| 80 // This method is called when there's a change in power status. | |
| 81 // This method is called on a background thread. | |
| 82 static void PowerStatusChangedHandler(void* object, | |
| 83 const chromeos::PowerStatus& status); | |
| 84 | |
| 85 // This methods starts the monitoring of power changes. | |
| 86 void Init(); | |
| 87 | |
| 88 // Called by the handler to update the power status. | |
| 89 // This will notify all the Observers. | |
| 90 void UpdatePowerStatus(const chromeos::PowerStatus& status); | |
| 91 | |
| 92 ObserverList<Observer> observers_; | |
| 93 | |
| 94 // A reference to the battery power api, to allow callbacks when the battery | |
| 95 // status changes. | |
| 96 chromeos::PowerStatusConnection power_status_connection_; | |
| 97 | |
| 98 // The latest power status. | |
| 99 chromeos::PowerStatus status_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(PowerLibraryImpl); | |
| 102 }; | 48 }; |
| 103 | 49 |
| 104 } // namespace chromeos | 50 } // namespace chromeos |
| 105 | 51 |
| 106 #endif // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ | 52 #endif // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ |
| OLD | NEW |