Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: content/renderer/device_sensors/device_light_event_pump.cc

Issue 286793002: [DeviceLight] Add renderer+common parts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove valueIsUpdated Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/device_sensors/device_light_event_pump.cc
diff --git a/content/renderer/device_sensors/device_light_event_pump.cc b/content/renderer/device_sensors/device_light_event_pump.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cae35c8f324ae7e543a02b977668c43e127317d9
--- /dev/null
+++ b/content/renderer/device_sensors/device_light_event_pump.cc
@@ -0,0 +1,70 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/device_sensors/device_light_event_pump.h"
+
+#include "content/common/device_sensors/device_light_messages.h"
+#include "content/public/renderer/render_thread.h"
+#include "third_party/WebKit/public/platform/WebDeviceLightListener.h"
+
+namespace content {
+
+const int DeviceLightEventPump::kDefaultLightPumpDelayMillis = 200;
+
+DeviceLightEventPump::DeviceLightEventPump()
+ : 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.
+ listener_(0),
+ 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.
+}
+
+DeviceLightEventPump::DeviceLightEventPump(int pump_delay_millis)
+ : DeviceSensorEventPump(pump_delay_millis),
+ listener_(0),
dcheng 2014/06/18 16:51:19 NULL
riju_ 2014/06/19 13:15:54 Done.
+ last_seen_data_(-1) {
+}
+
+DeviceLightEventPump::~DeviceLightEventPump() {
+}
+
+bool DeviceLightEventPump::SetListener(
+ blink::WebDeviceLightListener* listener) {
+ listener_ = listener;
+ return listener_ ? RequestStart() : Stop();
+}
+
+bool DeviceLightEventPump::OnControlMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(DeviceLightEventPump, message)
+ IPC_MESSAGE_HANDLER(DeviceLightMsg_DidStartPolling, OnDidStart)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void DeviceLightEventPump::FireEvent() {
+ DCHECK(listener_);
+ DeviceLightData data;
+ bool did_return_light_data = reader_->GetLatestData(&data);
+ 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.
+ last_seen_data_ = data.value;
+ listener_->didChangeDeviceLight(data.value);
+ }
+}
+
+bool DeviceLightEventPump::InitializeReader(base::SharedMemoryHandle handle) {
+ if (!reader_)
+ reader_.reset(new DeviceLightSharedMemoryReader());
+ return reader_->Initialize(handle);
+}
+
+bool DeviceLightEventPump::SendStartMessage() {
+ return RenderThread::Get()->Send(new DeviceLightHostMsg_StartPolling());
+}
+
+bool DeviceLightEventPump::SendStopMessage() {
+ return RenderThread::Get()->Send(new DeviceLightHostMsg_StopPolling());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698