OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 SensorProxy_h | 5 #ifndef SensorProxy_h |
6 #define SensorProxy_h | 6 #define SensorProxy_h |
7 | 7 |
8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
| 9 #include "device/generic_sensor/public/cpp/sensor_reading.h" |
9 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" | 10 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" |
10 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" | 11 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" |
11 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
12 #include "platform/Supplementable.h" | 13 #include "platform/Supplementable.h" |
13 #include "platform/heap/Handle.h" | 14 #include "platform/heap/Handle.h" |
14 | 15 |
15 namespace blink { | 16 namespace blink { |
16 | 17 |
17 class SensorProviderProxy; | 18 class SensorProviderProxy; |
18 | 19 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 std::unique_ptr<Function<void(bool)>>); | 54 std::unique_ptr<Function<void(bool)>>); |
54 void removeConfiguration(device::mojom::blink::SensorConfigurationPtr, | 55 void removeConfiguration(device::mojom::blink::SensorConfigurationPtr, |
55 std::unique_ptr<Function<void(bool)>>); | 56 std::unique_ptr<Function<void(bool)>>); |
56 | 57 |
57 void suspend(); | 58 void suspend(); |
58 void resume(); | 59 void resume(); |
59 | 60 |
60 device::mojom::blink::SensorType type() const { return m_type; } | 61 device::mojom::blink::SensorType type() const { return m_type; } |
61 device::mojom::blink::ReportingMode reportingMode() const { return m_mode; } | 62 device::mojom::blink::ReportingMode reportingMode() const { return m_mode; } |
62 | 63 |
63 struct Reading { | 64 using Reading = device::SensorReading; |
64 double timestamp; | |
65 double reading[3]; | |
66 }; | |
67 static_assert(sizeof(Reading) == | |
68 device::mojom::blink::SensorInitParams::kReadBufferSize, | |
69 "Check reading size"); | |
70 | 65 |
71 const Reading& reading() const { return m_reading; } | 66 const Reading& reading() const { return m_reading; } |
72 | 67 |
73 const device::mojom::blink::SensorConfiguration* defaultConfig() const; | 68 const device::mojom::blink::SensorConfiguration* defaultConfig() const; |
74 | 69 |
75 // Updates internal reading from shared buffer. | 70 // Updates internal reading from shared buffer. |
76 void updateInternalReading(); | 71 void updateInternalReading(); |
77 | 72 |
78 DECLARE_VIRTUAL_TRACE(); | 73 DECLARE_VIRTUAL_TRACE(); |
79 | 74 |
80 private: | 75 private: |
81 friend class SensorProviderProxy; | 76 friend class SensorProviderProxy; |
82 SensorProxy(device::mojom::blink::SensorType, SensorProviderProxy*); | 77 SensorProxy(device::mojom::blink::SensorType, SensorProviderProxy*); |
83 | 78 |
84 // device::mojom::blink::SensorClient overrides. | 79 // device::mojom::blink::SensorClient overrides. |
85 void RaiseError() override; | 80 void RaiseError() override; |
86 void SensorReadingChanged() override; | 81 void SensorReadingChanged() override; |
87 | 82 |
88 // Generic handler for a fatal error. | 83 // Generic handler for a fatal error. |
89 void handleSensorError(ExceptionCode = UnknownError, | 84 void handleSensorError(ExceptionCode = UnknownError, |
90 const String& sanitizedMessage = String(), | 85 const String& sanitizedMessage = String(), |
91 const String& unsanitizedMessage = String()); | 86 const String& unsanitizedMessage = String()); |
92 | 87 |
93 void onSensorCreated(device::mojom::blink::SensorInitParamsPtr, | 88 void onSensorCreated(device::mojom::blink::SensorInitParamsPtr, |
94 device::mojom::blink::SensorClientRequest); | 89 device::mojom::blink::SensorClientRequest); |
95 | 90 |
| 91 bool tryReadFromBuffer(); |
| 92 |
96 device::mojom::blink::SensorType m_type; | 93 device::mojom::blink::SensorType m_type; |
97 device::mojom::blink::ReportingMode m_mode; | 94 device::mojom::blink::ReportingMode m_mode; |
98 Member<SensorProviderProxy> m_provider; | 95 Member<SensorProviderProxy> m_provider; |
99 using ObserversSet = HeapHashSet<WeakMember<Observer>>; | 96 using ObserversSet = HeapHashSet<WeakMember<Observer>>; |
100 ObserversSet m_observers; | 97 ObserversSet m_observers; |
101 | 98 |
102 device::mojom::blink::SensorPtr m_sensor; | 99 device::mojom::blink::SensorPtr m_sensor; |
103 device::mojom::blink::SensorConfigurationPtr m_defaultConfig; | 100 device::mojom::blink::SensorConfigurationPtr m_defaultConfig; |
104 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding; | 101 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding; |
105 | 102 |
106 enum State { Uninitialized, Initializing, Initialized }; | 103 enum State { Uninitialized, Initializing, Initialized }; |
107 State m_state; | 104 State m_state; |
108 mojo::ScopedSharedBufferHandle m_sharedBufferHandle; | 105 mojo::ScopedSharedBufferHandle m_sharedBufferHandle; |
109 mojo::ScopedSharedBufferMapping m_sharedBuffer; | 106 mojo::ScopedSharedBufferMapping m_sharedBuffer; |
110 Reading m_reading; | 107 Reading m_reading; |
111 bool m_suspended; | 108 bool m_suspended; |
| 109 using ReadingBuffer = device::SensorReadingSharedBuffer; |
| 110 static_assert( |
| 111 sizeof(ReadingBuffer) == |
| 112 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests, |
| 113 "Check reading buffer size for tests"); |
112 }; | 114 }; |
113 | 115 |
114 } // namespace blink | 116 } // namespace blink |
115 | 117 |
116 #endif // SensorProxy_h | 118 #endif // SensorProxy_h |
OLD | NEW |