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

Side by Side 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: similarity=70 Created 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 #ifndef CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_
6 #define CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/shared_memory.h"
10 #include "base/timer.h"
11 #include "content/public/renderer/render_process_observer.h"
12 #include "content/renderer/shared_memory_seqlock_reader.h"
13
14 namespace WebKit {
15 class WebDeviceMotionData;
16 class WebDeviceMotionListener;
17 }
18
19 namespace content {
20 class RenderThread;
21
22 typedef SharedMemorySeqLockReader<WebKit::WebDeviceMotionData>
23 DeviceMotionSharedMemoryReader;
24
25 class DeviceMotionEventPump : public RenderProcessObserver {
26 public:
27 DeviceMotionEventPump();
28 virtual ~DeviceMotionEventPump();
29
30 // Sets the listener to receive updates for device motion data at
31 // regular intervals.
32 // Returns true if the registration was successful.
33 bool SetListener(WebKit::WebDeviceMotionListener*);
34
35 void SetDeviceMotionReader(scoped_ptr<DeviceMotionSharedMemoryReader>);
36
37 void Attach(RenderThread* thread);
38
39 // RenderProcessObserver implementation.
40 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
41
42 private:
43 // Delay between subsequent firing of events.
44 static const double kPumpDelayMillis;
45
46 // The pump is a tri-state automaton with allowed transitions as follows:
47 // STOPPED -> PENDING_START
48 // PENDING_START -> RUNNING
49 // PENDING_START -> STOPPED
50 // RUNNING -> STOPPED
51 enum PumpState {
52 STOPPED,
53 RUNNING,
54 PENDING_START
55 };
56
57 bool StartFetchingDeviceMotion();
58 bool StopFetchingDeviceMotion();
59 void OnDidStartDeviceMotion(base::SharedMemoryHandle renderer_handle);
60 void FireEvent();
61
62 WebKit::WebDeviceMotionListener* listener_;
63 scoped_ptr<DeviceMotionSharedMemoryReader> reader_;
64 base::RepeatingTimer<DeviceMotionEventPump> timer_;
65 PumpState state_;
66 };
67
68 } // namespace content
69
70 #endif // CONTENT_RENDERER_DEVICE_MOTION_EVENT_PUMP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698