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

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

Powered by Google App Engine
This is Rietveld 408576698