Index: content/renderer/device_sensors/device_motion_event_pump.h |
diff --git a/content/renderer/device_sensors/device_motion_event_pump.h b/content/renderer/device_sensors/device_motion_event_pump.h |
index 5846db199bb8a2e123874350752b4ee685c91cbc..d7a60eb5a6dfe6c453833a8f04841b5dc9b28f51 100644 |
--- a/content/renderer/device_sensors/device_motion_event_pump.h |
+++ b/content/renderer/device_sensors/device_motion_event_pump.h |
@@ -6,38 +6,107 @@ |
#define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_MOTION_EVENT_PUMP_H_ |
#include <memory> |
+#include <utility> |
+#include <vector> |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
#include "base/macros.h" |
-#include "content/renderer/device_sensors/device_sensor_event_pump.h" |
-#include "content/renderer/shared_memory_seqlock_reader.h" |
-#include "device/sensors/public/cpp/motion_data.h" |
-#include "device/sensors/public/interfaces/motion.mojom.h" |
- |
-namespace blink { |
-class WebDeviceMotionListener; |
-} |
+#include "base/time/time.h" |
+#include "base/timer/timer.h" |
+#include "content/public/renderer/platform_event_observer.h" |
+#include "content/renderer/render_thread_impl.h" |
+#include "device/generic_sensor/public/cpp/sensor_reading.h" |
+#include "device/generic_sensor/public/interfaces/sensor.mojom.h" |
+#include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h" |
+#include "mojo/public/cpp/bindings/binding.h" |
+#include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceMotionData.h" |
+#include "third_party/WebKit/public/platform/modules/device_orientation/WebDeviceMotionListener.h" |
namespace content { |
-typedef SharedMemorySeqLockReader<device::MotionData> |
- DeviceMotionSharedMemoryReader; |
- |
class CONTENT_EXPORT DeviceMotionEventPump |
- : public DeviceSensorMojoClientMixin< |
- DeviceSensorEventPump<blink::WebDeviceMotionListener>, |
- device::mojom::MotionSensor> { |
+ : NON_EXPORTED_BASE( |
+ public PlatformEventObserver<blink::WebDeviceMotionListener>) { |
public: |
explicit DeviceMotionEventPump(RenderThread* thread); |
~DeviceMotionEventPump() override; |
- // PlatformEventObserver. |
+ // PlatformEventObserver: |
+ void Start(blink::WebPlatformEventListener* listener) override; |
+ void Stop() override; |
+ void SendStartMessage() override; |
+ void SendStopMessage() override; |
void SendFakeDataForTesting(void* fake_data) override; |
protected: |
Reilly Grant (use Gerrit)
2017/05/27 03:17:51
DeviceMotionEventPump has no subclasses so nothing
juncai
2017/05/30 22:26:57
The DeviceMotionEventPumpForTesting is a subclass
|
- void FireEvent() override; |
- bool InitializeReader(base::SharedMemoryHandle handle) override; |
+ // Default rate for firing events. |
+ static constexpr int kDefaultPumpFrequencyHz = 60; |
+ static constexpr int kDefaultPumpDelayMicroseconds = |
+ base::Time::kMicrosecondsPerSecond / kDefaultPumpFrequencyHz; |
+ |
+ struct CONTENT_EXPORT SensorEntry : public device::mojom::SensorClient { |
+ SensorEntry(DeviceMotionEventPump* pump, |
+ device::mojom::SensorType sensor_type); |
+ ~SensorEntry() override; |
+ |
+ // device::mojom::SensorClient: |
+ void RaiseError() override; |
+ void SensorReadingChanged() override; |
+ |
+ // Mojo callback for SensorProvider::GetSensor(). |
+ void OnSensorCreated(device::mojom::SensorInitParamsPtr params, |
+ device::mojom::SensorClientRequest client_request); |
+ |
+ // Mojo callback for Sensor::AddConfiguration(). |
+ void OnSensorAddConfiguration(bool success); |
+ |
+ void HandleSensorError(); |
+ |
+ bool SensorReadingCouldBeRead(); |
+ |
+ DeviceMotionEventPump* event_pump; |
+ device::mojom::SensorPtr sensor; |
+ device::mojom::SensorType type; |
+ device::mojom::ReportingMode mode; |
+ device::PlatformSensorConfiguration default_config; |
+ mojo::ScopedSharedBufferHandle shared_buffer_handle; |
+ mojo::ScopedSharedBufferMapping shared_buffer; |
+ device::SensorReading reading; |
+ std::pair<double, double> frequency_limits; |
+ mojo::Binding<device::mojom::SensorClient> client_binding; |
+ }; |
+ |
+ friend struct SensorEntry; |
+ |
+ virtual void FireEvent(); |
+ |
+ void DidStart(); |
+ |
+ SensorEntry accelerometer_sensor_; |
Reilly Grant (use Gerrit)
2017/05/27 03:17:51
accelerometer_
juncai
2017/05/30 22:26:57
Done.
|
+ SensorEntry linear_acceleration_sensor_; |
+ SensorEntry gyroscope_sensor_; |
Reilly Grant (use Gerrit)
2017/05/27 03:17:51
gyroscope_
juncai
2017/05/30 22:26:57
Done.
|
+ int pump_delay_microseconds_; |
+ |
+ private: |
+ // The pump is a tri-state automaton with allowed transitions as follows: |
+ // STOPPED -> PENDING_START |
+ // PENDING_START -> RUNNING |
+ // PENDING_START -> STOPPED |
+ // RUNNING -> STOPPED |
+ enum class PumpState { STOPPED, RUNNING, PENDING_START }; |
+ |
+ bool CanStart() const; |
+ void GetDataFromSharedMemory(blink::WebDeviceMotionData* data); |
+ void GetSensor(SensorEntry* sensor_entry); |
+ void HandleSensorProviderError(); |
- std::unique_ptr<DeviceMotionSharedMemoryReader> reader_; |
+ mojo::InterfacePtr<device::mojom::SensorProvider> sensor_provider_; |
+ // The number of sensors that are tried by calling |
+ // SensorProvider::GetSensor() and Sensor::AddConfiguration(). |
+ int num_sensors_tried_; |
+ PumpState state_; |
+ base::RepeatingTimer timer_; |
DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPump); |
}; |