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

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

Issue 2330943002: [Sensors] Handle default sensor configuration (Closed)
Patch Set: 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 #include "modules/sensor/Sensor.h" 5 #include "modules/sensor/Sensor.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/ExceptionCode.h" 8 #include "core/dom/ExceptionCode.h"
9 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" 9 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
10 #include "modules/sensor/SensorErrorEvent.h" 10 #include "modules/sensor/SensorErrorEvent.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 { 118 {
119 if (m_state == Sensor::SensorState::ACTIVE || m_state == Sensor::SensorState ::ACTIVATING) 119 if (m_state == Sensor::SensorState::ACTIVE || m_state == Sensor::SensorState ::ACTIVATING)
120 stopListening(); 120 stopListening();
121 } 121 }
122 122
123 void Sensor::onSensorInitialized() 123 void Sensor::onSensorInitialized()
124 { 124 {
125 if (m_state != Sensor::SensorState::ACTIVATING) 125 if (m_state != Sensor::SensorState::ACTIVATING)
126 return; 126 return;
127 127
128 m_configuration = createSensorConfig(m_sensorOptions); 128 startListening();
129 if (!m_configuration) {
130 reportError();
131 return;
132 }
133
134 DCHECK(m_sensorProxy);
135 auto startCallback = WTF::bind(&Sensor::onStartRequestCompleted, wrapWeakPer sistent(this));
136 m_sensorProxy->addConfiguration(m_configuration->Clone(), std::move(startCal lback));
137 } 129 }
138 130
139 void Sensor::onSensorReadingChanged() 131 void Sensor::onSensorReadingChanged()
140 { 132 {
141 if (m_polling) 133 if (m_polling)
142 m_polling->onSensorReadingChanged(); 134 m_polling->onSensorReadingChanged();
143 } 135 }
144 136
145 void Sensor::onSensorError() 137 void Sensor::onSensorError()
146 { 138 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 184 }
193 185
194 void Sensor::startListening() 186 void Sensor::startListening()
195 { 187 {
196 DCHECK(m_sensorProxy); 188 DCHECK(m_sensorProxy);
197 updateState(Sensor::SensorState::ACTIVATING); 189 updateState(Sensor::SensorState::ACTIVATING);
198 if (!m_sensorReading) 190 if (!m_sensorReading)
199 m_sensorReading = createSensorReading(m_sensorProxy); 191 m_sensorReading = createSensorReading(m_sensorProxy);
200 192
201 m_sensorProxy->addObserver(this); 193 m_sensorProxy->addObserver(this);
202 if (m_sensorProxy->isInitialized()) { 194 if (!m_sensorProxy->isInitialized()) {
203 auto callback = WTF::bind(&Sensor::onStartRequestCompleted, wrapWeakPers istent(this));
204 DCHECK(m_configuration);
205 m_sensorProxy->addConfiguration(m_configuration->Clone(), std::move(call back));
206 } else {
207 m_sensorProxy->initialize(); 195 m_sensorProxy->initialize();
196 return;
208 } 197 }
198
199 if (!m_configuration) {
200 DCHECK(m_sensorProxy->defaultConfig());
timvolodine 2016/09/12 16:37:08 should this check be in sensorProxy itself, perhap
Mikhail 2016/09/12 17:08:10 right, the DCHECK can be omitted I just put it to
201 m_configuration = createSensorConfig(m_sensorOptions, *m_sensorProxy->de faultConfig());
202 if (!m_configuration) { // Failed to create configuration.
timvolodine 2016/09/12 16:37:08 when can this happen? maybe just DCHECK here?
Mikhail 2016/09/12 17:08:10 can be DCHECK() (given options checks can/should b
203 reportError();
204 return;
205 }
206 }
207
208 auto startCallback = WTF::bind(&Sensor::onStartRequestCompleted, wrapWeakPer sistent(this));
209 m_sensorProxy->addConfiguration(m_configuration->Clone(), std::move(startCal lback));
209 } 210 }
210 211
211 void Sensor::stopListening() 212 void Sensor::stopListening()
212 { 213 {
213 DCHECK(m_sensorProxy); 214 DCHECK(m_sensorProxy);
214 m_sensorReading = nullptr; 215 m_sensorReading = nullptr;
215 updateState(Sensor::SensorState::IDLE); 216 updateState(Sensor::SensorState::IDLE);
216 217
217 if (m_sensorProxy->isInitialized()) { 218 if (m_sensorProxy->isInitialized()) {
218 auto callback = WTF::bind(&Sensor::onStopRequestCompleted, wrapWeakPersi stent(this)); 219 auto callback = WTF::bind(&Sensor::onStopRequestCompleted, wrapWeakPersi stent(this));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 265
265 if (m_state != Sensor::SensorState::ACTIVE 266 if (m_state != Sensor::SensorState::ACTIVE
266 || page()->visibilityState() != PageVisibilityStateVisible) { 267 || page()->visibilityState() != PageVisibilityStateVisible) {
267 m_polling->stopPolling(); 268 m_polling->stopPolling();
268 } else { 269 } else {
269 m_polling->startPolling(); 270 m_polling->startPolling();
270 } 271 }
271 } 272 }
272 273
273 } // namespace blink 274 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698