Chromium Code Reviews| 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/BatteryStatusDispatcher.h" | |
| 6 | |
| 7 #include "platform/base/Bind.h" | |
| 8 #include "platform/battery/BatteryStatus.h" | |
| 9 #include "platform/battery/BatteryStatusListener.h" | |
| 10 #include "public/platform/Platform.h" | |
| 11 #include "wtf/Assertions.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 BatteryStatusDispatcher::BatteryStatusDispatcher(BatteryStatusListener* listener ) | |
| 16 : m_listener(listener) | |
| 17 { | |
| 18 ASSERT(m_listener); | |
| 19 | |
| 20 Platform::current()->connectToRemoteService(mojo::GetProxy(&m_monitor)); | |
| 21 // m_monitor can be null during testing. | |
| 22 if (m_monitor) | |
| 23 queryNextStatus(); | |
| 24 } | |
| 25 | |
| 26 BatteryStatusDispatcher::~BatteryStatusDispatcher() {} | |
| 27 | |
| 28 void BatteryStatusDispatcher::queryNextStatus() | |
| 29 { | |
| 30 m_monitor->QueryNextStatus( | |
| 31 bindInstanceToMethod(&BatteryStatusDispatcher::onDidChange, this)); | |
|
haraken
2016/01/25 02:00:28
Why can't we just use WTF::bind?
Anand Mistry (off Chromium)
2016/01/25 06:00:24
Why use bind at all? This doesn't need to be threa
Yuki
2016/01/26 07:50:32
Note that base::Bind and WTF::bind are NOT compati
| |
| 32 } | |
| 33 | |
| 34 void BatteryStatusDispatcher::onDidChange(device::BatteryStatusPtr batteryStatus ) | |
| 35 { | |
| 36 // m_monitor can be null during testing. | |
| 37 if (m_monitor) | |
| 38 queryNextStatus(); | |
| 39 | |
| 40 DCHECK(batteryStatus); | |
| 41 | |
| 42 BatteryStatus status(batteryStatus->charging, batteryStatus->charging_time, batteryStatus->discharging_time, batteryStatus->level); | |
| 43 m_listener->onUpdateBatteryStatus(status); | |
| 44 } | |
| 45 | |
| 46 } // namespace blink | |
| OLD | NEW |