Chromium Code Reviews| 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_messages.h" | |
| 8 #include "content/public/renderer/render_thread.h" | |
| 9 #include "third_party/WebKit/public/platform/WebDeviceLightListener.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 DeviceLightEventPump::DeviceLightEventPump() | |
| 14 : DeviceSensorEventPump(), listener_(0) { | |
| 15 } | |
| 16 | |
| 17 DeviceLightEventPump::DeviceLightEventPump(int pump_delay_millis) | |
| 18 : DeviceSensorEventPump(pump_delay_millis), listener_(0) { | |
| 19 } | |
| 20 | |
| 21 DeviceLightEventPump::~DeviceLightEventPump() { | |
| 22 } | |
| 23 | |
| 24 bool DeviceLightEventPump::SetListener( | |
| 25 blink::WebDeviceLightListener* listener) { | |
| 26 listener_ = listener; | |
| 27 return listener_ ? RequestStart() : Stop(); | |
| 28 } | |
| 29 | |
| 30 bool DeviceLightEventPump::OnControlMessageReceived( | |
| 31 const IPC::Message& message) { | |
| 32 bool handled = true; | |
| 33 IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump, message) | |
| 34 IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart) | |
| 35 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 36 IPC_END_MESSAGE_MAP() | |
| 37 return handled; | |
| 38 } | |
| 39 | |
| 40 void DeviceLightEventPump::FireEvent() { | |
| 41 DCHECK(listener_); | |
| 42 double data; | |
| 43 if (reader_->GetLatestData(&data)) | |
|
timvolodine
2014/05/21 18:24:12
if you are using the same infrastructure as motion
| |
| 44 listener_->didChangeDeviceLight(data); | |
| 45 } | |
| 46 | |
| 47 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) { | |
| 48 if (!reader_) | |
| 49 reader_.reset(new DeviceLightSharedMemoryReader()); | |
| 50 return reader_->Initialize(handle); | |
| 51 } | |
| 52 | |
| 53 bool DeviceLightEventPump::SendStartMessage() { | |
| 54 return RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling()); | |
| 55 } | |
| 56 | |
| 57 bool DeviceLightEventPump::SendStopMessage() { | |
| 58 return RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling()); | |
| 59 } | |
| 60 | |
| 61 } // namespace content | |
| OLD | NEW |