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

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: null event test case 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 == std::numeric_limits<double>::infinity()) {
51 // no data can be provided, this is a null event.
timvolodine 2014/09/10 13:47:25 nit: strictly speaking it's not a null event, some
riju_ 2014/09/22 08:22:21 Done.
52 return true;
53 }
54
55 return lux != last_seen_data_;
56 }
57
47 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) { 58 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) {
48 if (!reader_) 59 if (!reader_)
49 reader_.reset(new DeviceLightSharedMemoryReader()); 60 reader_.reset(new DeviceLightSharedMemoryReader());
50 return reader_->Initialize(handle); 61 return reader_->Initialize(handle);
51 } 62 }
52 63
53 void DeviceLightEventPump::SendStartMessage() { 64 void DeviceLightEventPump::SendStartMessage() {
54 RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling()); 65 RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling());
55 } 66 }
56 67
57 void DeviceLightEventPump::SendStopMessage() { 68 void DeviceLightEventPump::SendStopMessage() {
58 last_seen_data_ = -1; 69 last_seen_data_ = -1;
59 RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling()); 70 RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling());
60 } 71 }
61 72
62 void DeviceLightEventPump::SendFakeDataForTesting(void* fake_data) { 73 void DeviceLightEventPump::SendFakeDataForTesting(void* fake_data) {
63 double data = *static_cast<double*>(fake_data); 74 double data = *static_cast<double*>(fake_data);
64 75
65 listener()->didChangeDeviceLight(data); 76 listener()->didChangeDeviceLight(data);
66 } 77 }
67 78
68 } // namespace content 79 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698