| 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..e7f01a13813da2d509e8d7a60feb5ca2e0777c08 100644
|
| --- a/third_party/WebKit/Source/modules/battery/BatteryDispatcher.cpp
|
| +++ b/third_party/WebKit/Source/modules/battery/BatteryDispatcher.cpp
|
| @@ -4,28 +4,10 @@
|
|
|
| #include "modules/battery/BatteryDispatcher.h"
|
|
|
| -#include "modules/battery/BatteryStatus.h"
|
| -#include "public/platform/Platform.h"
|
| +#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 +15,7 @@ BatteryDispatcher& BatteryDispatcher::instance()
|
| }
|
|
|
| BatteryDispatcher::BatteryDispatcher()
|
| + : m_hasLatestData(false)
|
| {
|
| }
|
|
|
| @@ -40,34 +23,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_batteryStatusDispatcher = adoptPtr(new BatteryStatusDispatcher(this));
|
| }
|
|
|
| void BatteryDispatcher::stopListening()
|
| {
|
| - Platform::current()->stopListening(WebPlatformEventTypeBattery);
|
| - m_batteryStatus.clear();
|
| + m_batteryStatusDispatcher.clear();
|
| + m_hasLatestData = false;
|
| }
|
|
|
| } // namespace blink
|
|
|