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

Unified Diff: Source/modules/device_orientation/DeviceMotionDispatcher.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/DeviceMotionDispatcher.cpp
diff --git a/Source/modules/device_orientation/DeviceMotionDispatcher.cpp b/Source/modules/device_orientation/DeviceMotionDispatcher.cpp
index 93008e5ea33749e4a15f150af214e0fd173ed78f..79faf3dde0e5b39b93ea26afbf5028e174813adf 100644
--- a/Source/modules/device_orientation/DeviceMotionDispatcher.cpp
+++ b/Source/modules/device_orientation/DeviceMotionDispatcher.cpp
@@ -29,11 +29,12 @@
*/
#include "config.h"
-#include "DeviceMotionDispatcher.h"
+#include "modules/device_orientation/DeviceMotionDispatcher.h"
#include "modules/device_orientation/DeviceMotionController.h"
#include "modules/device_orientation/DeviceMotionData.h"
#include "public/platform/Platform.h"
+#include "wtf/TemporaryChange.h"
namespace WebCore {
@@ -69,20 +70,24 @@ void DeviceMotionDispatcher::startListening()
void DeviceMotionDispatcher::stopListening()
{
WebKit::Platform::current()->setDeviceMotionListener(0);
+ m_lastDeviceMotionData.clear();
}
void DeviceMotionDispatcher::didChangeDeviceMotion(const WebKit::WebDeviceMotionData& motion)
{
m_lastDeviceMotionData = DeviceMotionData::create(motion);
- bool needsPurge = false;
- for (size_t i = 0; i < m_controllers.size(); ++i) {
- if (m_controllers[i])
- static_cast<DeviceMotionController*>(m_controllers[i])->didChangeDeviceMotion(m_lastDeviceMotionData.get());
- else
- needsPurge = true;
+
+ {
+ TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
+ // Don't fire controllers removed or added during event dispatch.
+ size_t size = m_controllers.size();
+ for (size_t i = 0; i < size; ++i) {
+ if (m_controllers[i])
+ static_cast<DeviceMotionController*>(m_controllers[i])->didChangeDeviceMotion(m_lastDeviceMotionData.get());
+ }
}
- if (needsPurge)
+ if (m_needsPurge)
purgeControllers();
}
« no previous file with comments | « Source/modules/device_orientation/DeviceMotionDispatcher.h ('k') | Source/modules/device_orientation/DeviceOrientationData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698