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

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: 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..e63a1d38a321f5f07f0194505cf0ecdf5a9bdaad 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,13 +54,21 @@ 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()
@@ -73,6 +83,8 @@ void DeviceSensorEventDispatcher::purgeControllers()
}
}
+ m_needsPurge = false;
abarth-chromium 2013/07/31 00:56:19 Should we ASSERT(m_needsPurge) at the top of this
timvolodine 2013/07/31 13:59:00 Done.
+
if (m_controllers.isEmpty())
stopListening();
}

Powered by Google App Engine
This is Rietveld 408576698