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..6cc278e81e01497476dedd1cc0f26620de1eed27 100644 |
--- a/content/renderer/device_sensors/device_motion_event_pump.h |
+++ b/content/renderer/device_sensors/device_motion_event_pump.h |
@@ -6,38 +6,116 @@ |
#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: |
- 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; |
+ |
+ static constexpr int kMaxReadAttemptsCount = 10; |
+ |
+ struct CONTENT_EXPORT SensorEntry : public device::mojom::SensorClient { |
+ explicit SensorEntry(DeviceMotionEventPump* pump); |
+ ~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(); |
+ |
+ // Updates sensor reading from shared buffer. |
+ bool UpdateSensorReading(); |
+ |
+ bool TryReadFromBuffer(device::SensorReading* result); |
+ |
+ bool SensorReadingUpdated(); |
+ |
+ DeviceMotionEventPump* event_pump; |
+ device::mojom::SensorPtr sensor; |
+ device::mojom::SensorType type; |
+ bool active; |
+ 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(); |
+ |
+ std::vector<std::unique_ptr<SensorEntry>> sensors_; |
Reilly Grant (use Gerrit)
2017/05/22 20:29:46
Since this sensor type always uses exactly 3 senso
juncai
2017/05/23 02:30:23
Done.
|
+ int pump_delay_microseconds_; |
+ // The number of sensors that are available from a successful |
+ // SensorProvider::GetSensor() call. |
+ int num_available_sensors_; |
+ |
+ 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; |
+ bool AllAvailableSensorsAreActive() const; |
+ bool GetDataFromSharedMemory(blink::WebDeviceMotionData* data); |
+ void GetSensor(device::mojom::SensorType type); |
+ void HandleSensorProviderError(); |
- std::unique_ptr<DeviceMotionSharedMemoryReader> reader_; |
+ mojo::InterfacePtr<device::mojom::SensorProvider> sensor_provider_; |
+ // The number of sensors that are tried obtaining by calling |
+ // SensorProvider::GetSensor(). |
+ int num_sensors_tried_; |
+ PumpState state_; |
+ base::RepeatingTimer timer_; |
DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPump); |
}; |