Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Unified Diff: third_party/WebKit/Source/modules/sensor/Sensor.h

Issue 2051083002: WIP : Generic Sensor API implementation Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 e3d8dd86d549ea3f47b1a8482a0a121dccd8ff9c..b1d558996bb1569472cbd0330d7b6b7f5933c9e8 100644
--- a/third_party/WebKit/Source/modules/sensor/Sensor.h
+++ b/third_party/WebKit/Source/modules/sensor/Sensor.h
@@ -12,8 +12,9 @@
#include "core/frame/PlatformEventController.h"
#include "modules/EventTargetModules.h"
#include "modules/ModulesExport.h"
+#include "modules/sensor/SensorController.h"
#include "modules/sensor/SensorOptions.h"
-#include "modules/sensor/SensorState.h"
+#include "modules/sensor/SensorReading.h"
#include "platform/heap/Handle.h"
namespace blink {
@@ -21,23 +22,28 @@ namespace blink {
class ExceptionState;
class ScriptState;
class SensorReading;
+class SensorPollingStrategy;
class MODULES_EXPORT Sensor
: public EventTargetWithInlineData
, public ActiveScriptWrappable
, public ActiveDOMObject
- , public PlatformEventController {
+ , public SensorController::Observer {
USING_GARBAGE_COLLECTED_MIXIN(Sensor);
DEFINE_WRAPPERTYPEINFO();
public:
- ~Sensor() override;
+ enum class SensorState : int {
+ IDLE,
+ ACTIVATING,
+ ACTIVE,
+ ERRORED
+ };
- void start(ScriptState*, ExceptionState&);
- void stop(ScriptState*, ExceptionState&);
- void updateState(SensorState);
+ virtual void start(ScriptState*, ExceptionState&);
+ virtual void stop(ScriptState*, ExceptionState&);
- // EventTarget implementation.
+ // EventTarget overrides.
const AtomicString& interfaceName() const override { return EventTargetNames::Sensor; }
ExecutionContext* getExecutionContext() const override { return ContextLifecycleObserver::getExecutionContext(); }
@@ -50,21 +56,51 @@ public:
DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange);
- // ActiveDOMObject implementation.
- void suspend() override;
- void resume() override;
- void stop() override;
- bool hasPendingActivity() const override;
-
DECLARE_VIRTUAL_TRACE();
protected:
- Sensor(ExecutionContext*, const SensorOptions&);
- void notifyStateChange();
+ Sensor(ExecutionContext*, const SensorOptions&, device::sensors::blink::SensorType type);
+ virtual SensorReading* createSensorReading() = 0;
+ virtual device::sensors::blink::SensorConfigurationPtr createSensorOptions() = 0;
+
+ // Getters to be used by implementations.
+ const SensorOptions& options() const { return m_sensorOptions; }
+ SensorController* controller() { return m_controller; }
+
+private:
+ void InitControllerIfNeeded();
+
+ // EventTargetWithInlineData overrides.
+ void addedEventListener(const AtomicString& eventType, RegisteredEventListener&) override;
+ void removedEventListener(const AtomicString& eventType, const RegisteredEventListener&) override;
+
+ // ActiveDOMObject overrides.
+ void stop() override {}
+
+ // SensorController::Observer overrides.
+ void onSensorInitialized() override;
+ void onSensorReadingChanged() override;
+ void onSensorError() override;
+
+ // ActiveScriptWrappable overrides.
+ bool hasPendingActivity() const override;
+
+ void onStartRequestCompleted(bool);
+ void onStopRequestCompleted(bool);
+ void pollForData();
+
+ void updateState(SensorState newState);
+ void reportError();
+
+ void updatePollingStatus();
- SensorState m_sensorState;
+private:
Member<SensorReading> m_sensorReading;
SensorOptions m_sensorOptions;
+ device::sensors::blink::SensorType m_type;
+ SensorState m_state;
+ WeakMember<SensorController> m_controller;
+ Member<SensorPollingStrategy> m_polling;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698