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

Unified Diff: third_party/WebKit/Source/modules/device_light/DeviceLightDispatcher.cpp

Issue 2772843002: [DeviceLight] Ensure to round lux value to avoid fingerprinting risk. (Closed)
Patch Set: fix compile Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/LayoutTests/ambient-light/rounded-lux-value-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 19d9bc54f8986d181a567cbaf2b12a05a2de28df..3d6a1ee76b542d75fee2637862742c10f34a5968 100644
--- a/third_party/WebKit/Source/modules/device_light/DeviceLightDispatcher.cpp
+++ b/third_party/WebKit/Source/modules/device_light/DeviceLightDispatcher.cpp
@@ -4,9 +4,22 @@
#include "modules/device_light/DeviceLightDispatcher.h"
+#include <cmath>
+
#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.
+ // TODO(timvolodine): consider reducing the lux value precision further.
+ return std::isinf(lux) ? lux : std::round(lux);
+}
+} // namespace
+
namespace blink {
DeviceLightDispatcher& DeviceLightDispatcher::Instance() {
@@ -33,8 +46,11 @@ void DeviceLightDispatcher::StopListening() {
}
void DeviceLightDispatcher::DidChangeDeviceLight(double value) {
- last_device_light_data_ = value;
- NotifyControllers();
+ double newValue = EnsureRoundedLuxValue(value);
+ if (last_device_light_data_ != newValue) {
+ last_device_light_data_ = newValue;
+ NotifyControllers();
+ }
}
double DeviceLightDispatcher::LatestDeviceLightData() const {
« no previous file with comments | « third_party/WebKit/LayoutTests/ambient-light/rounded-lux-value-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698