| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_LIGHT_EVENT_PUMP_H_ | 5 #ifndef CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_LIGHT_EVENT_PUMP_H_ |
| 6 #define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_LIGHT_EVENT_PUMP_H_ | 6 #define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_LIGHT_EVENT_PUMP_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "content/common/device_sensors/device_light_data.h" | 11 #include "content/common/device_sensors/device_light_data.h" |
| 12 #include "content/renderer/device_sensors/device_sensor_event_pump.h" | 12 #include "content/renderer/device_sensors/device_sensor_event_pump.h" |
| 13 #include "content/renderer/shared_memory_seqlock_reader.h" | 13 #include "content/renderer/shared_memory_seqlock_reader.h" |
| 14 #include "device/sensors/public/interfaces/light.mojom.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 class WebDeviceLightListener; | 17 class WebDeviceLightListener; |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 typedef SharedMemorySeqLockReader<DeviceLightData> | 22 typedef SharedMemorySeqLockReader<DeviceLightData> |
| 22 DeviceLightSharedMemoryReader; | 23 DeviceLightSharedMemoryReader; |
| 23 | 24 |
| 24 class CONTENT_EXPORT DeviceLightEventPump | 25 class CONTENT_EXPORT DeviceLightEventPump |
| 25 : public DeviceSensorEventPump<blink::WebDeviceLightListener> { | 26 : public DeviceSensorMojoClientMixin< |
| 27 DeviceSensorEventPump<blink::WebDeviceLightListener>, |
| 28 device::mojom::LightSensor> { |
| 26 public: | 29 public: |
| 27 explicit DeviceLightEventPump(RenderThread* thread); | 30 explicit DeviceLightEventPump(RenderThread* thread); |
| 28 ~DeviceLightEventPump() override; | 31 ~DeviceLightEventPump() override; |
| 29 | 32 |
| 30 // Sets the listener to receive updates for device light data at | 33 // Sets the listener to receive updates for device light data at |
| 31 // regular intervals. Returns true if the registration was successful. | 34 // regular intervals. Returns true if the registration was successful. |
| 32 bool SetListener(blink::WebDeviceLightListener* listener); | 35 bool SetListener(blink::WebDeviceLightListener* listener); |
| 33 | 36 |
| 34 // PlatformEventObserver implementation. | 37 // PlatformEventObserver implementation. |
| 35 bool OnControlMessageReceived(const IPC::Message& message) override; | |
| 36 void SendFakeDataForTesting(void* data) override; | 38 void SendFakeDataForTesting(void* data) override; |
| 37 | 39 |
| 38 protected: | 40 protected: |
| 39 // Methods overriden from base class DeviceSensorEventPump | 41 // Methods overriden from base class DeviceSensorEventPump |
| 40 void FireEvent() override; | 42 void FireEvent() override; |
| 41 bool InitializeReader(base::SharedMemoryHandle handle) override; | 43 bool InitializeReader(base::SharedMemoryHandle handle) override; |
| 42 | 44 |
| 43 // PlatformEventObserver implementation. | |
| 44 void SendStartMessage() override; | |
| 45 void SendStopMessage() override; | |
| 46 | |
| 47 private: | 45 private: |
| 48 bool ShouldFireEvent(double data) const; | 46 bool ShouldFireEvent(double data) const; |
| 49 | 47 |
| 50 std::unique_ptr<DeviceLightSharedMemoryReader> reader_; | 48 std::unique_ptr<DeviceLightSharedMemoryReader> reader_; |
| 51 double last_seen_data_; | 49 double last_seen_data_; |
| 52 | 50 |
| 53 DISALLOW_COPY_AND_ASSIGN(DeviceLightEventPump); | 51 DISALLOW_COPY_AND_ASSIGN(DeviceLightEventPump); |
| 54 }; | 52 }; |
| 55 | 53 |
| 56 } // namespace content | 54 } // namespace content |
| 57 | 55 |
| 58 #endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_LIGHT_EVENT_PUMP_H_ | 56 #endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_LIGHT_EVENT_PUMP_H_ |
| OLD | NEW |