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"
15 class CONTENT_EXPORT DeviceSensorEventPump
: public RenderProcessObserver
{
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;
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
45 void OnDidStart(base::SharedMemoryHandle handle
);
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_
;
55 base::RepeatingTimer
<DeviceSensorEventPump
> timer_
;
58 } // namespace content
60 #endif // CONTENT_RENDERER_DEVICE_SENSOR_EVENT_PUMP_H_