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

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

Issue 2381913002: [sensors] Dispatch sensor events using postTask (Closed)
Patch Set: 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 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 d5f1b0421b799ab73d20664171a2d3c7b609c7ee..e0f7f31f1146d45f0ef669607a5376bb909452c4 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"
@@ -263,8 +264,10 @@ 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)));
haraken 2016/09/30 13:26:45 wrapWeakPersistent means that the event may not be
shalamov 2016/09/30 13:51:44 Yes, that was intentional. If sensor goes out of s
+ }
m_storedData = m_sensorProxy->reading();
}
@@ -274,7 +277,11 @@ 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();
}
@@ -297,4 +304,14 @@ 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