Chromium Code Reviews| Index: third_party/WebKit/Source/modules/sensor/SensorProxy.h |
| diff --git a/third_party/WebKit/Source/modules/sensor/SensorProxy.h b/third_party/WebKit/Source/modules/sensor/SensorProxy.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9f1538ca5cd5c932d63e77f9af1dc498a1f9e4b7 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/sensor/SensorProxy.h |
| @@ -0,0 +1,101 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef SensorProxy_h |
| +#define SensorProxy_h |
| + |
| +#include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" |
| +#include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" |
| +#include "modules/ModulesExport.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| +#include "platform/Supplementable.h" |
| +#include "platform/heap/Handle.h" |
| + |
| +namespace blink { |
| + |
| +class SensorProviderProxy; |
| + |
| +// This class wraps 'Sensor' mojo interface and used by multiple |
| +// JS sensor instances (within a single frame). |
|
timvolodine
2016/08/25 17:52:33
sensor instances of the same type?
Mikhail
2016/08/26 16:42:42
yes (comment is updated in the latest patch)
|
| +class MODULES_EXPORT SensorProxy final |
| + : public GarbageCollectedFinalized<SensorProxy> |
| + , public device::mojom::blink::SensorClient { |
| + USING_PRE_FINALIZER(SensorProxy, dispose); |
| + WTF_MAKE_NONCOPYABLE(SensorProxy); |
| +public: |
| + class Observer : public GarbageCollectedMixin { |
| + public: |
| + // Has valid 'Sensor' binding, add(remove)Configuration() |
|
timvolodine
2016/08/25 17:52:33
nit: {add,remove}Configuration
Mikhail
2016/08/26 16:42:42
Done.
|
| + // methods can be called. |
| + virtual void onSensorInitialized() {} |
| + // Platfrom sensort reading has changed (for 'ONCHANGE' reporting mode). |
| + virtual void onSensorReadingChanged() {} |
| + // An error has occurred. |
| + virtual void onSensorError() {} |
| + }; |
| + |
| + ~SensorProxy(); |
| + |
| + void dispose(); |
| + |
| + void addObserver(Observer*); |
| + void removeObserver(Observer*); |
| + |
| + void initialize(); |
| + |
| + bool isInitializing() const { return m_state == Initializing; } |
| + bool isInitialized() const { return m_state == Initialized; } |
| + |
| + void addConfiguration(device::mojom::blink::SensorConfigurationPtr, std::unique_ptr<Function<void(bool)>>); |
| + void removeConfiguration(device::mojom::blink::SensorConfigurationPtr, std::unique_ptr<Function<void(bool)>>); |
| + |
| + void suspend(); |
| + void resume(); |
| + |
| + device::mojom::blink::SensorType type() const { return m_type; } |
| + device::mojom::blink::ReportingMode reportingMode() const { return m_mode; } |
| + |
| + template <typename Reading> |
| + const Reading* reading() const |
| + { |
| + DCHECK(m_sharedBuffer); |
| + static_assert(sizeof(Reading) == device::mojom::blink::SensorReadBuffer::kReadBufferSize, "Check reading size"); |
| + return static_cast<Reading*>(m_sharedBuffer.get()); |
| + } |
| + |
| + DECLARE_VIRTUAL_TRACE(); |
| + |
| +private: |
| + friend class SensorProviderProxy; |
| + SensorProxy(device::mojom::blink::SensorType, SensorProviderProxy*); |
| + |
| + // device::mojom::blink::SensorClient overrides. |
| + void RaiseError() override; |
| + void SensorReadingChanged() override; |
| + |
| + void handleSensorError(); |
| + |
| + void onSensorCreated(device::mojom::blink::SensorReadBufferPtr, device::mojom::blink::SensorClientRequest); |
| + |
| + device::mojom::blink::SensorType m_type; |
| + device::mojom::blink::ReportingMode m_mode; |
| + Member<SensorProviderProxy> m_provider; |
| + using ObserversSet = HeapHashSet<WeakMember<Observer>>; |
| + ObserversSet m_observers; |
| + |
| + device::mojom::blink::SensorPtr m_sensor; |
| + mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding; |
| + enum State { |
| + Uninitialized, |
| + Initializing, |
| + Initialized |
| + }; |
| + State m_state; |
| + mojo::ScopedSharedBufferHandle m_sharedBufferHandle; |
| + mojo::ScopedSharedBufferMapping m_sharedBuffer; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // SensorProxy_h |