Chromium Code Reviews| Index: third_party/WebKit/Source/modules/device_light/DeviceLightDispatcher.cpp |
| diff --git a/third_party/WebKit/Source/modules/device_light/DeviceLightDispatcher.cpp b/third_party/WebKit/Source/modules/device_light/DeviceLightDispatcher.cpp |
| index 1629d9bce07305ed2901eb4b4b8a0a80022ef78a..f7d241748d4c93acc5816da64936a95cc4b42108 100644 |
| --- a/third_party/WebKit/Source/modules/device_light/DeviceLightDispatcher.cpp |
| +++ b/third_party/WebKit/Source/modules/device_light/DeviceLightDispatcher.cpp |
| @@ -4,9 +4,21 @@ |
| #include "modules/device_light/DeviceLightDispatcher.h" |
| +#include <math.h> |
| + |
| #include "modules/device_light/DeviceLightController.h" |
| #include "public/platform/Platform.h" |
| +namespace { |
| +double EnsureRoundedLuxValue(double lux) { |
| + // Make sure to round the lux value to nearest integer, to |
| + // avoid too precise values and hence reduce fingerprinting risk. |
| + // The special case when the lux value is infinity (no data can be |
| + // provided) is simply returned as is. |
| + return isinf(lux) ? lux : std::round(lux); |
|
palmer
2017/03/23 19:00:19
Apologies in advance for the drive-by. :)
A round
timvolodine
2017/04/20 01:34:30
Acknowledged.
|
| +} |
| +} // namespace |
| + |
| namespace blink { |
| DeviceLightDispatcher& DeviceLightDispatcher::instance() { |
| @@ -33,8 +45,11 @@ void DeviceLightDispatcher::stopListening() { |
| } |
| void DeviceLightDispatcher::didChangeDeviceLight(double value) { |
| - m_lastDeviceLightData = value; |
| - notifyControllers(); |
| + double newValue = EnsureRoundedLuxValue(value); |
| + if (m_lastDeviceLightData != newValue) { |
| + m_lastDeviceLightData = newValue; |
| + notifyControllers(); |
| + } |
| } |
| double DeviceLightDispatcher::latestDeviceLightData() const { |