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

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

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: fix compilation: peer_handle -> PeerHandle() Created 7 years, 5 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.h
diff --git a/content/renderer/device_orientation/device_motion_event_pump.h b/content/renderer/device_orientation/device_motion_event_pump.h
new file mode 100644
index 0000000000000000000000000000000000000000..e16e6b2d5153837ebe8f6c4b42b9cc3c410e2a52
--- /dev/null
+++ b/content/renderer/device_orientation/device_motion_event_pump.h
@@ -0,0 +1,72 @@
+// 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.
+
+#ifndef CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_
+#define CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "base/shared_memory.h"
+#include "base/timer/timer.h"
+#include "content/public/renderer/render_process_observer.h"
+#include "content/renderer/shared_memory_seqlock_reader.h"
+#include "third_party/WebKit/public/platform/WebDeviceMotionData.h"
+
+namespace WebKit {
+class WebDeviceMotionListener;
+}
+
+namespace content {
+class RenderThread;
+
+typedef SharedMemorySeqLockReader<WebKit::WebDeviceMotionData>
+ DeviceMotionSharedMemoryReader;
+
+class CONTENT_EXPORT DeviceMotionEventPump : public RenderProcessObserver {
+ public:
+ DeviceMotionEventPump();
+ virtual ~DeviceMotionEventPump();
+
+ static double GetDelayMillis();
+
+ // Sets the listener to receive updates for device motion data at
+ // regular intervals.
+ // Returns true if the registration was successful.
+ bool SetListener(WebKit::WebDeviceMotionListener*);
+
+ void SetDeviceMotionReader(scoped_ptr<DeviceMotionSharedMemoryReader>);
+
+ void Attach(RenderThread* thread);
+
+ // RenderProcessObserver implementation.
+ virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ protected:
+ // Delay between subsequent firing of events.
+ static const double kPumpDelayMillis;
+
+ // The pump is a tri-state automaton with allowed transitions as follows:
+ // STOPPED -> PENDING_START
+ // PENDING_START -> RUNNING
+ // PENDING_START -> STOPPED
+ // RUNNING -> STOPPED
+ enum PumpState {
+ STOPPED,
+ RUNNING,
+ PENDING_START
+ };
+
+ bool StartFetchingDeviceMotion();
+ bool StopFetchingDeviceMotion();
+ void OnDidStartDeviceMotion(base::SharedMemoryHandle renderer_handle);
+ void FireEvent();
+
+ WebKit::WebDeviceMotionListener* listener_;
+ scoped_ptr<DeviceMotionSharedMemoryReader> reader_;
+ base::RepeatingTimer<DeviceMotionEventPump> timer_;
+ PumpState state_;
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_
« no previous file with comments | « content/renderer/device_orientation/OWNERS ('k') | content/renderer/device_orientation/device_motion_event_pump.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698