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

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

Issue 2317743002: [Sensors] Implementation of the Generic Sensor API (Closed)
Patch Set: rebased Created 4 years, 3 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..3f00caeb0448c9bcb3d54159e05bb3ca192dedd6 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,29 @@ namespace blink {
class ExceptionState;
class ScriptState;
class SensorReading;
+class SensorPollingStrategy;
-class MODULES_EXPORT Sensor
+class Sensor
: public EventTargetWithInlineData
, public ActiveScriptWrappable
, public ActiveDOMObject
haraken 2016/09/07 15:53:43 Change this to ContextLifecycleObserver. You're n
Mikhail 2016/09/07 18:37:23 Done.
- , public PlatformEventController {
+ , public PageVisibilityObserver
+ , public SensorProxy::Observer {
USING_GARBAGE_COLLECTED_MIXIN(Sensor);
DEFINE_WRAPPERTYPEINFO();
public:
- ~Sensor() override;
+ enum class SensorState {
+ IDLE,
+ ACTIVATING,
+ ACTIVE,
+ ERRORED
+ };
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 +56,57 @@ 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();
+ ~Sensor();
timvolodine 2016/09/07 17:04:10 virtual or override nit: also, I think usually be
Mikhail 2016/09/07 18:37:23 Done.
+
protected:
- Sensor(ExecutionContext*, const SensorOptions&);
- void notifyStateChange();
+ Sensor(ExecutionContext*, const SensorOptions&, device::mojom::blink::SensorType);
+ virtual SensorReading* createSensorReading(SensorProxy*) = 0;
+
+ using SensorConfigurationPtr = device::mojom::blink::SensorConfigurationPtr;
+ virtual SensorConfigurationPtr createSensorConfig(const SensorOptions&) = 0;
+
+private:
+ void initSensorProxyIfNeeded();
+
+ // ActiveDOMObject overrides.
+ void stop() override;
haraken 2016/09/07 15:53:43 Then this method can be contextDestroyed(); i.e.,
Mikhail 2016/09/07 18:37:23 Done.
+
+ // 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;
+ Member<SensorProxy> m_sensorProxy;
+ std::unique_ptr<SensorPollingStrategy> m_polling;
+ SensorProxy::Reading m_storedData;
+ SensorConfigurationPtr m_configuration;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698