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

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

Issue 2746573002: [Sensors] Implement bindings for AbsoluteOrientationSensor (Closed)
Patch Set: Comments from Alex Created 3 years, 8 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 SensorProxy_h 5 #ifndef SensorProxy_h
6 #define SensorProxy_h 6 #define SensorProxy_h
7 7
8 #include "core/dom/ExceptionCode.h" 8 #include "core/dom/ExceptionCode.h"
9 #include "core/page/PageVisibilityObserver.h" 9 #include "core/page/PageVisibilityObserver.h"
10 #include "device/generic_sensor/public/cpp/sensor_reading.h" 10 #include "device/generic_sensor/public/cpp/sensor_reading.h"
(...skipping 13 matching lines...) Expand all
24 // This class wraps 'Sensor' mojo interface and used by multiple 24 // This class wraps 'Sensor' mojo interface and used by multiple
25 // JS sensor instances of the same type (within a single frame). 25 // JS sensor instances of the same type (within a single frame).
26 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, 26 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>,
27 public device::mojom::blink::SensorClient, 27 public device::mojom::blink::SensorClient,
28 public PageVisibilityObserver { 28 public PageVisibilityObserver {
29 USING_GARBAGE_COLLECTED_MIXIN(SensorProxy); 29 USING_GARBAGE_COLLECTED_MIXIN(SensorProxy);
30 USING_PRE_FINALIZER(SensorProxy, dispose); 30 USING_PRE_FINALIZER(SensorProxy, dispose);
31 WTF_MAKE_NONCOPYABLE(SensorProxy); 31 WTF_MAKE_NONCOPYABLE(SensorProxy);
32 32
33 public: 33 public:
34 class Observer : public GarbageCollectedMixin { 34 class Client : public GarbageCollectedMixin {
Reilly Grant (use Gerrit) 2017/03/24 15:10:33 Why rename this? It is an observer.
Mikhail 2017/03/24 16:30:31 Agree, the newly added method is actually notifica
35 public: 35 public:
36 // Has valid 'Sensor' binding, {add, remove}Configuration() 36 // Has valid 'Sensor' binding, {add, remove}Configuration()
37 // methods can be called. 37 // methods can be called.
38 virtual void onSensorInitialized() {} 38 virtual void onSensorInitialized() {}
39 // Platfrom sensort reading has changed. 39 // Platfrom sensort reading has changed.
Reilly Grant (use Gerrit) 2017/03/24 15:10:33 sensort -> sensor
Mikhail 2017/03/24 16:30:31 Done.
40 virtual void onSensorReadingChanged() {}
41 // Client should send 'onchange' event if needed.
42 // The 'notifySensorChanged' calls are in sync with rAF.
43 // Currently, we decide whether to send 'onchange' event based on the
44 // time elapsed from the previous notification.
45 // TODO: Reconsider this after https://github.com/w3c/sensors/issues/152
46 // is resolved.
40 // |timestamp| Reference timestamp in seconds of the moment when 47 // |timestamp| Reference timestamp in seconds of the moment when
41 // sensor reading was updated from the buffer. 48 // sensor reading was updated from the buffer.
42 // Note: |timestamp| values are only used to calculate elapsed time 49 // Note: |timestamp| values are only used to calculate elapsed time
43 // between shared buffer readings. These values *do not* correspond 50 // between shared buffer readings. These values *do not* correspond
44 // to sensor reading timestamps which are obtained on platform side. 51 // to sensor reading timestamps which are obtained on platform side.
45 virtual void onSensorReadingChanged(double timestamp) {} 52 virtual void notifySensorChanged(double timestamp) {}
46 // An error has occurred. 53 // An error has occurred.
47 virtual void onSensorError(ExceptionCode, 54 virtual void onSensorError(ExceptionCode,
48 const String& sanitizedMessage, 55 const String& sanitizedMessage,
49 const String& unsanitizedMessage) {} 56 const String& unsanitizedMessage) {}
50 }; 57 };
51 58
52 ~SensorProxy(); 59 ~SensorProxy();
53 60
54 void dispose(); 61 void dispose();
55 62
56 void addObserver(Observer*); 63 void addClient(Client*);
57 void removeObserver(Observer*); 64 void removeClient(Client*);
58 65
59 void initialize(); 66 void initialize();
60 67
61 bool isInitializing() const { return m_state == Initializing; } 68 bool isInitializing() const { return m_state == Initializing; }
62 bool isInitialized() const { return m_state == Initialized; } 69 bool isInitialized() const { return m_state == Initialized; }
63 70
64 // Is watching new reading data (initialized, not suspended and has 71 // Is watching new reading data (initialized, not suspended and has
65 // configurations added). 72 // configurations added).
66 bool isActive() const; 73 bool isActive() const;
67 74
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 std::unique_ptr<Function<void(bool)>> callback, 127 std::unique_ptr<Function<void(bool)>> callback,
121 bool result); 128 bool result);
122 void onRemoveConfigurationCompleted(double frequency, bool result); 129 void onRemoveConfigurationCompleted(double frequency, bool result);
123 130
124 bool tryReadFromBuffer(device::SensorReading& result); 131 bool tryReadFromBuffer(device::SensorReading& result);
125 void onAnimationFrame(double timestamp); 132 void onAnimationFrame(double timestamp);
126 133
127 device::mojom::blink::SensorType m_type; 134 device::mojom::blink::SensorType m_type;
128 device::mojom::blink::ReportingMode m_mode; 135 device::mojom::blink::ReportingMode m_mode;
129 Member<SensorProviderProxy> m_provider; 136 Member<SensorProviderProxy> m_provider;
130 using ObserversSet = HeapHashSet<WeakMember<Observer>>; 137 using ClientsSet = HeapHashSet<WeakMember<Client>>;
131 ObserversSet m_observers; 138 ClientsSet m_clients;
132 139
133 device::mojom::blink::SensorPtr m_sensor; 140 device::mojom::blink::SensorPtr m_sensor;
134 device::mojom::blink::SensorConfigurationPtr m_defaultConfig; 141 device::mojom::blink::SensorConfigurationPtr m_defaultConfig;
135 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding; 142 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding;
136 143
137 enum State { Uninitialized, Initializing, Initialized }; 144 enum State { Uninitialized, Initializing, Initialized };
138 State m_state; 145 State m_state;
139 mojo::ScopedSharedBufferHandle m_sharedBufferHandle; 146 mojo::ScopedSharedBufferHandle m_sharedBufferHandle;
140 mojo::ScopedSharedBufferMapping m_sharedBuffer; 147 mojo::ScopedSharedBufferMapping m_sharedBuffer;
141 bool m_suspended; 148 bool m_suspended;
142 device::SensorReading m_reading; 149 device::SensorReading m_reading;
143 std::pair<double, double> m_frequencyLimits; 150 std::pair<double, double> m_frequencyLimits;
144 151
145 Member<SensorReadingUpdater> m_readingUpdater; 152 Member<SensorReadingUpdater> m_readingUpdater;
146 WTF::Vector<double> m_frequenciesUsed; 153 WTF::Vector<double> m_frequenciesUsed;
147 double m_lastRafTimestamp; 154 double m_lastRafTimestamp;
148 155
149 using ReadingBuffer = device::SensorReadingSharedBuffer; 156 using ReadingBuffer = device::SensorReadingSharedBuffer;
150 static_assert( 157 static_assert(
151 sizeof(ReadingBuffer) == 158 sizeof(ReadingBuffer) ==
152 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests, 159 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests,
153 "Check reading buffer size for tests"); 160 "Check reading buffer size for tests");
154 }; 161 };
155 162
156 } // namespace blink 163 } // namespace blink
157 164
158 #endif // SensorProxy_h 165 #endif // SensorProxy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698