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

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: Use 'SuspenNotification' API 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 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
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.
54 void suspend() override;
55 void resume() override;
56 void stop() override;
57 bool hasPendingActivity() const override;
58
59 DECLARE_VIRTUAL_TRACE(); 63 DECLARE_VIRTUAL_TRACE();
60 64
61 protected: 65 protected:
62 Sensor(ExecutionContext*, const SensorOptions&); 66 Sensor(ExecutionContext*, const SensorOptions&, device::mojom::blink::Sensor Type);
63 void notifyStateChange(); 67 virtual SensorReading* createSensorReading(ExecutionContext*) = 0;
68 virtual device::mojom::blink::SensorConfigurationPtr createSensorOptions(con st SensorOptions&) = 0;
64 69
65 SensorState m_sensorState; 70 private:
71 void initSensorProxyIfNeeded();
72
73 // EventTargetWithInlineData overrides.
74 void addedEventListener(const AtomicString& eventType, RegisteredEventListen er&) override;
75 void removedEventListener(const AtomicString& eventType, const RegisteredEve ntListener&) override;
76
77 // ActiveDOMObject overrides.
78 void stop() override;
79
80 // SensorController::Observer overrides.
81 void onSensorInitialized() override;
82 void onSensorReadingChanged() override;
83 void onSensorError() override;
84
85 // ActiveScriptWrappable overrides.
86 bool hasPendingActivity() const override;
87
88 void onStartRequestCompleted(bool);
89 void onStopRequestCompleted(bool);
90
91 // PageVisibilityObserver overrides.
92 void pageVisibilityChanged() override;
93
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:
66 Member<SensorReading> m_sensorReading; 106 Member<SensorReading> m_sensorReading;
67 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;
68 }; 112 };
69 113
70 } // namespace blink 114 } // namespace blink
71 115
72 #endif // Sensor_h 116 #endif // Sensor_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/OWNERS ('k') | third_party/WebKit/Source/modules/sensor/Sensor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698