Home | History | Annotate | Download | only in device_orientation
      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.
      4 
      5 #ifndef CONTENT_RENDERER_DEVICE_SENSOR_EVENT_PUMP_H_
      6 #define CONTENT_RENDERER_DEVICE_SENSOR_EVENT_PUMP_H_
      7 
      8 #include "base/memory/shared_memory.h"
      9 #include "base/timer/timer.h"
     10 #include "content/public/renderer/render_process_observer.h"
     11 
     12 namespace content {
     13 class RenderThread;
     14 
     15 class CONTENT_EXPORT DeviceSensorEventPump : public RenderProcessObserver {
     16  public:
     17   // Default delay between subsequent firing of events.
     18   static const int kDefaultPumpDelayMillis;
     19 
     20   int GetDelayMillis() const;
     21 
     22   void Attach(RenderThread* thread);
     23   virtual bool OnControlMessageReceived(const IPC::Message& message) = 0;
     24 
     25  protected:
     26   // Constructor for a pump with default delay.
     27   DeviceSensorEventPump();
     28 
     29   // Constructor for a pump with a given delay.
     30   explicit DeviceSensorEventPump(int pump_delay_millis);
     31   virtual ~DeviceSensorEventPump();
     32 
     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
     42   };
     43 
     44   bool RequestStart();
     45   void OnDidStart(base::SharedMemoryHandle handle);
     46   bool Stop();
     47 
     48   virtual void FireEvent() = 0;
     49   virtual bool InitializeReader(base::SharedMemoryHandle handle) = 0;
     50   virtual bool SendStartMessage() = 0;
     51   virtual bool SendStopMessage() = 0;
     52 
     53   int pump_delay_millis_;
     54   PumpState state_;
     55   base::RepeatingTimer<DeviceSensorEventPump> timer_;
     56 };
     57 
     58 }  // namespace content
     59 
     60 #endif  // CONTENT_RENDERER_DEVICE_SENSOR_EVENT_PUMP_H_
     61