Chromium Code Reviews| 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(); |
| } |