OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2013 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2013 Google Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 #if DCHECK_IS_ON() | 57 #if DCHECK_IS_ON() |
58 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); | 58 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); |
59 DCHECK(activeDOMObject->suspendIfNeededCalled()); | 59 DCHECK(activeDOMObject->suspendIfNeededCalled()); |
60 #endif | 60 #endif |
61 activeDOMObject->suspend(); | 61 activeDOMObject->suspend(); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() | 65 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() |
66 { | 66 { |
67 // Neither additions nor removals are allowed while iterating. | 67 // Observers may be removed, but handled after iteration has completed. |
68 TemporaryChange<IterationState> scope(m_iterationState, AllowingNone); | 68 TemporaryChange<IterationState> scope(m_iterationState, AllowPendingRemoval)
; |
69 for (ContextLifecycleObserver* observer : m_observers) { | 69 ObserverSet observers; |
| 70 m_observers.swap(observers); |
| 71 for (ContextLifecycleObserver* observer : observers) { |
70 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) | 72 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) |
71 continue; | 73 continue; |
72 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); | 74 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); |
73 #if DCHECK_IS_ON() | 75 #if DCHECK_IS_ON() |
74 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); | 76 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); |
75 DCHECK(activeDOMObject->suspendIfNeededCalled()); | 77 DCHECK(activeDOMObject->suspendIfNeededCalled()); |
76 #endif | 78 #endif |
77 activeDOMObject->stop(); | 79 activeDOMObject->stop(); |
78 } | 80 } |
| 81 removePending(observers); |
79 } | 82 } |
80 | 83 |
81 unsigned ContextLifecycleNotifier::activeDOMObjectCount() const | 84 unsigned ContextLifecycleNotifier::activeDOMObjectCount() const |
82 { | 85 { |
| 86 DCHECK(!isIteratingOverObservers()); |
83 unsigned activeDOMObjects = 0; | 87 unsigned activeDOMObjects = 0; |
84 for (ContextLifecycleObserver* observer : m_observers) { | 88 for (ContextLifecycleObserver* observer : m_observers) { |
85 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) | 89 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) |
86 continue; | 90 continue; |
87 activeDOMObjects++; | 91 activeDOMObjects++; |
88 } | 92 } |
89 return activeDOMObjects; | 93 return activeDOMObjects; |
90 } | 94 } |
91 | 95 |
92 #if DCHECK_IS_ON() | 96 #if DCHECK_IS_ON() |
93 bool ContextLifecycleNotifier::contains(ActiveDOMObject* object) const | 97 bool ContextLifecycleNotifier::contains(ActiveDOMObject* object) const |
94 { | 98 { |
| 99 DCHECK(!isIteratingOverObservers()); |
95 for (ContextLifecycleObserver* observer : m_observers) { | 100 for (ContextLifecycleObserver* observer : m_observers) { |
96 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) | 101 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) |
97 continue; | 102 continue; |
98 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); | 103 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); |
99 if (activeDOMObject == object) | 104 if (activeDOMObject == object) |
100 return true; | 105 return true; |
101 } | 106 } |
102 return false; | 107 return false; |
103 } | 108 } |
104 #endif | 109 #endif |
105 | 110 |
106 } // namespace blink | 111 } // namespace blink |
OLD | NEW |