Chromium Code Reviews| Index: third_party/WebKit/Source/platform/battery/BatteryStatusDispatcher.cpp | 
| diff --git a/third_party/WebKit/Source/platform/battery/BatteryStatusDispatcher.cpp b/third_party/WebKit/Source/platform/battery/BatteryStatusDispatcher.cpp | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..ad2c5b4c55637d3490b28becf9832d0dad6b7638 | 
| --- /dev/null | 
| +++ b/third_party/WebKit/Source/platform/battery/BatteryStatusDispatcher.cpp | 
| @@ -0,0 +1,46 @@ | 
| +// Copyright 2014 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "platform/battery/BatteryStatusDispatcher.h" | 
| + | 
| +#include "platform/base/Bind.h" | 
| +#include "platform/battery/BatteryStatus.h" | 
| +#include "platform/battery/BatteryStatusListener.h" | 
| +#include "public/platform/Platform.h" | 
| +#include "wtf/Assertions.h" | 
| + | 
| +namespace blink { | 
| + | 
| +BatteryStatusDispatcher::BatteryStatusDispatcher(BatteryStatusListener* listener) | 
| + : m_listener(listener) | 
| +{ | 
| + ASSERT(m_listener); | 
| + | 
| + Platform::current()->connectToRemoteService(mojo::GetProxy(&m_monitor)); | 
| + // m_monitor can be null during testing. | 
| + if (m_monitor) | 
| + queryNextStatus(); | 
| +} | 
| + | 
| +BatteryStatusDispatcher::~BatteryStatusDispatcher() {} | 
| + | 
| +void BatteryStatusDispatcher::queryNextStatus() | 
| +{ | 
| + m_monitor->QueryNextStatus( | 
| + 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
 
 | 
| +} | 
| + | 
| +void BatteryStatusDispatcher::onDidChange(device::BatteryStatusPtr batteryStatus) | 
| +{ | 
| + // m_monitor can be null during testing. | 
| + if (m_monitor) | 
| + queryNextStatus(); | 
| + | 
| + DCHECK(batteryStatus); | 
| + | 
| + BatteryStatus status(batteryStatus->charging, batteryStatus->charging_time, batteryStatus->discharging_time, batteryStatus->level); | 
| + m_listener->onUpdateBatteryStatus(status); | 
| +} | 
| + | 
| +} // namespace blink |