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

Side by Side Diff: third_party/WebKit/Source/modules/device_light/DeviceLightDispatcher.cpp

Issue 2845763002: Remove DeviceLightEvent implementation (Closed)
Patch Set: same as previous patch Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "modules/device_light/DeviceLightDispatcher.h"
6
7 #include <cmath>
8
9 #include "modules/device_light/DeviceLightController.h"
10 #include "public/platform/Platform.h"
11
12 namespace {
13 double EnsureRoundedLuxValue(double lux) {
14 // Make sure to round the lux value to nearest integer, to
15 // avoid too precise values and hence reduce fingerprinting risk.
16 // The special case when the lux value is infinity (no data can be
17 // provided) is simply returned as is.
18 // TODO(timvolodine): consider reducing the lux value precision further.
19 return std::isinf(lux) ? lux : std::round(lux);
20 }
21 } // namespace
22
23 namespace blink {
24
25 DeviceLightDispatcher& DeviceLightDispatcher::Instance() {
26 DEFINE_STATIC_LOCAL(DeviceLightDispatcher, device_light_dispatcher,
27 (new DeviceLightDispatcher));
28 return device_light_dispatcher;
29 }
30
31 DeviceLightDispatcher::DeviceLightDispatcher() : last_device_light_data_(-1) {}
32
33 DeviceLightDispatcher::~DeviceLightDispatcher() {}
34
35 DEFINE_TRACE(DeviceLightDispatcher) {
36 PlatformEventDispatcher::Trace(visitor);
37 }
38
39 void DeviceLightDispatcher::StartListening() {
40 Platform::Current()->StartListening(kWebPlatformEventTypeDeviceLight, this);
41 }
42
43 void DeviceLightDispatcher::StopListening() {
44 Platform::Current()->StopListening(kWebPlatformEventTypeDeviceLight);
45 last_device_light_data_ = -1;
46 }
47
48 void DeviceLightDispatcher::DidChangeDeviceLight(double value) {
49 double newValue = EnsureRoundedLuxValue(value);
50 if (last_device_light_data_ != newValue) {
51 last_device_light_data_ = newValue;
52 NotifyControllers();
53 }
54 }
55
56 double DeviceLightDispatcher::LatestDeviceLightData() const {
57 return last_device_light_data_;
58 }
59
60 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698