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.
5 #include "content/renderer/device_sensors/device_light_event_pump.h"
7 #include "content/common/device_sensors/device_light_messages.h"
8 #include "content/public/renderer/render_thread.h"
9 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h"
12 // Default delay between subsequent firing of DeviceLight events.
13 const int kDefaultLightPumpDelayMillis
= 200;
18 DeviceLightEventPump::DeviceLightEventPump(RenderThread
* thread
)
19 : DeviceSensorEventPump
<blink::WebDeviceLightListener
>(thread
),
21 pump_delay_millis_
= kDefaultLightPumpDelayMillis
;
24 DeviceLightEventPump::~DeviceLightEventPump() {
27 bool DeviceLightEventPump::OnControlMessageReceived(
28 const IPC::Message
& message
) {
30 IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump
, message
)
31 IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling
, OnDidStart
)
32 IPC_MESSAGE_UNHANDLED(handled
= false)
37 void DeviceLightEventPump::FireEvent() {
40 bool did_return_light_data
= reader_
->GetLatestData(&data
);
41 if (did_return_light_data
&& data
.value
!= last_seen_data_
) {
42 last_seen_data_
= data
.value
;
43 listener()->didChangeDeviceLight(data
.value
);
47 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle
) {
49 reader_
.reset(new DeviceLightSharedMemoryReader());
50 return reader_
->Initialize(handle
);
53 void DeviceLightEventPump::SendStartMessage() {
54 RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling());
57 void DeviceLightEventPump::SendStopMessage() {
59 RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling());
62 void DeviceLightEventPump::SendFakeDataForTesting(void* fake_data
) {
63 double data
= *static_cast<double*>(fake_data
);
65 listener()->didChangeDeviceLight(data
);
68 } // namespace content