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