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 const int DeviceLightEventPump::kDefaultLightPumpDelayMillis = 200; | |
| 14 | |
| 15 DeviceLightEventPump::DeviceLightEventPump() | |
| 16 : DeviceSensorEventPump(kDefaultLightPumpDelayMillis), | |
|
dcheng
2014/06/18 16:51:19
Not for this patch, but it would be nice to fix th
riju_
2014/06/19 13:15:54
Ok. I will put up the new CL once this goes in.
| |
| 17 listener_(0), | |
| 18 last_seen_data_(-1) { | |
|
timvolodine
2014/06/18 17:38:36
you probably also want to set to -1 when Stop is c
riju_
2014/06/19 13:15:54
Done.
| |
| 19 } | |
| 20 | |
| 21 DeviceLightEventPump::DeviceLightEventPump(int pump_delay_millis) | |
| 22 : DeviceSensorEventPump(pump_delay_millis), | |
| 23 listener_(0), | |
|
dcheng
2014/06/18 16:51:19
NULL
riju_
2014/06/19 13:15:54
Done.
| |
| 24 last_seen_data_(-1) { | |
| 25 } | |
| 26 | |
| 27 DeviceLightEventPump::~DeviceLightEventPump() { | |
| 28 } | |
| 29 | |
| 30 bool DeviceLightEventPump::SetListener( | |
| 31 blink::WebDeviceLightListener* listener) { | |
| 32 listener_ = listener; | |
| 33 return listener_ ? RequestStart() : Stop(); | |
| 34 } | |
| 35 | |
| 36 bool DeviceLightEventPump::OnControlMessageReceived( | |
| 37 const IPC::Message& message) { | |
| 38 bool handled = true; | |
| 39 IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump, message) | |
| 40 IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart) | |
| 41 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 42 IPC_END_MESSAGE_MAP() | |
| 43 return handled; | |
| 44 } | |
| 45 | |
| 46 void DeviceLightEventPump::FireEvent() { | |
| 47 DCHECK(listener_); | |
| 48 DeviceLightData data; | |
| 49 bool did_return_light_data = reader_->GetLatestData(&data); | |
| 50 if (data.value != last_seen_data_ && did_return_light_data) { | |
|
dcheng
2014/06/18 16:51:19
Nit: It probably makes more sense to order the che
riju_
2014/06/19 13:15:54
Done.
| |
| 51 last_seen_data_ = data.value; | |
| 52 listener_->didChangeDeviceLight(data.value); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) { | |
| 57 if (!reader_) | |
| 58 reader_.reset(new DeviceLightSharedMemoryReader()); | |
| 59 return reader_->Initialize(handle); | |
| 60 } | |
| 61 | |
| 62 bool DeviceLightEventPump::SendStartMessage() { | |
| 63 return RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling()); | |
| 64 } | |
| 65 | |
| 66 bool DeviceLightEventPump::SendStopMessage() { | |
| 67 return RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling()); | |
| 68 } | |
| 69 | |
| 70 } // namespace content | |
| OLD | NEW |