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

Unified Diff: third_party/WebKit/Source/modules/sensor/Sensor.cpp

Issue 2381913002: [sensors] Dispatch sensor events using postTask (Closed)
Patch Set: Rebased. Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/Sensor.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/sensor/Sensor.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/Sensor.cpp b/third_party/WebKit/Source/modules/sensor/Sensor.cpp
index 0ccfb6fe73e8c97fd04f3cb7beedccd0014c5b0a..a87b8be19f01c7b23dd3bab04323acdaa27be36c 100644
--- a/third_party/WebKit/Source/modules/sensor/Sensor.cpp
+++ b/third_party/WebKit/Source/modules/sensor/Sensor.cpp
@@ -6,6 +6,7 @@
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
+#include "core/dom/ExecutionContextTask.h"
#include "core/inspector/ConsoleMessage.h"
#include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
#include "modules/sensor/SensorErrorEvent.h"
@@ -268,9 +269,13 @@ void Sensor::pollForData() {
m_sensorProxy->updateInternalReading();
DCHECK(m_sensorReading);
- if (m_sensorReading->isReadingUpdated(m_storedData))
- dispatchEvent(
- SensorReadingEvent::create(EventTypeNames::change, m_sensorReading));
+ if (getExecutionContext() &&
+ m_sensorReading->isReadingUpdated(m_storedData)) {
+ getExecutionContext()->postTask(
+ BLINK_FROM_HERE,
+ createSameThreadTask(&Sensor::notifySensorReadingChanged,
+ wrapWeakPersistent(this)));
+ }
m_storedData = m_sensorProxy->reading();
}
@@ -279,7 +284,12 @@ void Sensor::updateState(Sensor::SensorState newState) {
if (newState == m_state)
return;
m_state = newState;
- dispatchEvent(Event::create(EventTypeNames::statechange));
+ if (getExecutionContext()) {
+ getExecutionContext()->postTask(
+ BLINK_FROM_HERE, createSameThreadTask(&Sensor::notifyStateChanged,
+ wrapWeakPersistent(this)));
+ }
+
updatePollingStatus();
}
@@ -300,4 +310,13 @@ void Sensor::updatePollingStatus() {
}
}
+void Sensor::notifySensorReadingChanged() {
+ dispatchEvent(
+ SensorReadingEvent::create(EventTypeNames::change, m_sensorReading));
+}
+
+void Sensor::notifyStateChanged() {
+ dispatchEvent(Event::create(EventTypeNames::statechange));
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/Sensor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698