OLD | NEW |
| (Empty) |
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 CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_LIGHT_EVENT_PUMP_H_ | |
6 #define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_LIGHT_EVENT_PUMP_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | |
11 #include "content/renderer/device_sensors/device_sensor_event_pump.h" | |
12 #include "content/renderer/shared_memory_seqlock_reader.h" | |
13 #include "device/sensors/public/cpp/device_light_data.h" | |
14 #include "device/sensors/public/interfaces/light.mojom.h" | |
15 | |
16 namespace blink { | |
17 class WebDeviceLightListener; | |
18 } | |
19 | |
20 namespace content { | |
21 | |
22 typedef SharedMemorySeqLockReader<device::DeviceLightData> | |
23 DeviceLightSharedMemoryReader; | |
24 | |
25 class CONTENT_EXPORT DeviceLightEventPump | |
26 : public DeviceSensorMojoClientMixin< | |
27 DeviceSensorEventPump<blink::WebDeviceLightListener>, | |
28 device::mojom::LightSensor> { | |
29 public: | |
30 explicit DeviceLightEventPump(RenderThread* thread); | |
31 ~DeviceLightEventPump() override; | |
32 | |
33 // Sets the listener to receive updates for device light data at | |
34 // regular intervals. Returns true if the registration was successful. | |
35 bool SetListener(blink::WebDeviceLightListener* listener); | |
36 | |
37 // PlatformEventObserver implementation. | |
38 void SendFakeDataForTesting(void* data) override; | |
39 | |
40 protected: | |
41 // Methods overriden from base class DeviceSensorEventPump | |
42 void FireEvent() override; | |
43 bool InitializeReader(base::SharedMemoryHandle handle) override; | |
44 | |
45 private: | |
46 bool ShouldFireEvent(double data) const; | |
47 | |
48 std::unique_ptr<DeviceLightSharedMemoryReader> reader_; | |
49 double last_seen_data_; | |
50 | |
51 DISALLOW_COPY_AND_ASSIGN(DeviceLightEventPump); | |
52 }; | |
53 | |
54 } // namespace content | |
55 | |
56 #endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_LIGHT_EVENT_PUMP_H_ | |
OLD | NEW |