Chromium Code Reviews| Index: third_party/WebKit/Source/modules/battery/BatteryDispatcher.cpp |
| diff --git a/third_party/WebKit/Source/modules/battery/BatteryDispatcher.cpp b/third_party/WebKit/Source/modules/battery/BatteryDispatcher.cpp |
| index 896d72deeedf1388859b8619e392544dd169096b..8a2fa4996000576fa7667f57d646c5dd716099ce 100644 |
| --- a/third_party/WebKit/Source/modules/battery/BatteryDispatcher.cpp |
| +++ b/third_party/WebKit/Source/modules/battery/BatteryDispatcher.cpp |
| @@ -4,28 +4,11 @@ |
| #include "modules/battery/BatteryDispatcher.h" |
| -#include "modules/battery/BatteryStatus.h" |
| -#include "public/platform/Platform.h" |
| +#include "platform/battery/battery_dispatcher_proxy.h" |
|
kinuko
2016/02/18 00:50:53
nit: not needed (it's in header file)
Yuki
2016/02/18 06:05:14
Done.
|
| +#include "wtf/PassOwnPtr.h" |
| namespace blink { |
| -namespace { |
| - |
| -double ensureTwoSignificantDigits(double level) |
| -{ |
| - // Convert battery level value which should be in [0, 1] to a value in [0, 1] |
| - // with 2 digits of precision. This is to provide a consistent experience |
| - // across platforms (e.g. on Mac and Android the battery changes are generally |
| - // reported with 1% granularity). It also serves the purpose of reducing the |
| - // possibility of fingerprinting and triggers less level change events on |
| - // platforms where the granularity is high. |
| - ASSERT(level >= 0 && level <= 1); |
| - return round(level * 100) / 100.f; |
| -} |
| - |
| -} // namespace |
| - |
| - |
| BatteryDispatcher& BatteryDispatcher::instance() |
| { |
| DEFINE_STATIC_LOCAL(Persistent<BatteryDispatcher>, batteryDispatcher, (new BatteryDispatcher())); |
| @@ -33,6 +16,8 @@ BatteryDispatcher& BatteryDispatcher::instance() |
| } |
| BatteryDispatcher::BatteryDispatcher() |
| + : m_hasLatestData(false) |
| + , m_batteryDispatcherProxy(adoptPtr(new BatteryDispatcherProxy(this))) |
| { |
| } |
| @@ -40,34 +25,22 @@ BatteryDispatcher::~BatteryDispatcher() |
| { |
| } |
| -DEFINE_TRACE(BatteryDispatcher) |
| +void BatteryDispatcher::OnUpdateBatteryStatus(const BatteryStatus& batteryStatus) |
| { |
| - visitor->trace(m_batteryStatus); |
| - PlatformEventDispatcher::trace(visitor); |
| -} |
| - |
| -void BatteryDispatcher::updateBatteryStatus(const WebBatteryStatus& batteryStatus) |
| -{ |
| - m_batteryStatus = BatteryStatus::create( |
| - batteryStatus.charging, batteryStatus.chargingTime, batteryStatus.dischargingTime, |
| - ensureTwoSignificantDigits(batteryStatus.level)); |
| + m_batteryStatus = batteryStatus; |
| + m_hasLatestData = true; |
| notifyControllers(); |
| } |
| -BatteryStatus* BatteryDispatcher::latestData() |
| -{ |
| - return m_batteryStatus.get(); |
| -} |
| - |
| void BatteryDispatcher::startListening() |
| { |
| - Platform::current()->startListening(WebPlatformEventTypeBattery, this); |
| + m_batteryDispatcherProxy->StartListening(); |
| } |
| void BatteryDispatcher::stopListening() |
| { |
| - Platform::current()->stopListening(WebPlatformEventTypeBattery); |
| - m_batteryStatus.clear(); |
| + m_batteryDispatcherProxy->StopListening(); |
| + m_hasLatestData = false; |
| } |
| } // namespace blink |