1 // Copyright 2015 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.
5 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_POWER_OBSERVER_H_
6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_POWER_OBSERVER_H_
9 #include "base/power_monitor/power_observer.h"
10 #include "content/browser/background_sync/background_sync.pb.h"
11 #include "content/common/content_export.h"
15 // BackgroundSyncPowerObserver monitors the charging status of the device and
16 // determines if the power conditions of BackgroundSyncRegistrations are met.
17 class CONTENT_EXPORT BackgroundSyncPowerObserver
: public base::PowerObserver
{
19 // Creates a BackgroundSyncPowerObserver. |power_callback| is run when the
20 // battery states changes asynchronously via PostMessage.
21 explicit BackgroundSyncPowerObserver(const base::Closure
& power_callback
);
23 ~BackgroundSyncPowerObserver() override
;
25 // Returns true if the state of the battery (charging or not) meets the needs
27 bool PowerSufficient(SyncPowerState power_state
) const;
30 friend class BackgroundSyncPowerObserverTest
;
32 // PowerObserver overrides
33 void OnPowerStateChange(bool on_battery_power
) override
;
35 // |observing_power_monitor_| is true when the constructor is able to find and
36 // register an observer with the base::PowerMonitor. This should always be
37 // true except for tests in which the browser initialization isn't done.
38 bool observing_power_monitor_
;
42 // The callback to run when the battery state changes.
43 base::Closure power_changed_callback_
;
45 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncPowerObserver
);
48 } // namespace content
50 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_POWER_OBSERVER_H_