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