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

Unified Diff: content/renderer/device_orientation/device_motion_event_pump.cc

Issue 14678012: Implement the content/renderer and content/browser part of the Device Motion API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added unit test for device_motion_event_pump Created 7 years, 7 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_orientation/device_motion_event_pump.cc
diff --git a/content/renderer/device_orientation/device_motion_event_pump.cc b/content/renderer/device_orientation/device_motion_event_pump.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6b1626760e8920336c6ff8ffed0fd39711f90b11
--- /dev/null
+++ b/content/renderer/device_orientation/device_motion_event_pump.cc
@@ -0,0 +1,71 @@
+// Copyright (c) 2013 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 "device_motion_event_pump.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "base/shared_memory.h"
+#include "device_motion_shared_memory_reader.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebDeviceMotionData.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebDeviceMotionListener.h"
+
+namespace content {
+
+const double DeviceMotionEventPump::kPumpDelayMillis = 40;
+
+DeviceMotionEventPump::DeviceMotionEventPump()
+ : listener_(0) {
+}
+
+DeviceMotionEventPump::~DeviceMotionEventPump() {
+}
+
+void DeviceMotionEventPump::setListener(
+ WebKit::WebDeviceMotionListener* listener) {
+ listener_ = listener;
+ listener_ ? startFetchingDeviceMotion() : stopFetchingDeviceMotion();
+}
+
+void DeviceMotionEventPump::setDeviceMotionReader(
+ DeviceMotionSharedMemoryReader* reader) {
+ reader_.reset(reader);
+}
+
+void DeviceMotionEventPump::startFetchingDeviceMotion() {
+ DVLOG(2) << "start fetching device motion";
+ if (timer_.IsRunning())
+ return;
+
+ if (!reader_.get())
+ setDeviceMotionReader(new DeviceMotionSharedMemoryReader);
+
+ reader_->startUpdating();
+ timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kPumpDelayMillis),
+ this, &DeviceMotionEventPump::fireEvent);
darin (slow to review) 2013/05/29 06:41:53 nit: fix indentation
timvolodine 2013/05/29 18:59:06 Done.
+}
+
+void DeviceMotionEventPump::stopFetchingDeviceMotion() {
+ DVLOG(2) << "stop fetching device motion";
+ if (timer_.IsRunning()) {
+ timer_.Stop();
+ reader_->stopUpdating();
+ }
+}
+
+void DeviceMotionEventPump::fireEvent() {
+ DCHECK(listener_);
+ WebKit::WebDeviceMotionData data;
+ if (reader_->latestDeviceMotionData(data))
+ listener_->didChangeDeviceMotion(data);
+}
+
+void DeviceMotionEventPump::didChangeDeviceMotion(
+ const WebKit::WebDeviceMotionData& data) {
+ NOTIMPLEMENTED();
darin (slow to review) 2013/05/29 06:41:53 add a comment? why is DeviceMotionEventPump exten
timvolodine 2013/05/29 18:59:06 actually the listener interface is no longer relev
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698