OLD | NEW |
---|---|
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 |
11 namespace { | 11 namespace { |
12 // Default delay between subsequent firing of DeviceLight events. | 12 // Default delay between subsequent firing of DeviceLight events. |
13 const int kDefaultLightPumpDelayMillis = 200; | 13 const int kDefaultLightPumpDelayMillis = 199; |
timvolodine
2014/09/04 17:16:58
why not 200?
| |
14 } // namespace | 14 } // namespace |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 DeviceLightEventPump::DeviceLightEventPump(RenderThread* thread) | 18 DeviceLightEventPump::DeviceLightEventPump(RenderThread* thread) |
19 : DeviceSensorEventPump<blink::WebDeviceLightListener>(thread), | 19 : DeviceSensorEventPump<blink::WebDeviceLightListener>(thread), |
20 last_seen_data_(-1) { | 20 last_seen_data_(-1) { |
21 pump_delay_millis_ = kDefaultLightPumpDelayMillis; | 21 pump_delay_millis_ = kDefaultLightPumpDelayMillis; |
22 } | 22 } |
23 | 23 |
24 DeviceLightEventPump::~DeviceLightEventPump() { | 24 DeviceLightEventPump::~DeviceLightEventPump() { |
25 } | 25 } |
26 | 26 |
27 bool DeviceLightEventPump::OnControlMessageReceived( | 27 bool DeviceLightEventPump::OnControlMessageReceived( |
28 const IPC::Message& message) { | 28 const IPC::Message& message) { |
29 bool handled = true; | 29 bool handled = true; |
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 bool did_return_light_data = reader_->GetLatestData(&data); |
41 if (did_return_light_data && data.value != last_seen_data_) { | 41 // It seems that we need to fire multiple times to blink to get 1 NULL |
timvolodine
2014/09/04 17:16:58
remove comment
riju_
2014/09/08 09:26:18
Done.
| |
42 // event. +inf = no sensors | |
43 if ((did_return_light_data && data.value != last_seen_data_) || | |
44 data.value == std::numeric_limits<double>::infinity()) { | |
timvolodine
2014/09/04 17:16:58
this does not look right.
you could do reader_->Ge
timvolodine
2014/09/04 17:16:58
also I am not sure if negative values could be fir
riju_
2014/09/08 09:26:18
Done.
| |
42 last_seen_data_ = data.value; | 45 last_seen_data_ = data.value; |
43 listener()->didChangeDeviceLight(data.value); | 46 listener()->didChangeDeviceLight(data.value); |
44 } | 47 } |
45 } | 48 } |
46 | 49 |
47 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) { | 50 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) { |
48 if (!reader_) | 51 if (!reader_) |
49 reader_.reset(new DeviceLightSharedMemoryReader()); | 52 reader_.reset(new DeviceLightSharedMemoryReader()); |
50 return reader_->Initialize(handle); | 53 return reader_->Initialize(handle); |
51 } | 54 } |
52 | 55 |
53 void DeviceLightEventPump::SendStartMessage() { | 56 void DeviceLightEventPump::SendStartMessage() { |
54 RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling()); | 57 RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling()); |
55 } | 58 } |
56 | 59 |
57 void DeviceLightEventPump::SendStopMessage() { | 60 void DeviceLightEventPump::SendStopMessage() { |
58 last_seen_data_ = -1; | 61 last_seen_data_ = -1; |
59 RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling()); | 62 RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling()); |
60 } | 63 } |
61 | 64 |
62 void DeviceLightEventPump::SendFakeDataForTesting(void* fake_data) { | 65 void DeviceLightEventPump::SendFakeDataForTesting(void* fake_data) { |
63 double data = *static_cast<double*>(fake_data); | 66 double data = *static_cast<double*>(fake_data); |
64 | 67 |
65 listener()->didChangeDeviceLight(data); | 68 listener()->didChangeDeviceLight(data); |
66 } | 69 } |
67 | 70 |
68 } // namespace content | 71 } // namespace content |
OLD | NEW |