1 // Copyright 2014 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 THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_MOTION_EVENT_PUMP_H_
6 #define THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_MOTION_EVENT_PUMP_H_
7 
8 #include "base/macros.h"
9 #include "third_party/blink/renderer/modules/device_orientation/device_sensor_event_pump.h"
10 #include "third_party/blink/renderer/modules/modules_export.h"
11 #include "third_party/blink/renderer/platform/heap/handle.h"
12 
13 namespace blink {
14 
15 class DeviceMotionData;
16 class DeviceSensorEntry;
17 class PlatformEventController;
18 
19 class MODULES_EXPORT DeviceMotionEventPump
20     : public GarbageCollected<DeviceMotionEventPump>,
21       public DeviceSensorEventPump {
22  public:
23   explicit DeviceMotionEventPump(LocalFrame&);
24   ~DeviceMotionEventPump() override;
25 
26   void SetController(PlatformEventController*);
27   void RemoveController();
28 
29   // Note that the returned object is owned by this class.
30   DeviceMotionData* LatestDeviceMotionData();
31 
32   void Trace(Visitor*) const override;
33 
34   // DeviceSensorEventPump:
35   void SendStartMessage(LocalFrame& frame) override;
36   void SendStopMessage() override;
37 
38  protected:
39   // DeviceSensorEventPump:
40   void FireEvent(TimerBase*) override;
41 
42   Member<DeviceSensorEntry> accelerometer_;
43   Member<DeviceSensorEntry> linear_acceleration_sensor_;
44   Member<DeviceSensorEntry> gyroscope_;
45 
46  private:
47   friend class DeviceMotionEventPumpTest;
48 
49   void StartListening(LocalFrame&);
50   void StopListening();
51   void NotifyController();
52 
53   // DeviceSensorEventPump:
54   bool SensorsReadyOrErrored() const override;
55 
56   DeviceMotionData* GetDataFromSharedMemory();
57 
58   Member<DeviceMotionData> data_;
59   Member<PlatformEventController> controller_;
60 
61   DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPump);
62 };
63 
64 }  // namespace blink
65 
66 #endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_DEVICE_ORIENTATION_DEVICE_MOTION_EVENT_PUMP_H_
67