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 BindToRequest(new BatteryMonitorImpl(), &request); | 14 new BatteryMonitorImpl(request.Pass()); |
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)))) { |
18 } | 22 } |
19 | 23 |
20 BatteryMonitorImpl::~BatteryMonitorImpl() { | 24 BatteryMonitorImpl::~BatteryMonitorImpl() { |
21 } | 25 } |
22 | 26 |
23 void BatteryMonitorImpl::OnConnectionEstablished() { | 27 void BatteryMonitorImpl::RegisterSubscription() { |
24 subscription_ = BatteryStatusService::GetInstance()->AddCallback( | |
25 base::Bind(&BatteryMonitorImpl::DidChange, base::Unretained(this))); | |
26 } | 28 } |
27 | 29 |
28 void BatteryMonitorImpl::DidChange(const BatteryStatus& battery_status) { | 30 void BatteryMonitorImpl::DidChange(const BatteryStatus& battery_status) { |
29 BatteryStatusPtr status(BatteryStatus::New()); | 31 BatteryStatusPtr status(BatteryStatus::New()); |
30 *status = battery_status; | 32 *status = battery_status; |
31 client()->DidChange(status.Pass()); | 33 binding_.client()->DidChange(status.Pass()); |
32 } | 34 } |
33 | 35 |
34 } // namespace device | 36 } // namespace device |
OLD | NEW |