OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "platform/battery/battery_dispatcher_proxy.h" | |
6 | |
7 #include "platform/battery/battery_status.h" | |
8 #include "platform/threading/BindForMojo.h" | |
9 #include "public/platform/Platform.h" | |
10 #include "wtf/Assertions.h" | |
11 | |
12 namespace blink { | |
13 | |
14 BatteryDispatcherProxy::BatteryDispatcherProxy(Listener* listener) | |
15 : listener_(listener) { | |
16 ASSERT(listener_); | |
17 } | |
18 | |
19 BatteryDispatcherProxy::~BatteryDispatcherProxy() {} | |
20 | |
21 void BatteryDispatcherProxy::StartListening() { | |
22 ASSERT(!monitor_.is_bound()); | |
23 Platform::current()->connectToRemoteService(mojo::GetProxy(&monitor_)); | |
24 // monitor_ can be null during testing. | |
25 if (monitor_) | |
26 QueryNextStatus(); | |
27 } | |
28 | |
29 void BatteryDispatcherProxy::StopListening() { | |
30 // monitor_ can be null during testing. | |
31 if (monitor_) | |
32 monitor_.reset(); | |
33 } | |
34 | |
35 void BatteryDispatcherProxy::QueryNextStatus() { | |
36 monitor_->QueryNextStatus( | |
37 sameThreadBindForMojo(&BatteryDispatcherProxy::OnDidChange, this)); | |
38 } | |
39 | |
40 void BatteryDispatcherProxy::OnDidChange( | |
41 device::BatteryStatusPtr battery_status) { | |
42 // monitor_ can be null during testing. | |
43 if (monitor_) | |
44 QueryNextStatus(); | |
45 | |
46 DCHECK(battery_status); | |
47 | |
48 BatteryStatus status(battery_status->charging, | |
49 battery_status->charging_time, | |
50 battery_status->discharging_time, | |
51 battery_status->level); | |
52 listener_->OnUpdateBatteryStatus(status); | |
53 } | |
54 | |
55 } // namespace blink | |
OLD | NEW |