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

Side by Side 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, 4 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "modules/device_orientation/DeviceSensorEventDispatcher.h" 32 #include "modules/device_orientation/DeviceSensorEventDispatcher.h"
33 33
34 namespace WebCore { 34 namespace WebCore {
35 35
36 DeviceSensorEventDispatcher::DeviceSensorEventDispatcher() 36 DeviceSensorEventDispatcher::DeviceSensorEventDispatcher()
37 : m_needsPurge(false)
38 , m_isDispatching(false)
37 { 39 {
38 } 40 }
39 41
40 DeviceSensorEventDispatcher::~DeviceSensorEventDispatcher() 42 DeviceSensorEventDispatcher::~DeviceSensorEventDispatcher()
41 { 43 {
42 } 44 }
43 45
44 void DeviceSensorEventDispatcher::addController(DeviceSensorEventController* con troller) 46 void DeviceSensorEventDispatcher::addController(DeviceSensorEventController* con troller)
45 { 47 {
46 bool wasEmpty = m_controllers.isEmpty(); 48 bool wasEmpty = m_controllers.isEmpty();
47 if (!m_controllers.contains(controller)) 49 if (!m_controllers.contains(controller))
48 m_controllers.append(controller); 50 m_controllers.append(controller);
49 if (wasEmpty) 51 if (wasEmpty)
50 startListening(); 52 startListening();
51 } 53 }
52 54
53 void DeviceSensorEventDispatcher::removeController(DeviceSensorEventController* controller) 55 void DeviceSensorEventDispatcher::removeController(DeviceSensorEventController* controller)
54 { 56 {
55 // Do not actually remove controller from the vector, instead zero them out. 57 // Do not actually remove the controller from the vector, instead zero them out.
56 // The zeros are removed after didChangeDeviceMotion has dispatched all even ts. 58 // The zeros are removed in these two cases:
57 // This is to prevent re-entrancy case when a controller is destroyed while in the 59 // 1. either immediately if we are not dispatching any events,
58 // didChangeDeviceMotion method. 60 // 2. or after didChangeDeviceMotion/Orientation has dispatched all events.
61 // This is to correctly handle the re-entrancy case when a controller is des troyed
62 // while in the didChangeDeviceMotion/Orientation method.
59 size_t index = m_controllers.find(controller); 63 size_t index = m_controllers.find(controller);
60 if (index != notFound) 64 if (index == notFound)
61 m_controllers[index] = 0; 65 return;
66
67 m_controllers[index] = 0;
68 m_needsPurge = true;
69
70 if (!m_isDispatching)
71 purgeControllers();
62 } 72 }
63 73
64 void DeviceSensorEventDispatcher::purgeControllers() 74 void DeviceSensorEventDispatcher::purgeControllers()
65 { 75 {
66 size_t i = 0; 76 size_t i = 0;
67 while (i < m_controllers.size()) { 77 while (i < m_controllers.size()) {
68 if (!m_controllers[i]) { 78 if (!m_controllers[i]) {
69 m_controllers[i] = m_controllers.last(); 79 m_controllers[i] = m_controllers.last();
70 m_controllers.removeLast(); 80 m_controllers.removeLast();
71 } else { 81 } else {
72 ++i; 82 ++i;
73 } 83 }
74 } 84 }
75 85
86 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.
87
76 if (m_controllers.isEmpty()) 88 if (m_controllers.isEmpty())
77 stopListening(); 89 stopListening();
78 } 90 }
79 91
80 } // namespace WebCore 92 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698