Chromium Code Reviews| 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/page/PageVisibilityObserver.h" | |
| 8 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" | 9 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" |
| 9 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" | 10 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" |
| 10 #include "mojo/public/cpp/bindings/binding.h" | 11 #include "mojo/public/cpp/bindings/binding.h" |
| 11 #include "platform/Supplementable.h" | 12 #include "platform/Supplementable.h" |
| 12 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 class SensorProviderProxy; | 17 class SensorProviderProxy; |
| 17 | 18 |
| 18 // This class wraps 'Sensor' mojo interface and used by multiple | 19 // This class wraps 'Sensor' mojo interface and used by multiple |
| 19 // JS sensor instances of the same type (within a single frame). | 20 // JS sensor instances of the same type (within a single frame). |
| 20 class SensorProxy final | 21 class SensorProxy final |
| 21 : public GarbageCollectedFinalized<SensorProxy> | 22 : public GarbageCollectedFinalized<SensorProxy> |
| 22 , public device::mojom::blink::SensorClient { | 23 , public device::mojom::blink::SensorClient |
| 24 , public PageVisibilityObserver { | |
|
haraken
2016/09/08 11:07:13
Sensor is already a PageVisibilityObserver. Can we
Mikhail
2016/09/08 11:24:48
Tim raised the same concern at https://codereview.
| |
| 25 USING_GARBAGE_COLLECTED_MIXIN(SensorProxy); | |
| 23 USING_PRE_FINALIZER(SensorProxy, dispose); | 26 USING_PRE_FINALIZER(SensorProxy, dispose); |
| 24 WTF_MAKE_NONCOPYABLE(SensorProxy); | 27 WTF_MAKE_NONCOPYABLE(SensorProxy); |
| 25 public: | 28 public: |
| 26 class Observer : public GarbageCollectedMixin { | 29 class Observer : public GarbageCollectedMixin { |
| 27 public: | 30 public: |
| 28 // Has valid 'Sensor' binding, {add, remove}Configuration() | 31 // Has valid 'Sensor' binding, {add, remove}Configuration() |
| 29 // methods can be called. | 32 // methods can be called. |
| 30 virtual void onSensorInitialized() {} | 33 virtual void onSensorInitialized() {} |
| 31 // Platfrom sensort reading has changed (for 'ONCHANGE' reporting mode). | 34 // Platfrom sensort reading has changed (for 'ONCHANGE' reporting mode). |
| 32 virtual void onSensorReadingChanged() {} | 35 virtual void onSensorReadingChanged() {} |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 60 | 63 |
| 61 const Reading& reading() const { return m_reading; } | 64 const Reading& reading() const { return m_reading; } |
| 62 | 65 |
| 63 // Updates internal reading from shared buffer. | 66 // Updates internal reading from shared buffer. |
| 64 void updateInternalReading(); | 67 void updateInternalReading(); |
| 65 | 68 |
| 66 DECLARE_VIRTUAL_TRACE(); | 69 DECLARE_VIRTUAL_TRACE(); |
| 67 | 70 |
| 68 private: | 71 private: |
| 69 friend class SensorProviderProxy; | 72 friend class SensorProviderProxy; |
| 70 SensorProxy(device::mojom::blink::SensorType, SensorProviderProxy*); | 73 SensorProxy(device::mojom::blink::SensorType, Page*, SensorProviderProxy*); |
| 71 | 74 |
| 72 // device::mojom::blink::SensorClient overrides. | 75 // device::mojom::blink::SensorClient overrides. |
| 73 void RaiseError() override; | 76 void RaiseError() override; |
| 74 void SensorReadingChanged() override; | 77 void SensorReadingChanged() override; |
| 75 | 78 |
| 79 // PageVisibilityObserver overrides. | |
| 80 void pageVisibilityChanged() override; | |
| 81 | |
| 76 // Generic handler for a fatal error. | 82 // Generic handler for a fatal error. |
| 77 void handleSensorError(); | 83 void handleSensorError(); |
| 78 | 84 |
| 79 void onSensorCreated(device::mojom::blink::SensorReadBufferPtr, device::mojo m::blink::SensorClientRequest); | 85 void onSensorCreated(device::mojom::blink::SensorReadBufferPtr, device::mojo m::blink::SensorClientRequest); |
| 80 | 86 |
| 81 device::mojom::blink::SensorType m_type; | 87 device::mojom::blink::SensorType m_type; |
| 82 device::mojom::blink::ReportingMode m_mode; | 88 device::mojom::blink::ReportingMode m_mode; |
| 83 Member<SensorProviderProxy> m_provider; | 89 Member<SensorProviderProxy> m_provider; |
| 84 using ObserversSet = HeapHashSet<WeakMember<Observer>>; | 90 using ObserversSet = HeapHashSet<WeakMember<Observer>>; |
| 85 ObserversSet m_observers; | 91 ObserversSet m_observers; |
| 86 | 92 |
| 87 device::mojom::blink::SensorPtr m_sensor; | 93 device::mojom::blink::SensorPtr m_sensor; |
| 88 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding; | 94 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding; |
| 89 enum State { | 95 enum State { |
| 90 Uninitialized, | 96 Uninitialized, |
| 91 Initializing, | 97 Initializing, |
| 92 Initialized | 98 Initialized |
| 93 }; | 99 }; |
| 94 State m_state; | 100 State m_state; |
| 95 mojo::ScopedSharedBufferHandle m_sharedBufferHandle; | 101 mojo::ScopedSharedBufferHandle m_sharedBufferHandle; |
| 96 mojo::ScopedSharedBufferMapping m_sharedBuffer; | 102 mojo::ScopedSharedBufferMapping m_sharedBuffer; |
| 97 Reading m_reading; | 103 Reading m_reading; |
| 98 }; | 104 }; |
| 99 | 105 |
| 100 } // namespace blink | 106 } // namespace blink |
| 101 | 107 |
| 102 #endif // SensorProxy_h | 108 #endif // SensorProxy_h |
| OLD | NEW |