OLD | NEW |
---|---|
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 ActiveDOMObject |
haraken
2016/09/07 15:53:43
Change this to ContextLifecycleObserver.
You're n
Mikhail
2016/09/07 18:37:23
Done.
| |
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: |
34 ~Sensor() override; | 36 enum class SensorState { |
37 IDLE, | |
38 ACTIVATING, | |
39 ACTIVE, | |
40 ERRORED | |
41 }; | |
35 | 42 |
36 void start(ScriptState*, ExceptionState&); | 43 void start(ScriptState*, ExceptionState&); |
37 void stop(ScriptState*, ExceptionState&); | 44 void stop(ScriptState*, ExceptionState&); |
38 void updateState(SensorState); | |
39 | 45 |
40 // EventTarget implementation. | 46 // EventTarget overrides. |
41 const AtomicString& interfaceName() const override { return EventTargetNames ::Sensor; } | 47 const AtomicString& interfaceName() const override { return EventTargetNames ::Sensor; } |
42 ExecutionContext* getExecutionContext() const override { return ContextLifec ycleObserver::getExecutionContext(); } | 48 ExecutionContext* getExecutionContext() const override { return ContextLifec ycleObserver::getExecutionContext(); } |
43 | 49 |
44 // Getters | 50 // Getters |
45 String state() const; | 51 String state() const; |
46 // TODO(riju): crbug.com/614797 . | 52 // TODO(riju): crbug.com/614797 . |
47 SensorReading* reading() const; | 53 SensorReading* reading() const; |
48 | 54 |
49 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 55 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
50 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); | 56 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); |
51 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); | 57 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); |
52 | 58 |
53 // ActiveDOMObject implementation. | 59 // ActiveScriptWrappable overrides. |
54 void suspend() override; | |
55 void resume() override; | |
56 void stop() override; | |
57 | |
58 // ScriptWrappable implementation. | |
59 bool hasPendingActivity() const override; | 60 bool hasPendingActivity() const override; |
60 | 61 |
61 DECLARE_VIRTUAL_TRACE(); | 62 DECLARE_VIRTUAL_TRACE(); |
62 | 63 |
64 ~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.
| |
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 // ActiveDOMObject overrides. | |
77 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.
| |
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 |
OLD | NEW |