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

Side by Side 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, 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/ModulesExport.h"
15 #include "modules/sensor/SensorOptions.h" 16 #include "modules/sensor/SensorOptions.h"
16 #include "modules/sensor/SensorState.h" 17 #include "modules/sensor/SensorProxy.h"
17 #include "platform/heap/Handle.h" 18 #include "platform/heap/Handle.h"
18 19
19 namespace blink { 20 namespace blink {
20 21
21 class ExceptionState; 22 class ExceptionState;
22 class ScriptState; 23 class ScriptState;
23 class SensorReading; 24 class SensorReading;
25 class SensorPollingStrategy;
24 26
25 class MODULES_EXPORT Sensor 27 class MODULES_EXPORT Sensor
26 : public EventTargetWithInlineData 28 : public EventTargetWithInlineData
27 , public ActiveScriptWrappable 29 , public ActiveScriptWrappable
28 , public ActiveDOMObject 30 , public ActiveDOMObject
29 , public PlatformEventController { 31 , public PageVisibilityObserver
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/
32 , public SensorProxy::Observer {
33 USING_PRE_FINALIZER(Sensor, dispose);
30 USING_GARBAGE_COLLECTED_MIXIN(Sensor); 34 USING_GARBAGE_COLLECTED_MIXIN(Sensor);
31 DEFINE_WRAPPERTYPEINFO(); 35 DEFINE_WRAPPERTYPEINFO();
32 36
33 public: 37 public:
34 ~Sensor() override; 38 enum class SensorState {
39 IDLE,
40 ACTIVATING,
41 ACTIVE,
42 ERRORED
43 };
44
45 void dispose();
35 46
36 void start(ScriptState*, ExceptionState&); 47 void start(ScriptState*, ExceptionState&);
37 void stop(ScriptState*, ExceptionState&); 48 void stop(ScriptState*, ExceptionState&);
38 void updateState(SensorState);
39 49
40 // EventTarget implementation. 50 // EventTarget overrides.
41 const AtomicString& interfaceName() const override { return EventTargetNames ::Sensor; } 51 const AtomicString& interfaceName() const override { return EventTargetNames ::Sensor; }
42 ExecutionContext* getExecutionContext() const override { return ContextLifec ycleObserver::getExecutionContext(); } 52 ExecutionContext* getExecutionContext() const override { return ContextLifec ycleObserver::getExecutionContext(); }
43 53
44 // Getters 54 // Getters
45 String state() const; 55 String state() const;
46 // TODO(riju): crbug.com/614797 . 56 // TODO(riju): crbug.com/614797 .
47 SensorReading* reading() const; 57 SensorReading* reading() const;
48 58
49 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 59 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
50 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); 60 DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
51 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); 61 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange);
52 62
53 // ActiveDOMObject implementation. 63 DECLARE_VIRTUAL_TRACE();
54 void suspend() override; 64
55 void resume() override; 65 // ActiveScriptWrappable overrides.
66 bool hasPendingActivity() const override;
67
68 protected:
69 Sensor(ExecutionContext*, const SensorOptions&, device::mojom::blink::Sensor Type);
70 virtual SensorReading* createSensorReading(ExecutionContext*) = 0;
71 virtual device::mojom::blink::SensorConfigurationPtr createSensorOptions(con st SensorOptions&) = 0;
72
73 private:
74 void initSensorProxyIfNeeded();
75
76 // EventTargetWithInlineData overrides.
77 void addedEventListener(const AtomicString& eventType, RegisteredEventListen er&) override;
78 void removedEventListener(const AtomicString& eventType, const RegisteredEve ntListener&) override;
79
80 // ActiveDOMObject overrides.
56 void stop() override; 81 void stop() override;
57 82
58 // ScriptWrappable implementation. 83 // SensorController::Observer overrides.
59 bool hasPendingActivity() const override; 84 void onSensorInitialized() override;
85 void onSensorReadingChanged() override;
86 void onSensorError() override;
60 87
61 DECLARE_VIRTUAL_TRACE(); 88 void onStartRequestCompleted(bool);
89 void onStopRequestCompleted(bool);
62 90
63 protected: 91 // PageVisibilityObserver overrides.
64 Sensor(ExecutionContext*, const SensorOptions&); 92 void pageVisibilityChanged() override;
65 void notifyStateChange();
66 93
67 SensorState m_sensorState; 94 void startListening();
95 void stopListening();
96
97 // Makes sensor reading refresh its values from the shared buffer.
98 void pollForData();
99
100 void updateState(SensorState newState);
101 void reportError();
102
103 void updatePollingStatus();
104
105 private:
68 Member<SensorReading> m_sensorReading; 106 Member<SensorReading> m_sensorReading;
69 SensorOptions m_sensorOptions; 107 SensorOptions m_sensorOptions;
108 device::mojom::blink::SensorType m_type;
109 SensorState m_state;
110 WeakMember<SensorProxy> m_sensorProxy;
111 Member<SensorPollingStrategy> m_polling;
70 }; 112 };
71 113
72 } // namespace blink 114 } // namespace blink
73 115
74 #endif // Sensor_h 116 #endif // Sensor_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698