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

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

Issue 2323683002: [Sensors] Implement sensor data polling (Closed)
Patch Set: Applied Tim's suggestions 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/sensor/SensorPollingStrategy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 return; 153 return;
154 154
155 if (!result) { 155 if (!result) {
156 reportError(); 156 reportError();
157 return; 157 return;
158 } 158 }
159 159
160 DCHECK(m_configuration); 160 DCHECK(m_configuration);
161 DCHECK(m_sensorProxy); 161 DCHECK(m_sensorProxy);
162 auto pollCallback = WTF::bind(&Sensor::pollForData, wrapWeakPersistent(this) ); 162 auto pollCallback = WTF::bind(&Sensor::pollForData, wrapWeakPersistent(this) );
163 m_polling = SensorPollingStrategy::create(m_configuration->frequency, std::m ove(pollCallback), m_sensorProxy->reportingMode()); 163 DCHECK_GT(m_configuration->frequency, 0);
164 m_polling = SensorPollingStrategy::create(1 / m_configuration->frequency, st d::move(pollCallback), m_sensorProxy->reportingMode());
164 updateState(Sensor::SensorState::ACTIVE); 165 updateState(Sensor::SensorState::ACTIVE);
165 } 166 }
166 167
167 void Sensor::onStopRequestCompleted(bool result) 168 void Sensor::onStopRequestCompleted(bool result)
168 { 169 {
169 if (m_state == Sensor::SensorState::IDLE) 170 if (m_state == Sensor::SensorState::IDLE)
170 return; 171 return;
171 172
172 if (!result) 173 if (!result)
173 reportError(); 174 reportError();
174 175
175 DCHECK(m_sensorProxy); 176 DCHECK(m_sensorProxy);
176 m_sensorProxy->removeObserver(this); 177 m_sensorProxy->removeObserver(this);
177 } 178 }
178 179
179 void Sensor::pageVisibilityChanged() 180 void Sensor::pageVisibilityChanged()
180 { 181 {
181 updatePollingStatus(); 182 updatePollingStatus();
183
184 if (!m_sensorProxy || !m_sensorProxy->isInitialized())
185 return;
186
187 if (page()->visibilityState() != PageVisibilityStateVisible) {
188 m_sensorProxy->suspend();
189 } else {
190 m_sensorProxy->resume();
191 }
182 } 192 }
183 193
184 void Sensor::startListening() 194 void Sensor::startListening()
185 { 195 {
186 DCHECK(m_sensorProxy); 196 DCHECK(m_sensorProxy);
187 updateState(Sensor::SensorState::ACTIVATING); 197 updateState(Sensor::SensorState::ACTIVATING);
188 if (!m_sensorReading) 198 if (!m_sensorReading)
189 m_sensorReading = createSensorReading(m_sensorProxy); 199 m_sensorReading = createSensorReading(m_sensorProxy);
190 200
191 m_sensorProxy->addObserver(this); 201 m_sensorProxy->addObserver(this);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 264
255 if (m_state != Sensor::SensorState::ACTIVE 265 if (m_state != Sensor::SensorState::ACTIVE
256 || page()->visibilityState() != PageVisibilityStateVisible) { 266 || page()->visibilityState() != PageVisibilityStateVisible) {
257 m_polling->stopPolling(); 267 m_polling->stopPolling();
258 } else { 268 } else {
259 m_polling->startPolling(); 269 m_polling->startPolling();
260 } 270 }
261 } 271 }
262 272
263 } // namespace blink 273 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/sensor/SensorPollingStrategy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698