Refactor management of overview window copy lifetime into a separate class.
[chromium-blink-merge.git] / content / renderer / device_orientation / device_sensor_event_pump.h
blob8f0e37e80c3f45429bb62e39fb9be6c65fed7a37
1 // Copyright 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.
5 #ifndef CONTENT_RENDERER_DEVICE_SENSOR_EVENT_PUMP_H_
6 #define CONTENT_RENDERER_DEVICE_SENSOR_EVENT_PUMP_H_
8 #include "base/memory/shared_memory.h"
9 #include "base/timer/timer.h"
10 #include "content/public/renderer/render_process_observer.h"
12 namespace content {
13 class RenderThread;
15 class CONTENT_EXPORT DeviceSensorEventPump : public RenderProcessObserver {
16 public:
17 // Default delay between subsequent firing of events.
18 static const int kDefaultPumpDelayMillis;
20 int GetDelayMillis() const;
22 void Attach(RenderThread* thread);
23 virtual bool OnControlMessageReceived(const IPC::Message& message) = 0;
25 protected:
26 // Constructor for a pump with default delay.
27 DeviceSensorEventPump();
29 // Constructor for a pump with a given delay.
30 explicit DeviceSensorEventPump(int pump_delay_millis);
31 virtual ~DeviceSensorEventPump();
33 // The pump is a tri-state automaton with allowed transitions as follows:
34 // STOPPED -> PENDING_START
35 // PENDING_START -> RUNNING
36 // PENDING_START -> STOPPED
37 // RUNNING -> STOPPED
38 enum PumpState {
39 STOPPED,
40 RUNNING,
41 PENDING_START
44 bool RequestStart();
45 void OnDidStart(base::SharedMemoryHandle handle);
46 bool Stop();
48 virtual void FireEvent() = 0;
49 virtual bool InitializeReader(base::SharedMemoryHandle handle) = 0;
50 virtual bool SendStartMessage() = 0;
51 virtual bool SendStopMessage() = 0;
53 int pump_delay_millis_;
54 PumpState state_;
55 base::RepeatingTimer<DeviceSensorEventPump> timer_;
58 } // namespace content
60 #endif // CONTENT_RENDERER_DEVICE_SENSOR_EVENT_PUMP_H_