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 #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 Loading... |
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 m_sensorProxy->suspend(); | 180 m_sensorProxy->suspend(); |
189 } else { | 181 } else { |
190 m_sensorProxy->resume(); | 182 m_sensorProxy->resume(); |
191 } | 183 } |
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); |
| 192 DCHECK(m_sensorReading); |
| 193 } |
200 | 194 |
201 m_sensorProxy->addObserver(this); | 195 m_sensorProxy->addObserver(this); |
202 if (m_sensorProxy->isInitialized()) { | 196 if (!m_sensorProxy->isInitialized()) { |
203 auto callback = WTF::bind(&Sensor::onStartRequestCompleted, wrapWeakPers
istent(this)); | 197 m_sensorProxy->initialize(); |
| 198 return; |
| 199 } |
| 200 |
| 201 if (!m_configuration) { |
| 202 m_configuration = createSensorConfig(m_sensorOptions, *m_sensorProxy->de
faultConfig()); |
204 DCHECK(m_configuration); | 203 DCHECK(m_configuration); |
205 m_sensorProxy->addConfiguration(m_configuration->Clone(), std::move(call
back)); | |
206 } else { | |
207 m_sensorProxy->initialize(); | |
208 } | 204 } |
| 205 |
| 206 auto startCallback = WTF::bind(&Sensor::onStartRequestCompleted, wrapWeakPer
sistent(this)); |
| 207 m_sensorProxy->addConfiguration(m_configuration->Clone(), std::move(startCal
lback)); |
209 } | 208 } |
210 | 209 |
211 void Sensor::stopListening() | 210 void Sensor::stopListening() |
212 { | 211 { |
213 DCHECK(m_sensorProxy); | 212 DCHECK(m_sensorProxy); |
214 m_sensorReading = nullptr; | 213 m_sensorReading = nullptr; |
215 updateState(Sensor::SensorState::IDLE); | 214 updateState(Sensor::SensorState::IDLE); |
216 | 215 |
217 if (m_sensorProxy->isInitialized()) { | 216 if (m_sensorProxy->isInitialized()) { |
218 auto callback = WTF::bind(&Sensor::onStopRequestCompleted, wrapWeakPersi
stent(this)); | 217 auto callback = WTF::bind(&Sensor::onStopRequestCompleted, wrapWeakPersi
stent(this)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 263 |
265 if (m_state != Sensor::SensorState::ACTIVE | 264 if (m_state != Sensor::SensorState::ACTIVE |
266 || page()->visibilityState() != PageVisibilityStateVisible) { | 265 || page()->visibilityState() != PageVisibilityStateVisible) { |
267 m_polling->stopPolling(); | 266 m_polling->stopPolling(); |
268 } else { | 267 } else { |
269 m_polling->startPolling(); | 268 m_polling->startPolling(); |
270 } | 269 } |
271 } | 270 } |
272 | 271 |
273 } // namespace blink | 272 } // namespace blink |
OLD | NEW |