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