Chromium Code Reviews| Index: third_party/WebKit/Source/modules/sensor/Sensor.h |
| diff --git a/third_party/WebKit/Source/modules/sensor/Sensor.h b/third_party/WebKit/Source/modules/sensor/Sensor.h |
| index 5e37b2d3455d5056c4e45d7c08bf3297ca33b843..f9a44880aac5e79dd0206538c91c814613b59fd2 100644 |
| --- a/third_party/WebKit/Source/modules/sensor/Sensor.h |
| +++ b/third_party/WebKit/Source/modules/sensor/Sensor.h |
| @@ -10,10 +10,10 @@ |
| #include "core/dom/ActiveDOMObject.h" |
| #include "core/dom/ContextLifecycleObserver.h" |
| #include "core/frame/PlatformEventController.h" |
| +#include "core/page/PageVisibilityObserver.h" |
| #include "modules/EventTargetModules.h" |
| -#include "modules/ModulesExport.h" |
| #include "modules/sensor/SensorOptions.h" |
| -#include "modules/sensor/SensorState.h" |
| +#include "modules/sensor/SensorProxy.h" |
| #include "platform/heap/Handle.h" |
| namespace blink { |
| @@ -21,23 +21,32 @@ namespace blink { |
| class ExceptionState; |
| class ScriptState; |
| class SensorReading; |
| +class SensorPollingStrategy; |
| -class MODULES_EXPORT Sensor |
| +class Sensor |
| : public EventTargetWithInlineData |
| , public ActiveScriptWrappable |
| , public ActiveDOMObject |
| - , public PlatformEventController { |
| + , public PageVisibilityObserver |
| + , public SensorProxy::Observer { |
| + USING_PRE_FINALIZER(Sensor, dispose); |
| USING_GARBAGE_COLLECTED_MIXIN(Sensor); |
| DEFINE_WRAPPERTYPEINFO(); |
| public: |
| - ~Sensor() override; |
| + enum class SensorState { |
| + IDLE, |
| + ACTIVATING, |
| + ACTIVE, |
| + ERRORED |
| + }; |
| + |
| + void dispose(); |
| void start(ScriptState*, ExceptionState&); |
| void stop(ScriptState*, ExceptionState&); |
| - void updateState(SensorState); |
| - // EventTarget implementation. |
| + // EventTarget overrides. |
| const AtomicString& interfaceName() const override { return EventTargetNames::Sensor; } |
| ExecutionContext* getExecutionContext() const override { return ContextLifecycleObserver::getExecutionContext(); } |
| @@ -50,23 +59,56 @@ public: |
| DEFINE_ATTRIBUTE_EVENT_LISTENER(change); |
| DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); |
| - // ActiveDOMObject implementation. |
| - void suspend() override; |
| - void resume() override; |
| - void stop() override; |
| - |
| - // ScriptWrappable implementation. |
| + // ActiveScriptWrappable overrides. |
| bool hasPendingActivity() const override; |
| DECLARE_VIRTUAL_TRACE(); |
| protected: |
| - Sensor(ExecutionContext*, const SensorOptions&); |
| - void notifyStateChange(); |
| + Sensor(ExecutionContext*, const SensorOptions&, device::mojom::blink::SensorType); |
| + virtual SensorReading* createSensorReading(ExecutionContext*) = 0; |
| + |
| + using SensorConfiguration = device::mojom::blink::SensorConfiguration; |
| + using SensorConfigurationPtr = device::mojom::blink::SensorConfigurationPtr; |
| + virtual SensorConfigurationPtr createSensorConfig(const SensorOptions&, const SensorConfiguration* defaultConfig) = 0; |
| + |
| +private: |
| + void initSensorProxyIfNeeded(); |
| + |
| + // ActiveDOMObject overrides. |
| + void stop() override; |
| + |
| + // SensorController::Observer overrides. |
| + void onSensorInitialized() override; |
| + void onSensorReadingChanged() override; |
| + void onSensorError() override; |
| + |
| + void onStartRequestCompleted(bool); |
| + void onStopRequestCompleted(bool); |
| + |
| + // PageVisibilityObserver overrides. |
| + void pageVisibilityChanged() override; |
| + |
| + void startListening(); |
| + void stopListening(); |
| + |
| + // Makes sensor reading refresh its values from the shared buffer. |
| + void pollForData(); |
| + |
| + void updateState(SensorState newState); |
| + void reportError(); |
| + |
| + void updatePollingStatus(); |
| - SensorState m_sensorState; |
| +private: |
| Member<SensorReading> m_sensorReading; |
| SensorOptions m_sensorOptions; |
| + device::mojom::blink::SensorType m_type; |
| + SensorState m_state; |
| + WeakMember<SensorProxy> m_sensorProxy; |
|
haraken
2016/09/06 05:04:28
Is there any reason you want to make this a weak m
Mikhail
2016/09/06 07:13:58
m_sensorProxy might get deleted if a problem turns
|
| + Member<SensorPollingStrategy> m_polling; |
| + SensorProxy::Reading m_storedData; |
| + SensorConfigurationPtr m_configuration; |
| }; |
| } // namespace blink |