Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: content/renderer/device_sensors/device_motion_event_pump.h

Issue 2896583005: Reland: Refactor DeviceMotionEventPump to use //device/generic_sensor instead of //device/sensors (Closed)
Patch Set: updated device sensor browsertest Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_MOTION_EVENT_PUMP_H_ 5 #ifndef CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_MOTION_EVENT_PUMP_H_
6 #define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_MOTION_EVENT_PUMP_H_ 6 #define CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_MOTION_EVENT_PUMP_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <utility>
10 #include <vector>
9 11
12 #include "base/bind.h"
13 #include "base/bind_helpers.h"
10 #include "base/macros.h" 14 #include "base/macros.h"
11 #include "content/renderer/device_sensors/device_sensor_event_pump.h" 15 #include "base/time/time.h"
12 #include "content/renderer/shared_memory_seqlock_reader.h" 16 #include "base/timer/timer.h"
13 #include "device/sensors/public/cpp/motion_data.h" 17 #include "content/public/renderer/platform_event_observer.h"
14 #include "device/sensors/public/interfaces/motion.mojom.h" 18 #include "content/renderer/render_thread_impl.h"
15 19 #include "device/generic_sensor/public/cpp/sensor_reading.h"
16 namespace blink { 20 #include "device/generic_sensor/public/interfaces/sensor.mojom.h"
17 class WebDeviceMotionListener; 21 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom.h"
18 } 22 #include "mojo/public/cpp/bindings/binding.h"
23 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic eMotionData.h"
24 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic eMotionListener.h"
19 25
20 namespace content { 26 namespace content {
21 27
22 typedef SharedMemorySeqLockReader<device::MotionData>
23 DeviceMotionSharedMemoryReader;
24
25 class CONTENT_EXPORT DeviceMotionEventPump 28 class CONTENT_EXPORT DeviceMotionEventPump
26 : public DeviceSensorMojoClientMixin< 29 : NON_EXPORTED_BASE(
27 DeviceSensorEventPump<blink::WebDeviceMotionListener>, 30 public PlatformEventObserver<blink::WebDeviceMotionListener>) {
28 device::mojom::MotionSensor> {
29 public: 31 public:
30 explicit DeviceMotionEventPump(RenderThread* thread); 32 explicit DeviceMotionEventPump(RenderThread* thread);
31 ~DeviceMotionEventPump() override; 33 ~DeviceMotionEventPump() override;
32 34
33 // PlatformEventObserver. 35 // PlatformEventObserver:
36 void Start(blink::WebPlatformEventListener* listener) override;
37 void Stop() override;
38 void SendStartMessage() override;
39 void SendStopMessage() override;
34 void SendFakeDataForTesting(void* fake_data) override; 40 void SendFakeDataForTesting(void* fake_data) override;
35 41
36 protected: 42 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
37 void FireEvent() override; 43 // Default rate for firing events.
38 bool InitializeReader(base::SharedMemoryHandle handle) override; 44 static constexpr int kDefaultPumpFrequencyHz = 60;
45 static constexpr int kDefaultPumpDelayMicroseconds =
46 base::Time::kMicrosecondsPerSecond / kDefaultPumpFrequencyHz;
39 47
40 std::unique_ptr<DeviceMotionSharedMemoryReader> reader_; 48 struct CONTENT_EXPORT SensorEntry : public device::mojom::SensorClient {
49 SensorEntry(DeviceMotionEventPump* pump,
50 device::mojom::SensorType sensor_type);
51 ~SensorEntry() override;
52
53 // device::mojom::SensorClient:
54 void RaiseError() override;
55 void SensorReadingChanged() override;
56
57 // Mojo callback for SensorProvider::GetSensor().
58 void OnSensorCreated(device::mojom::SensorInitParamsPtr params,
59 device::mojom::SensorClientRequest client_request);
60
61 // Mojo callback for Sensor::AddConfiguration().
62 void OnSensorAddConfiguration(bool success);
63
64 void HandleSensorError();
65
66 bool SensorReadingCouldBeRead();
67
68 DeviceMotionEventPump* event_pump;
69 device::mojom::SensorPtr sensor;
70 device::mojom::SensorType type;
71 device::mojom::ReportingMode mode;
72 device::PlatformSensorConfiguration default_config;
73 mojo::ScopedSharedBufferHandle shared_buffer_handle;
74 mojo::ScopedSharedBufferMapping shared_buffer;
75 device::SensorReading reading;
76 std::pair<double, double> frequency_limits;
77 mojo::Binding<device::mojom::SensorClient> client_binding;
78 };
79
80 friend struct SensorEntry;
81
82 virtual void FireEvent();
83
84 void DidStart();
85
86 SensorEntry accelerometer_sensor_;
Reilly Grant (use Gerrit) 2017/05/27 03:17:51 accelerometer_
juncai 2017/05/30 22:26:57 Done.
87 SensorEntry linear_acceleration_sensor_;
88 SensorEntry gyroscope_sensor_;
Reilly Grant (use Gerrit) 2017/05/27 03:17:51 gyroscope_
juncai 2017/05/30 22:26:57 Done.
89 int pump_delay_microseconds_;
90
91 private:
92 // The pump is a tri-state automaton with allowed transitions as follows:
93 // STOPPED -> PENDING_START
94 // PENDING_START -> RUNNING
95 // PENDING_START -> STOPPED
96 // RUNNING -> STOPPED
97 enum class PumpState { STOPPED, RUNNING, PENDING_START };
98
99 bool CanStart() const;
100 void GetDataFromSharedMemory(blink::WebDeviceMotionData* data);
101 void GetSensor(SensorEntry* sensor_entry);
102 void HandleSensorProviderError();
103
104 mojo::InterfacePtr<device::mojom::SensorProvider> sensor_provider_;
105 // The number of sensors that are tried by calling
106 // SensorProvider::GetSensor() and Sensor::AddConfiguration().
107 int num_sensors_tried_;
108 PumpState state_;
109 base::RepeatingTimer timer_;
41 110
42 DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPump); 111 DISALLOW_COPY_AND_ASSIGN(DeviceMotionEventPump);
43 }; 112 };
44 113
45 } // namespace content 114 } // namespace content
46 115
47 #endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_MOTION_EVENT_PUMP_H_ 116 #endif // CONTENT_RENDERER_DEVICE_SENSORS_DEVICE_MOTION_EVENT_PUMP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698