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

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

Issue 2121313002: [sensors] Generic Sensors Framework blink side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sensors_mojo_interfaces
Patch Set: Use 'SuspenNotification' API Created 4 years, 4 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..eef77cedc777a8de6ecfff92639b36d63536552a 100644
--- a/third_party/WebKit/Source/modules/sensor/Sensor.h
+++ b/third_party/WebKit/Source/modules/sensor/Sensor.h
@@ -10,10 +10,11 @@
#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 +22,32 @@ namespace blink {
class ExceptionState;
class ScriptState;
class SensorReading;
+class SensorPollingStrategy;
class MODULES_EXPORT 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,21 +60,55 @@ public:
DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange);
- // ActiveDOMObject implementation.
- void suspend() override;
- void resume() override;
+ DECLARE_VIRTUAL_TRACE();
+
+protected:
+ Sensor(ExecutionContext*, const SensorOptions&, device::mojom::blink::SensorType);
+ virtual SensorReading* createSensorReading(ExecutionContext*) = 0;
+ virtual device::mojom::blink::SensorConfigurationPtr createSensorOptions(const SensorOptions&) = 0;
+
+private:
+ void initSensorProxyIfNeeded();
+
+ // 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;
- DECLARE_VIRTUAL_TRACE();
+ void onStartRequestCompleted(bool);
+ void onStopRequestCompleted(bool);
-protected:
- Sensor(ExecutionContext*, const SensorOptions&);
- void notifyStateChange();
+ // 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;
+ Member<SensorPollingStrategy> m_polling;
};
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/OWNERS ('k') | third_party/WebKit/Source/modules/sensor/Sensor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698