1 // Copyright 2014 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 #include "device/battery/battery_monitor_impl.h"
8 #include "base/logging.h"
13 void BatteryMonitorImpl::Create(
14 mojo::InterfaceRequest
<BatteryMonitor
> request
) {
15 new BatteryMonitorImpl(request
.Pass());
18 BatteryMonitorImpl::BatteryMonitorImpl(
19 mojo::InterfaceRequest
<BatteryMonitor
> request
)
20 : binding_(this, request
.Pass()),
21 status_to_report_(false) {
22 // NOTE: DidChange may be called before AddCallback returns. This is done to
23 // report current status.
24 subscription_
= BatteryStatusService::GetInstance()->AddCallback(
25 base::Bind(&BatteryMonitorImpl::DidChange
, base::Unretained(this)));
28 BatteryMonitorImpl::~BatteryMonitorImpl() {
31 void BatteryMonitorImpl::QueryNextStatus(
32 const BatteryStatusCallback
& callback
) {
33 if (!callback_
.is_null()) {
34 DVLOG(1) << "Overlapped call to QueryNextStatus!";
40 if (status_to_report_
)
44 void BatteryMonitorImpl::RegisterSubscription() {
47 void BatteryMonitorImpl::DidChange(const BatteryStatus
& battery_status
) {
48 status_
= battery_status
;
49 status_to_report_
= true;
51 if (!callback_
.is_null())
55 void BatteryMonitorImpl::ReportStatus() {
56 callback_
.Run(status_
.Clone());
59 status_to_report_
= false;