OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 COMPONENTS_DOWNLOAD_INTERNAL_SCHEDULER_BATTERY_LISTENER_H_ |
| 6 #define COMPONENTS_DOWNLOAD_INTERNAL_SCHEDULER_BATTERY_LISTENER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/observer_list.h" |
| 11 #include "base/power_monitor/power_observer.h" |
| 12 #include "components/download/public/download_params.h" |
| 13 |
| 14 namespace download { |
| 15 |
| 16 // Listen to battery charing state changes and notify observers in download |
| 17 // service. |
| 18 // TODO(xingliu): Converts to device service when it's fully done. |
| 19 class BatteryListener : public base::PowerObserver { |
| 20 public: |
| 21 class Observer { |
| 22 public: |
| 23 // Called when certain battery requirements are meet. |
| 24 virtual void OnBatteryChange( |
| 25 SchedulingParams::BatteryRequirements battery_status) = 0; |
| 26 }; |
| 27 |
| 28 BatteryListener(); |
| 29 ~BatteryListener() override; |
| 30 |
| 31 // Retrieves the current minimum battery requirement. |
| 32 SchedulingParams::BatteryRequirements CurrentBatteryStatus() const; |
| 33 |
| 34 // Start to listen to battery change. |
| 35 void Start(); |
| 36 |
| 37 // Stop to listen to battery change. |
| 38 void Stop(); |
| 39 |
| 40 // Adds/Removes observers. |
| 41 void AddObserver(Observer* observer); |
| 42 void RemoveObserver(Observer* observer); |
| 43 |
| 44 private: |
| 45 // base::PowerObserver implementation. |
| 46 void OnPowerStateChange(bool on_battery_power) override; |
| 47 |
| 48 // Notifies |observers_| about battery requirement change. |
| 49 void NotifyBatteryChange(SchedulingParams::BatteryRequirements); |
| 50 |
| 51 // Observers to monitor battery change in download service. |
| 52 base::ObserverList<Observer> observers_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(BatteryListener); |
| 55 }; |
| 56 |
| 57 } // namespace download |
| 58 |
| 59 #endif // COMPONENTS_DOWNLOAD_INTERNAL_SCHEDULER_BATTERY_LISTENER_H_ |
OLD | NEW |