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

Side by Side Diff: content/renderer/device_sensors/device_light_event_pump.cc

Issue 292693004: [DeviceLight] Browser+java part (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Forgot some light bits removal from device_inertial_sensor_diagnostics.html Created 6 years, 3 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/device_sensors/device_light_event_pump.h" 5 #include "content/renderer/device_sensors/device_light_event_pump.h"
6 6
7 #include "content/common/device_sensors/device_light_messages.h" 7 #include "content/common/device_sensors/device_light_messages.h"
8 #include "content/public/renderer/render_thread.h" 8 #include "content/public/renderer/render_thread.h"
9 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h" 9 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h"
10 10
(...skipping 19 matching lines...) Expand all
30 IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump, message) 30 IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump, message)
31 IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart) 31 IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart)
32 IPC_MESSAGE_UNHANDLED(handled = false) 32 IPC_MESSAGE_UNHANDLED(handled = false)
33 IPC_END_MESSAGE_MAP() 33 IPC_END_MESSAGE_MAP()
34 return handled; 34 return handled;
35 } 35 }
36 36
37 void DeviceLightEventPump::FireEvent() { 37 void DeviceLightEventPump::FireEvent() {
38 DCHECK(listener()); 38 DCHECK(listener());
39 DeviceLightData data; 39 DeviceLightData data;
40 bool did_return_light_data = reader_->GetLatestData(&data); 40 if (reader_->GetLatestData(&data) && ShouldFireEvent(data.value)) {
41 if (did_return_light_data && data.value != last_seen_data_) {
42 last_seen_data_ = data.value; 41 last_seen_data_ = data.value;
43 listener()->didChangeDeviceLight(data.value); 42 listener()->didChangeDeviceLight(data.value);
44 } 43 }
45 } 44 }
46 45
46 bool DeviceLightEventPump::ShouldFireEvent(double lux) const {
47 if (lux < 0)
48 return false;
49
50 if (lux != last_seen_data_ || lux == std::numeric_limits<double>::infinity())
timvolodine 2014/09/08 15:20:19 could you add a comment regarding why infinity is
timvolodine 2014/09/08 15:20:19 also a unit test for this case would be desirable
riju_ 2014/09/09 14:01:18 Done.
riju_ 2014/09/09 14:01:18 Done.
51 return true;
52
53 return false;
54 }
55
47 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) { 56 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) {
48 if (!reader_) 57 if (!reader_)
49 reader_.reset(new DeviceLightSharedMemoryReader()); 58 reader_.reset(new DeviceLightSharedMemoryReader());
50 return reader_->Initialize(handle); 59 return reader_->Initialize(handle);
51 } 60 }
52 61
53 void DeviceLightEventPump::SendStartMessage() { 62 void DeviceLightEventPump::SendStartMessage() {
54 RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling()); 63 RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling());
55 } 64 }
56 65
57 void DeviceLightEventPump::SendStopMessage() { 66 void DeviceLightEventPump::SendStopMessage() {
58 last_seen_data_ = -1; 67 last_seen_data_ = -1;
59 RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling()); 68 RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling());
60 } 69 }
61 70
62 void DeviceLightEventPump::SendFakeDataForTesting(void* fake_data) { 71 void DeviceLightEventPump::SendFakeDataForTesting(void* fake_data) {
63 double data = *static_cast<double*>(fake_data); 72 double data = *static_cast<double*>(fake_data);
64 73
65 listener()->didChangeDeviceLight(data); 74 listener()->didChangeDeviceLight(data);
66 } 75 }
67 76
68 } // namespace content 77 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698