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

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

Issue 2698153003: Reduce createSameThreadTask usage in modules/ (Closed)
Patch Set: Move a static callback to an anonymous namespace Created 3 years, 10 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 "core/dom/ExecutionContextTask.h"
10 #include "core/dom/TaskRunnerHelper.h" 9 #include "core/dom/TaskRunnerHelper.h"
11 #include "core/inspector/ConsoleMessage.h" 10 #include "core/inspector/ConsoleMessage.h"
12 #include "core/timing/DOMWindowPerformance.h" 11 #include "core/timing/DOMWindowPerformance.h"
13 #include "core/timing/Performance.h" 12 #include "core/timing/Performance.h"
14 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" 13 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
15 #include "modules/sensor/SensorErrorEvent.h" 14 #include "modules/sensor/SensorErrorEvent.h"
16 #include "modules/sensor/SensorProviderProxy.h" 15 #include "modules/sensor/SensorProviderProxy.h"
17 16
18 using namespace device::mojom::blink; 17 using namespace device::mojom::blink;
19 18
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 void Sensor::updateState(Sensor::SensorState newState) { 271 void Sensor::updateState(Sensor::SensorState newState) {
273 if (newState == m_state) 272 if (newState == m_state)
274 return; 273 return;
275 274
276 if (newState == SensorState::Activated && getExecutionContext()) { 275 if (newState == SensorState::Activated && getExecutionContext()) {
277 DCHECK_EQ(SensorState::Activating, m_state); 276 DCHECK_EQ(SensorState::Activating, m_state);
278 // The initial value for m_lastUpdateTimestamp is set to current time, 277 // The initial value for m_lastUpdateTimestamp is set to current time,
279 // so that the first reading update will be notified considering the given 278 // so that the first reading update will be notified considering the given
280 // frequency hint. 279 // frequency hint.
281 m_lastUpdateTimestamp = WTF::monotonicallyIncreasingTime(); 280 m_lastUpdateTimestamp = WTF::monotonicallyIncreasingTime();
282 getExecutionContext()->postTask( 281 TaskRunnerHelper::get(TaskType::Sensor, getExecutionContext())
283 TaskType::Sensor, BLINK_FROM_HERE, 282 ->postTask(BLINK_FROM_HERE, WTF::bind(&Sensor::notifyOnActivate,
284 createSameThreadTask(&Sensor::notifyOnActivate, 283 wrapWeakPersistent(this)));
285 wrapWeakPersistent(this)));
286 } 284 }
287 285
288 m_state = newState; 286 m_state = newState;
289 } 287 }
290 288
291 void Sensor::reportError(ExceptionCode code, 289 void Sensor::reportError(ExceptionCode code,
292 const String& sanitizedMessage, 290 const String& sanitizedMessage,
293 const String& unsanitizedMessage) { 291 const String& unsanitizedMessage) {
294 updateState(Sensor::SensorState::Errored); 292 updateState(Sensor::SensorState::Errored);
295 if (getExecutionContext()) { 293 if (getExecutionContext()) {
296 auto error = 294 auto error =
297 DOMException::create(code, sanitizedMessage, unsanitizedMessage); 295 DOMException::create(code, sanitizedMessage, unsanitizedMessage);
298 getExecutionContext()->postTask( 296 TaskRunnerHelper::get(TaskType::Sensor, getExecutionContext())
299 TaskType::Sensor, BLINK_FROM_HERE, 297 ->postTask(BLINK_FROM_HERE,
300 createSameThreadTask(&Sensor::notifyError, wrapWeakPersistent(this), 298 WTF::bind(&Sensor::notifyError, wrapWeakPersistent(this),
301 wrapPersistent(error))); 299 wrapPersistent(error)));
302 } 300 }
303 } 301 }
304 302
305 void Sensor::notifySensorReadingChanged() { 303 void Sensor::notifySensorReadingChanged() {
306 DCHECK(m_sensorProxy); 304 DCHECK(m_sensorProxy);
307 305
308 if (m_sensorProxy->reading().timestamp != m_storedData.timestamp) { 306 if (m_sensorProxy->reading().timestamp != m_storedData.timestamp) {
309 m_storedData = m_sensorProxy->reading(); 307 m_storedData = m_sensorProxy->reading();
310 dispatchEvent(Event::create(EventTypeNames::change)); 308 dispatchEvent(Event::create(EventTypeNames::change));
(...skipping 10 matching lines...) Expand all
321 } 319 }
322 320
323 bool Sensor::canReturnReadings() const { 321 bool Sensor::canReturnReadings() const {
324 if (m_state != Sensor::SensorState::Activated) 322 if (m_state != Sensor::SensorState::Activated)
325 return false; 323 return false;
326 DCHECK(m_sensorProxy); 324 DCHECK(m_sensorProxy);
327 return m_sensorProxy->reading().timestamp != 0.0; 325 return m_sensorProxy->reading().timestamp != 0.0;
328 } 326 }
329 327
330 } // namespace blink 328 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698