| 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 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 class TimeDelta; | 12 class TimeDelta; |
| 13 } | 13 } |
| 14 | 14 |
| 15 namespace chromeos { | 15 namespace chromeos { |
| 16 | 16 |
| 17 typedef base::Callback<void(int64_t)> CalculateIdleTimeCallback; | 17 typedef base::Callback<void(int64_t)> CalculateIdleTimeCallback; |
| 18 struct PowerStatus; |
| 18 | 19 |
| 19 // This interface defines interaction with the ChromeOS power library APIs. | 20 // This interface defines interaction with the ChromeOS power library APIs. |
| 20 // Classes can add themselves as observers. Users can get an instance of this | 21 // Classes can add themselves as observers. Users can get an instance of this |
| 21 // library class like this: chromeos::CrosLibrary::Get()->GetPowerLibrary() | 22 // library class like this: chromeos::CrosLibrary::Get()->GetPowerLibrary() |
| 22 class PowerLibrary { | 23 class PowerLibrary { |
| 23 public: | 24 public: |
| 24 class Observer { | 25 class Observer { |
| 25 public: | 26 public: |
| 26 virtual void PowerChanged(PowerLibrary* obj) = 0; | 27 virtual void PowerChanged(const PowerStatus& status) = 0; |
| 27 virtual void SystemResumed() = 0; | 28 virtual void SystemResumed() = 0; |
| 28 | 29 |
| 29 protected: | 30 protected: |
| 30 virtual ~Observer() {} | 31 virtual ~Observer() {} |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 virtual ~PowerLibrary() {} | 34 virtual ~PowerLibrary() {} |
| 34 | 35 |
| 35 virtual void Init() = 0; | 36 virtual void Init() = 0; |
| 36 | 37 |
| 37 virtual void AddObserver(Observer* observer) = 0; | 38 virtual void AddObserver(Observer* observer) = 0; |
| 38 virtual void RemoveObserver(Observer* observer) = 0; | 39 virtual void RemoveObserver(Observer* observer) = 0; |
| 39 | 40 |
| 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, | 41 // Calculates idle time asynchronously. If it encounters some error, |
| 59 // it returns -1. | 42 // it returns -1. |
| 60 virtual void CalculateIdleTime(CalculateIdleTimeCallback* callback) = 0; | 43 virtual void CalculateIdleTime(CalculateIdleTimeCallback* callback) = 0; |
| 61 | 44 |
| 62 // Enable/disable screen lock for current session. | 45 // Enable/disable screen lock for current session. |
| 63 virtual void EnableScreenLock(bool enable) = 0; | 46 virtual void EnableScreenLock(bool enable) = 0; |
| 64 | 47 |
| 65 // Requests restart of the system. | 48 // Requests restart of the system. |
| 66 virtual void RequestRestart() = 0; | 49 virtual void RequestRestart() = 0; |
| 67 | 50 |
| 68 // Requests shutdown of the system. | 51 // Requests shutdown of the system. |
| 69 virtual void RequestShutdown() = 0; | 52 virtual void RequestShutdown() = 0; |
| 70 | 53 |
| 71 // UI initiated request for status update. | 54 // UI initiated request for status update. |
| 72 virtual void RequestStatusUpdate() = 0; | 55 virtual void RequestStatusUpdate() = 0; |
| 73 | 56 |
| 74 // Factory function, creates a new instance and returns ownership. | 57 // Factory function, creates a new instance and returns ownership. |
| 75 // For normal usage, access the singleton via CrosLibrary::Get(). | 58 // For normal usage, access the singleton via CrosLibrary::Get(). |
| 76 static PowerLibrary* GetImpl(bool stub); | 59 static PowerLibrary* GetImpl(bool stub); |
| 77 }; | 60 }; |
| 78 | 61 |
| 79 } // namespace chromeos | 62 } // namespace chromeos |
| 80 | 63 |
| 81 #endif // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ | 64 #endif // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ |
| OLD | NEW |