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 { |
| 12 // Default delay between subsequent firing of DeviceLight events. |
| 13 const int kDefaultLightPumpDelayMillis = 200; |
| 14 } // namespace |
| 15 |
| 16 namespace content { |
| 17 |
| 18 DeviceLightEventPump::DeviceLightEventPump() |
| 19 : DeviceSensorEventPump(kDefaultLightPumpDelayMillis), |
| 20 listener_(NULL), |
| 21 last_seen_data_(-1) { |
| 22 } |
| 23 |
| 24 DeviceLightEventPump::DeviceLightEventPump(int pump_delay_millis) |
| 25 : DeviceSensorEventPump(pump_delay_millis), |
| 26 listener_(NULL), |
| 27 last_seen_data_(-1) { |
| 28 } |
| 29 |
| 30 DeviceLightEventPump::~DeviceLightEventPump() { |
| 31 } |
| 32 |
| 33 bool DeviceLightEventPump::SetListener( |
| 34 blink::WebDeviceLightListener* listener) { |
| 35 listener_ = listener; |
| 36 return listener_ ? RequestStart() : Stop(); |
| 37 } |
| 38 |
| 39 bool DeviceLightEventPump::OnControlMessageReceived( |
| 40 const IPC::Message& message) { |
| 41 bool handled = true; |
| 42 IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump, message) |
| 43 IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart) |
| 44 IPC_MESSAGE_UNHANDLED(handled = false) |
| 45 IPC_END_MESSAGE_MAP() |
| 46 return handled; |
| 47 } |
| 48 |
| 49 void DeviceLightEventPump::FireEvent() { |
| 50 DCHECK(listener_); |
| 51 DeviceLightData data; |
| 52 bool did_return_light_data = reader_->GetLatestData(&data); |
| 53 if (did_return_light_data && data.value != last_seen_data_) { |
| 54 last_seen_data_ = data.value; |
| 55 listener_->didChangeDeviceLight(data.value); |
| 56 } |
| 57 } |
| 58 |
| 59 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) { |
| 60 if (!reader_) |
| 61 reader_.reset(new DeviceLightSharedMemoryReader()); |
| 62 return reader_->Initialize(handle); |
| 63 } |
| 64 |
| 65 bool DeviceLightEventPump::SendStartMessage() { |
| 66 return RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling()); |
| 67 } |
| 68 |
| 69 bool DeviceLightEventPump::SendStopMessage() { |
| 70 last_seen_data_ = -1; |
| 71 return RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling()); |
| 72 } |
| 73 |
| 74 } // namespace content |
OLD | NEW |