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

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

Issue 2587733002: Specify TaskType of posted Task explicitly in Sensor API (11) (Closed)
Patch Set: Created 4 years 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 | « third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp ('k') | no next file » | 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 "core/dom/ExecutionContextTask.h" 9 #include "core/dom/ExecutionContextTask.h"
10 #include "core/dom/TaskRunnerHelper.h"
10 #include "core/inspector/ConsoleMessage.h" 11 #include "core/inspector/ConsoleMessage.h"
11 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" 12 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
12 #include "modules/sensor/SensorErrorEvent.h" 13 #include "modules/sensor/SensorErrorEvent.h"
13 #include "modules/sensor/SensorProviderProxy.h" 14 #include "modules/sensor/SensorProviderProxy.h"
14 #include "modules/sensor/SensorReading.h" 15 #include "modules/sensor/SensorReading.h"
15 #include "modules/sensor/SensorUpdateNotificationStrategy.h" 16 #include "modules/sensor/SensorUpdateNotificationStrategy.h"
16 17
17 using namespace device::mojom::blink; 18 using namespace device::mojom::blink;
18 19
19 namespace blink { 20 namespace blink {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 if (m_state != Sensor::SensorState::Activated) 260 if (m_state != Sensor::SensorState::Activated)
260 return; 261 return;
261 262
262 DCHECK(m_sensorProxy); 263 DCHECK(m_sensorProxy);
263 DCHECK(m_sensorProxy->isInitialized()); 264 DCHECK(m_sensorProxy->isInitialized());
264 DCHECK(m_sensorProxy->sensorReading()); 265 DCHECK(m_sensorProxy->sensorReading());
265 266
266 if (getExecutionContext() && 267 if (getExecutionContext() &&
267 m_sensorProxy->sensorReading()->isReadingUpdated(m_storedData)) { 268 m_sensorProxy->sensorReading()->isReadingUpdated(m_storedData)) {
268 getExecutionContext()->postTask( 269 getExecutionContext()->postTask(
269 BLINK_FROM_HERE, 270 TaskType::Sensor, BLINK_FROM_HERE,
270 createSameThreadTask(&Sensor::notifySensorReadingChanged, 271 createSameThreadTask(&Sensor::notifySensorReadingChanged,
271 wrapWeakPersistent(this))); 272 wrapWeakPersistent(this)));
272 } 273 }
273 274
274 m_storedData = m_sensorProxy->sensorReading()->data(); 275 m_storedData = m_sensorProxy->sensorReading()->data();
275 } 276 }
276 277
277 void Sensor::updateState(Sensor::SensorState newState) { 278 void Sensor::updateState(Sensor::SensorState newState) {
278 if (newState == m_state) 279 if (newState == m_state)
279 return; 280 return;
280 281
281 if (newState == SensorState::Activated && getExecutionContext()) { 282 if (newState == SensorState::Activated && getExecutionContext()) {
282 DCHECK_EQ(SensorState::Activating, m_state); 283 DCHECK_EQ(SensorState::Activating, m_state);
283 getExecutionContext()->postTask( 284 getExecutionContext()->postTask(
284 BLINK_FROM_HERE, createSameThreadTask(&Sensor::notifyOnActivate, 285 TaskType::Sensor, BLINK_FROM_HERE,
285 wrapWeakPersistent(this))); 286 createSameThreadTask(&Sensor::notifyOnActivate,
287 wrapWeakPersistent(this)));
286 } 288 }
287 289
288 m_state = newState; 290 m_state = newState;
289 } 291 }
290 292
291 void Sensor::reportError(ExceptionCode code, 293 void Sensor::reportError(ExceptionCode code,
292 const String& sanitizedMessage, 294 const String& sanitizedMessage,
293 const String& unsanitizedMessage) { 295 const String& unsanitizedMessage) {
294 updateState(Sensor::SensorState::Errored); 296 updateState(Sensor::SensorState::Errored);
295 if (getExecutionContext()) { 297 if (getExecutionContext()) {
296 auto error = 298 auto error =
297 DOMException::create(code, sanitizedMessage, unsanitizedMessage); 299 DOMException::create(code, sanitizedMessage, unsanitizedMessage);
298 getExecutionContext()->postTask( 300 getExecutionContext()->postTask(
299 BLINK_FROM_HERE, 301 TaskType::Sensor, BLINK_FROM_HERE,
300 createSameThreadTask(&Sensor::notifyError, wrapWeakPersistent(this), 302 createSameThreadTask(&Sensor::notifyError, wrapWeakPersistent(this),
301 wrapPersistent(error))); 303 wrapPersistent(error)));
302 } 304 }
303 } 305 }
304 306
305 void Sensor::onSuspended() { 307 void Sensor::onSuspended() {
306 if (m_sensorUpdateNotifier) 308 if (m_sensorUpdateNotifier)
307 m_sensorUpdateNotifier->cancelPendingNotifications(); 309 m_sensorUpdateNotifier->cancelPendingNotifications();
308 } 310 }
309 311
310 void Sensor::notifySensorReadingChanged() { 312 void Sensor::notifySensorReadingChanged() {
311 dispatchEvent(Event::create(EventTypeNames::change)); 313 dispatchEvent(Event::create(EventTypeNames::change));
312 } 314 }
313 315
314 void Sensor::notifyOnActivate() { 316 void Sensor::notifyOnActivate() {
315 dispatchEvent(Event::create(EventTypeNames::activate)); 317 dispatchEvent(Event::create(EventTypeNames::activate));
316 } 318 }
317 319
318 void Sensor::notifyError(DOMException* error) { 320 void Sensor::notifyError(DOMException* error) {
319 dispatchEvent( 321 dispatchEvent(
320 SensorErrorEvent::create(EventTypeNames::error, std::move(error))); 322 SensorErrorEvent::create(EventTypeNames::error, std::move(error)));
321 } 323 }
322 324
323 } // namespace blink 325 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698