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

Side by Side Diff: third_party/WebKit/Source/modules/sensor/Sensor.h

Issue 2317743002: [Sensors] Implementation of the Generic Sensor API (Closed)
Patch Set: Comments from Tim and haraken 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef Sensor_h 5 #ifndef Sensor_h
6 #define Sensor_h 6 #define Sensor_h
7 7
8 #include "bindings/core/v8/ActiveScriptWrappable.h" 8 #include "bindings/core/v8/ActiveScriptWrappable.h"
9 #include "bindings/core/v8/ScriptWrappable.h" 9 #include "bindings/core/v8/ScriptWrappable.h"
10 #include "core/dom/ActiveDOMObject.h" 10 #include "core/dom/ActiveDOMObject.h"
11 #include "core/dom/ContextLifecycleObserver.h" 11 #include "core/dom/ContextLifecycleObserver.h"
12 #include "core/frame/PlatformEventController.h" 12 #include "core/frame/PlatformEventController.h"
13 #include "core/page/PageVisibilityObserver.h"
13 #include "modules/EventTargetModules.h" 14 #include "modules/EventTargetModules.h"
14 #include "modules/ModulesExport.h"
15 #include "modules/sensor/SensorOptions.h" 15 #include "modules/sensor/SensorOptions.h"
16 #include "modules/sensor/SensorState.h" 16 #include "modules/sensor/SensorProxy.h"
17 #include "platform/heap/Handle.h" 17 #include "platform/heap/Handle.h"
18 18
19 namespace blink { 19 namespace blink {
20 20
21 class ExceptionState; 21 class ExceptionState;
22 class ScriptState; 22 class ScriptState;
23 class SensorReading; 23 class SensorReading;
24 class SensorPollingStrategy;
24 25
25 class MODULES_EXPORT Sensor 26 class Sensor
26 : public EventTargetWithInlineData 27 : public EventTargetWithInlineData
27 , public ActiveScriptWrappable 28 , public ActiveScriptWrappable
28 , public ActiveDOMObject 29 , public ContextLifecycleObserver
29 , public PlatformEventController { 30 , public PageVisibilityObserver
31 , public SensorProxy::Observer {
30 USING_GARBAGE_COLLECTED_MIXIN(Sensor); 32 USING_GARBAGE_COLLECTED_MIXIN(Sensor);
31 DEFINE_WRAPPERTYPEINFO(); 33 DEFINE_WRAPPERTYPEINFO();
32 34
33 public: 35 public:
36 enum class SensorState {
37 IDLE,
38 ACTIVATING,
39 ACTIVE,
40 ERRORED
41 };
42
34 ~Sensor() override; 43 ~Sensor() override;
35 44
36 void start(ScriptState*, ExceptionState&); 45 void start(ScriptState*, ExceptionState&);
37 void stop(ScriptState*, ExceptionState&); 46 void stop(ScriptState*, ExceptionState&);
38 void updateState(SensorState);
39 47
40 // EventTarget implementation. 48 // EventTarget overrides.
41 const AtomicString& interfaceName() const override { return EventTargetNames ::Sensor; } 49 const AtomicString& interfaceName() const override { return EventTargetNames ::Sensor; }
42 ExecutionContext* getExecutionContext() const override { return ContextLifec ycleObserver::getExecutionContext(); } 50 ExecutionContext* getExecutionContext() const override { return ContextLifec ycleObserver::getExecutionContext(); }
43 51
44 // Getters 52 // Getters
45 String state() const; 53 String state() const;
46 // TODO(riju): crbug.com/614797 . 54 // TODO(riju): crbug.com/614797 .
47 SensorReading* reading() const; 55 SensorReading* reading() const;
48 56
49 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 57 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
50 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); 58 DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
51 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); 59 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange);
52 60
53 // ActiveDOMObject implementation. 61 // ActiveScriptWrappable overrides.
54 void suspend() override;
55 void resume() override;
56 void stop() override;
57
58 // ScriptWrappable implementation.
59 bool hasPendingActivity() const override; 62 bool hasPendingActivity() const override;
60 63
61 DECLARE_VIRTUAL_TRACE(); 64 DECLARE_VIRTUAL_TRACE();
62 65
63 protected: 66 protected:
64 Sensor(ExecutionContext*, const SensorOptions&); 67 Sensor(ExecutionContext*, const SensorOptions&, device::mojom::blink::Sensor Type);
65 void notifyStateChange(); 68 virtual SensorReading* createSensorReading(SensorProxy*) = 0;
66 69
67 SensorState m_sensorState; 70 using SensorConfigurationPtr = device::mojom::blink::SensorConfigurationPtr;
71 virtual SensorConfigurationPtr createSensorConfig(const SensorOptions&) = 0;
72
73 private:
74 void initSensorProxyIfNeeded();
75
76 // ContextLifecycleObserver overrides.
77 void contextDestroyed() override;
78
79 // SensorController::Observer overrides.
80 void onSensorInitialized() override;
81 void onSensorReadingChanged() override;
82 void onSensorError() override;
83
84 void onStartRequestCompleted(bool);
85 void onStopRequestCompleted(bool);
86
87 // PageVisibilityObserver overrides.
88 void pageVisibilityChanged() override;
89
90 void startListening();
91 void stopListening();
92
93 // Makes sensor reading refresh its values from the shared buffer.
94 void pollForData();
95
96 void updateState(SensorState newState);
97 void reportError();
98
99 void updatePollingStatus();
100
101 private:
68 Member<SensorReading> m_sensorReading; 102 Member<SensorReading> m_sensorReading;
69 SensorOptions m_sensorOptions; 103 SensorOptions m_sensorOptions;
104 device::mojom::blink::SensorType m_type;
105 SensorState m_state;
106 Member<SensorProxy> m_sensorProxy;
107 std::unique_ptr<SensorPollingStrategy> m_polling;
108 SensorProxy::Reading m_storedData;
109 SensorConfigurationPtr m_configuration;
70 }; 110 };
71 111
72 } // namespace blink 112 } // namespace blink
73 113
74 #endif // Sensor_h 114 #endif // Sensor_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/BUILD.gn ('k') | third_party/WebKit/Source/modules/sensor/Sensor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698