Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Unified Diff: components/download/internal/scheduler/battery_listener.h

Issue 2867073004: Battery listener for download service in native code. (Closed)
Patch Set: Work on feedbacks. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/download/internal/BUILD.gn ('k') | components/download/internal/scheduler/battery_listener.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/download/internal/scheduler/battery_listener.h
diff --git a/components/download/internal/scheduler/battery_listener.h b/components/download/internal/scheduler/battery_listener.h
new file mode 100644
index 0000000000000000000000000000000000000000..2ddc6109b55f1567508d63a0909351485b102bc5
--- /dev/null
+++ b/components/download/internal/scheduler/battery_listener.h
@@ -0,0 +1,59 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_DOWNLOAD_INTERNAL_SCHEDULER_BATTERY_LISTENER_H_
+#define COMPONENTS_DOWNLOAD_INTERNAL_SCHEDULER_BATTERY_LISTENER_H_
+
+#include <memory>
+
+#include "base/observer_list.h"
+#include "base/power_monitor/power_observer.h"
+#include "components/download/public/download_params.h"
+
+namespace download {
+
+// Listen to battery charing state changes and notify observers in download
+// service.
+// TODO(xingliu): Converts to device service when it's fully done.
+class BatteryListener : public base::PowerObserver {
+ public:
+ class Observer {
+ public:
+ // Called when certain battery requirements are meet.
+ virtual void OnBatteryChange(
+ SchedulingParams::BatteryRequirements battery_status) = 0;
+ };
+
+ BatteryListener();
+ ~BatteryListener() override;
+
+ // Retrieves the current minimum battery requirement.
+ SchedulingParams::BatteryRequirements CurrentBatteryStatus() const;
+
+ // Start to listen to battery change.
+ void Start();
+
+ // Stop to listen to battery change.
+ void Stop();
+
+ // Adds/Removes observers.
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ private:
+ // base::PowerObserver implementation.
+ void OnPowerStateChange(bool on_battery_power) override;
+
+ // Notifies |observers_| about battery requirement change.
+ void NotifyBatteryChange(SchedulingParams::BatteryRequirements);
+
+ // Observers to monitor battery change in download service.
+ base::ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(BatteryListener);
+};
+
+} // namespace download
+
+#endif // COMPONENTS_DOWNLOAD_INTERNAL_SCHEDULER_BATTERY_LISTENER_H_
« no previous file with comments | « components/download/internal/BUILD.gn ('k') | components/download/internal/scheduler/battery_listener.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698