| 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 "core/page/PageVisibilityObserver.h" | 9 #include "core/page/PageVisibilityObserver.h" |
| 10 #include "device/generic_sensor/public/cpp/sensor_reading.h" | 10 #include "device/generic_sensor/public/cpp/sensor_reading.h" |
| 11 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" | 11 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" |
| 12 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" | 12 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" |
| 13 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 14 #include "platform/Supplementable.h" | 14 #include "platform/Supplementable.h" |
| 15 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
| 16 #include "public/platform/modules/permissions/permission.mojom-blink.h" |
| 17 #include "public/platform/modules/permissions/permission_status.mojom-blink.h" |
| 16 #include "wtf/Vector.h" | 18 #include "wtf/Vector.h" |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 | 21 |
| 20 class SensorProviderProxy; | 22 class SensorProviderProxy; |
| 21 class SensorReading; | 23 class SensorReading; |
| 22 class SensorReadingUpdater; | 24 class SensorReadingUpdater; |
| 25 class SecurityOrigin; |
| 23 | 26 |
| 24 // This class wraps 'Sensor' mojo interface and used by multiple | 27 // This class wraps 'Sensor' mojo interface and used by multiple |
| 25 // JS sensor instances of the same type (within a single frame). | 28 // JS sensor instances of the same type (within a single frame). |
| 26 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, | 29 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, |
| 27 public device::mojom::blink::SensorClient, | 30 public device::mojom::blink::SensorClient, |
| 31 public mojom::blink::PermissionObserver, |
| 28 public PageVisibilityObserver { | 32 public PageVisibilityObserver { |
| 29 USING_GARBAGE_COLLECTED_MIXIN(SensorProxy); | 33 USING_GARBAGE_COLLECTED_MIXIN(SensorProxy); |
| 30 USING_PRE_FINALIZER(SensorProxy, Dispose); | 34 USING_PRE_FINALIZER(SensorProxy, Dispose); |
| 31 WTF_MAKE_NONCOPYABLE(SensorProxy); | 35 WTF_MAKE_NONCOPYABLE(SensorProxy); |
| 32 | 36 |
| 33 public: | 37 public: |
| 34 class Observer : public GarbageCollectedMixin { | 38 class Observer : public GarbageCollectedMixin { |
| 35 public: | 39 public: |
| 36 // Has valid 'Sensor' binding, {add, remove}Configuration() | 40 // Has valid 'Sensor' binding, {add, remove}Configuration() |
| 37 // methods can be called. | 41 // methods can be called. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 const WTF::Vector<double>& FrequenciesUsed() const { | 100 const WTF::Vector<double>& FrequenciesUsed() const { |
| 97 return frequencies_used_; | 101 return frequencies_used_; |
| 98 } | 102 } |
| 99 | 103 |
| 100 DECLARE_VIRTUAL_TRACE(); | 104 DECLARE_VIRTUAL_TRACE(); |
| 101 | 105 |
| 102 private: | 106 private: |
| 103 friend class SensorProviderProxy; | 107 friend class SensorProviderProxy; |
| 104 friend class SensorReadingUpdaterContinuous; | 108 friend class SensorReadingUpdaterContinuous; |
| 105 friend class SensorReadingUpdaterOnChange; | 109 friend class SensorReadingUpdaterOnChange; |
| 106 SensorProxy(device::mojom::blink::SensorType, SensorProviderProxy*, Page*); | 110 SensorProxy(device::mojom::blink::SensorType, |
| 107 | 111 RefPtr<SecurityOrigin>, |
| 112 SensorProviderProxy*, |
| 113 Page*); |
| 108 // Updates sensor reading from shared buffer. | 114 // Updates sensor reading from shared buffer. |
| 109 void UpdateSensorReading(); | 115 void UpdateSensorReading(); |
| 110 void NotifySensorChanged(double timestamp); | 116 void NotifySensorChanged(double timestamp); |
| 111 | 117 |
| 112 // device::mojom::blink::SensorClient overrides. | 118 // device::mojom::blink::SensorClient overrides. |
| 113 void RaiseError() override; | 119 void RaiseError() override; |
| 114 void SensorReadingChanged() override; | 120 void SensorReadingChanged() override; |
| 115 | 121 |
| 116 // PageVisibilityObserver overrides. | 122 // PageVisibilityObserver overrides. |
| 117 void PageVisibilityChanged() override; | 123 void PageVisibilityChanged() override; |
| 118 | 124 |
| 119 // Generic handler for a fatal error. | 125 // Generic handler for a fatal error. |
| 120 void HandleSensorError(); | 126 void HandleSensorError(); |
| 121 | 127 |
| 122 // mojo call callbacks. | 128 // mojo call callbacks. |
| 123 void OnSensorCreated(device::mojom::blink::SensorInitParamsPtr, | 129 void OnSensorCreated(device::mojom::blink::SensorInitParamsPtr, |
| 124 device::mojom::blink::SensorClientRequest); | 130 device::mojom::blink::SensorClientRequest); |
| 125 void OnAddConfigurationCompleted( | 131 void OnAddConfigurationCompleted( |
| 126 double frequency, | 132 double frequency, |
| 127 std::unique_ptr<Function<void(bool)>> callback, | 133 std::unique_ptr<Function<void(bool)>> callback, |
| 128 bool result); | 134 bool result); |
| 129 void OnRemoveConfigurationCompleted(double frequency, bool result); | 135 void OnRemoveConfigurationCompleted(double frequency, bool result); |
| 130 | 136 |
| 131 bool TryReadFromBuffer(device::SensorReading& result); | 137 bool TryReadFromBuffer(device::SensorReading& result); |
| 132 void OnAnimationFrame(double timestamp); | 138 void OnAnimationFrame(double timestamp); |
| 133 | 139 |
| 140 // PermissionObserver override. |
| 141 void OnPermissionStatusChange(mojom::blink::PermissionStatus); |
| 142 |
| 134 device::mojom::blink::SensorType type_; | 143 device::mojom::blink::SensorType type_; |
| 135 device::mojom::blink::ReportingMode mode_; | 144 device::mojom::blink::ReportingMode mode_; |
| 136 Member<SensorProviderProxy> provider_; | 145 Member<SensorProviderProxy> provider_; |
| 146 |
| 137 using ObserversSet = HeapHashSet<WeakMember<Observer>>; | 147 using ObserversSet = HeapHashSet<WeakMember<Observer>>; |
| 138 ObserversSet observers_; | 148 ObserversSet observers_; |
| 139 | 149 |
| 140 device::mojom::blink::SensorPtr sensor_; | 150 device::mojom::blink::SensorPtr sensor_; |
| 141 device::mojom::blink::SensorConfigurationPtr default_config_; | 151 device::mojom::blink::SensorConfigurationPtr default_config_; |
| 142 mojo::Binding<device::mojom::blink::SensorClient> client_binding_; | 152 mojo::Binding<device::mojom::blink::SensorClient> client_binding_; |
| 143 | 153 |
| 144 enum State { kUninitialized, kInitializing, kInitialized }; | 154 enum State { kUninitialized, kInitializing, kInitialized }; |
| 145 State state_; | 155 State state_; |
| 146 mojo::ScopedSharedBufferHandle shared_buffer_handle_; | 156 mojo::ScopedSharedBufferHandle shared_buffer_handle_; |
| 147 mojo::ScopedSharedBufferMapping shared_buffer_; | 157 mojo::ScopedSharedBufferMapping shared_buffer_; |
| 148 bool suspended_; | 158 bool suspended_; |
| 149 device::SensorReading reading_; | 159 device::SensorReading reading_; |
| 150 std::pair<double, double> frequency_limits_; | 160 std::pair<double, double> frequency_limits_; |
| 151 | 161 |
| 152 Member<SensorReadingUpdater> reading_updater_; | 162 Member<SensorReadingUpdater> reading_updater_; |
| 153 WTF::Vector<double> frequencies_used_; | 163 WTF::Vector<double> frequencies_used_; |
| 154 double last_raf_timestamp_; | 164 double last_raf_timestamp_; |
| 155 | 165 |
| 156 using ReadingBuffer = device::SensorReadingSharedBuffer; | 166 using ReadingBuffer = device::SensorReadingSharedBuffer; |
| 157 static_assert( | 167 static_assert( |
| 158 sizeof(ReadingBuffer) == | 168 sizeof(ReadingBuffer) == |
| 159 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests, | 169 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests, |
| 160 "Check reading buffer size for tests"); | 170 "Check reading buffer size for tests"); |
| 171 |
| 172 RefPtr<SecurityOrigin> security_origin_; |
| 173 mojo::Binding<mojom::blink::PermissionObserver> binding_; |
| 174 bool permission_subscribed_; |
| 161 }; | 175 }; |
| 162 | 176 |
| 163 } // namespace blink | 177 } // namespace blink |
| 164 | 178 |
| 165 #endif // SensorProxy_h | 179 #endif // SensorProxy_h |
| OLD | NEW |