OLD | NEW |
---|---|
(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 "content/renderer/device_sensors/device_light_event_pump.h" | |
6 | |
7 #include "content/common/device_sensors/device_light_data.h" | |
timvolodine
2014/06/03 16:08:12
not needed if already included in device_light_eve
riju_
2014/06/05 19:50:00
Done. Now, I am forward declaring in .h and the in
| |
8 #include "content/common/device_sensors/device_light_messages.h" | |
9 #include "content/public/renderer/render_thread.h" | |
10 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h" | |
11 | |
12 namespace content { | |
13 | |
14 const int DeviceLightEventPump::kDefaultLightPumpDelayMillis = 200; | |
15 | |
16 DeviceLightEventPump::DeviceLightEventPump() | |
17 : DeviceSensorEventPump(kDefaultLightPumpDelayMillis), listener_(0) { | |
18 } | |
19 | |
20 DeviceLightEventPump::DeviceLightEventPump(int pump_delay_millis) | |
21 : DeviceSensorEventPump(pump_delay_millis), listener_(0) { | |
22 } | |
23 | |
24 DeviceLightEventPump::~DeviceLightEventPump() { | |
25 } | |
26 | |
27 bool DeviceLightEventPump::SetListener( | |
28 blink::WebDeviceLightListener* listener) { | |
29 listener_ = listener; | |
30 return listener_ ? RequestStart() : Stop(); | |
31 } | |
32 | |
33 bool DeviceLightEventPump::OnControlMessageReceived( | |
34 const IPC::Message& message) { | |
35 bool handled = true; | |
36 IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump, message) | |
37 IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart) | |
38 IPC_MESSAGE_UNHANDLED(handled = false) | |
39 IPC_END_MESSAGE_MAP() | |
40 return handled; | |
41 } | |
42 | |
43 void DeviceLightEventPump::FireEvent() { | |
44 DCHECK(listener_); | |
45 DeviceLightData data; | |
46 if (reader_->GetLatestData(&data) && data.valueIsUpdated) | |
47 listener_->didChangeDeviceLight(data.value); | |
48 } | |
49 | |
50 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) { | |
51 if (!reader_) | |
52 reader_.reset(new DeviceLightSharedMemoryReader()); | |
53 return reader_->Initialize(handle); | |
54 } | |
55 | |
56 bool DeviceLightEventPump::SendStartMessage() { | |
57 return RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling()); | |
58 } | |
59 | |
60 bool DeviceLightEventPump::SendStopMessage() { | |
61 return RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling()); | |
62 } | |
63 | |
64 } // namespace content | |
OLD | NEW |