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

Unified Diff: Source/modules/device_orientation/DeviceSensorEventDispatcher.cpp

Issue 21256002: Fire null Device Motion events only once. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed comments Created 7 years, 5 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
Index: Source/modules/device_orientation/DeviceSensorEventDispatcher.cpp
diff --git a/Source/modules/device_orientation/DeviceSensorEventDispatcher.cpp b/Source/modules/device_orientation/DeviceSensorEventDispatcher.cpp
index 2e3fb332ea623b019443b53710ddbeaa938f52d6..e48d4a3eed516f5ea0bb2a2bcbc034ec1513580b 100644
--- a/Source/modules/device_orientation/DeviceSensorEventDispatcher.cpp
+++ b/Source/modules/device_orientation/DeviceSensorEventDispatcher.cpp
@@ -34,6 +34,8 @@
namespace WebCore {
DeviceSensorEventDispatcher::DeviceSensorEventDispatcher()
+ : m_needsPurge(false)
+ , m_isDispatching(false)
{
}
@@ -52,17 +54,27 @@ void DeviceSensorEventDispatcher::addController(DeviceSensorEventController* con
void DeviceSensorEventDispatcher::removeController(DeviceSensorEventController* controller)
{
- // Do not actually remove controller from the vector, instead zero them out.
- // The zeros are removed after didChangeDeviceMotion has dispatched all events.
- // This is to prevent re-entrancy case when a controller is destroyed while in the
- // didChangeDeviceMotion method.
+ // Do not actually remove the controller from the vector, instead zero them out.
+ // The zeros are removed in these two cases:
+ // 1. either immediately if we are not dispatching any events,
+ // 2. or after didChangeDeviceMotion/Orientation has dispatched all events.
+ // This is to correctly handle the re-entrancy case when a controller is destroyed
+ // while in the didChangeDeviceMotion/Orientation method.
size_t index = m_controllers.find(controller);
- if (index != notFound)
- m_controllers[index] = 0;
+ if (index == notFound)
+ return;
+
+ m_controllers[index] = 0;
+ m_needsPurge = true;
+
+ if (!m_isDispatching)
+ purgeControllers();
}
void DeviceSensorEventDispatcher::purgeControllers()
{
+ ASSERT(m_needsPurge);
+
size_t i = 0;
while (i < m_controllers.size()) {
if (!m_controllers[i]) {
@@ -73,6 +85,8 @@ void DeviceSensorEventDispatcher::purgeControllers()
}
}
+ m_needsPurge = false;
+
if (m_controllers.isEmpty())
stopListening();
}

Powered by Google App Engine
This is Rietveld 408576698