Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(724)

Unified Diff: third_party/WebKit/Source/modules/battery/BatteryDispatcher.cpp

Issue 1740843002: Revert of Migrates battery_status from content/renderer/ to WebKit/platform/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 8a414accee6e851edd475579bf4bc75f270994ee..896d72deeedf1388859b8619e392544dd169096b 100644
--- a/third_party/WebKit/Source/modules/battery/BatteryDispatcher.cpp
+++ b/third_party/WebKit/Source/modules/battery/BatteryDispatcher.cpp
@@ -4,9 +4,27 @@
#include "modules/battery/BatteryDispatcher.h"
-#include "wtf/PassOwnPtr.h"
+#include "modules/battery/BatteryStatus.h"
+#include "public/platform/Platform.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()
{
@@ -15,8 +33,6 @@
}
BatteryDispatcher::BatteryDispatcher()
- : m_hasLatestData(false)
- , m_batteryDispatcherProxy(adoptPtr(new BatteryDispatcherProxy(this)))
{
}
@@ -24,22 +40,34 @@
{
}
-void BatteryDispatcher::OnUpdateBatteryStatus(const BatteryStatus& batteryStatus)
+DEFINE_TRACE(BatteryDispatcher)
{
- m_batteryStatus = batteryStatus;
- m_hasLatestData = true;
+ 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));
notifyControllers();
+}
+
+BatteryStatus* BatteryDispatcher::latestData()
+{
+ return m_batteryStatus.get();
}
void BatteryDispatcher::startListening()
{
- m_batteryDispatcherProxy->StartListening();
+ Platform::current()->startListening(WebPlatformEventTypeBattery, this);
}
void BatteryDispatcher::stopListening()
{
- m_batteryDispatcherProxy->StopListening();
- m_hasLatestData = false;
+ Platform::current()->stopListening(WebPlatformEventTypeBattery);
+ m_batteryStatus.clear();
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698