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

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: Rebased 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 5e37b2d3455d5056c4e45d7c08bf3297ca33b843..a0fab4e560099e29e6e80d8029aaaf66a579439e 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 {
timvolodine 2016/08/25 17:52:32 can we actually re-use the PlatformEventController
Mikhail 2016/08/26 16:42:41 PageVisibilityObserver is more convenient as we ha
timvolodine 2016/09/01 19:02:05 in the PlatformEventController we have a special m
Mikhail 2016/09/02 08:23:43 Yes. According to the spec (https://w3c.github.io/
+ , 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 +60,55 @@ public:
DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange);
- // ActiveDOMObject implementation.
- void suspend() override;
- void resume() override;
- void stop() override;
+ DECLARE_VIRTUAL_TRACE();
- // 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;
+ 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;
+
+ 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;
+ Member<SensorPollingStrategy> m_polling;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698