OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "device/battery/battery_monitor_impl.h" | 5 #include "device/battery/battery_monitor_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 | 8 |
9 namespace device { | 9 namespace device { |
10 | 10 |
11 // static | 11 // static |
12 void BatteryMonitorImpl::Create( | 12 void BatteryMonitorImpl::Create( |
13 mojo::InterfaceRequest<BatteryMonitor> request) { | 13 mojo::InterfaceRequest<BatteryMonitor> request) { |
14 new BatteryMonitorImpl(request.Pass()); | 14 BindToRequest(new BatteryMonitorImpl(), &request); |
15 } | 15 } |
16 | 16 |
17 BatteryMonitorImpl::BatteryMonitorImpl( | 17 BatteryMonitorImpl::BatteryMonitorImpl() { |
18 mojo::InterfaceRequest<BatteryMonitor> request) | |
19 : binding_(this, request.Pass()), | |
20 subscription_(BatteryStatusService::GetInstance()->AddCallback( | |
21 base::Bind(&BatteryMonitorImpl::DidChange, base::Unretained(this)))) { | |
22 } | 18 } |
23 | 19 |
24 BatteryMonitorImpl::~BatteryMonitorImpl() { | 20 BatteryMonitorImpl::~BatteryMonitorImpl() { |
25 } | 21 } |
26 | 22 |
27 void BatteryMonitorImpl::RegisterSubscription() { | 23 void BatteryMonitorImpl::OnConnectionEstablished() { |
| 24 subscription_ = BatteryStatusService::GetInstance()->AddCallback( |
| 25 base::Bind(&BatteryMonitorImpl::DidChange, base::Unretained(this))); |
28 } | 26 } |
29 | 27 |
30 void BatteryMonitorImpl::DidChange(const BatteryStatus& battery_status) { | 28 void BatteryMonitorImpl::DidChange(const BatteryStatus& battery_status) { |
31 BatteryStatusPtr status(BatteryStatus::New()); | 29 BatteryStatusPtr status(BatteryStatus::New()); |
32 *status = battery_status; | 30 *status = battery_status; |
33 binding_.client()->DidChange(status.Pass()); | 31 client()->DidChange(status.Pass()); |
34 } | 32 } |
35 | 33 |
36 } // namespace device | 34 } // namespace device |
OLD | NEW |