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

Unified Diff: third_party/WebKit/Source/core/dom/ContextLifecycleNotifier.cpp

Issue 2094143002: Avoid snapshotting ContextLifecycleObservers when iterating. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove IterationScope, indirection not needed Created 4 years, 6 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/frame/DOMWindowLifecycleNotifier.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/ContextLifecycleNotifier.cpp
diff --git a/third_party/WebKit/Source/core/dom/ContextLifecycleNotifier.cpp b/third_party/WebKit/Source/core/dom/ContextLifecycleNotifier.cpp
index 38a035cfbf25fb11f831e8ec9c8c943291b1ab74..c089d6e5c7660d86601356cab18abd0e3a062843 100644
--- a/third_party/WebKit/Source/core/dom/ContextLifecycleNotifier.cpp
+++ b/third_party/WebKit/Source/core/dom/ContextLifecycleNotifier.cpp
@@ -34,68 +34,47 @@ namespace blink {
void ContextLifecycleNotifier::notifyResumingActiveDOMObjects()
{
- TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll);
- Vector<UntracedMember<ContextLifecycleObserver>> snapshotOfObservers;
- copyToVector(m_observers, snapshotOfObservers);
- for (ContextLifecycleObserver* observer : snapshotOfObservers) {
- // FIXME: Oilpan: At the moment, it's possible that a ActiveDOMObject
- // observer is destructed while iterating. Once we enable Oilpan by default
- // for all LifecycleObserver<T>s, we can remove the hack by making m_observers
- // a HeapHashSet<WeakMember<LifecycleObserver<T>>>.
- // (i.e., we can just iterate m_observers without taking a snapshot).
- // For more details, see https://codereview.chromium.org/247253002/.
- if (m_observers.contains(observer)) {
- if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjectType)
- continue;
- ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observer);
+ TemporaryChange<IterationState> scope(m_iterationState, AllowingNone);
+ for (ContextLifecycleObserver* observer : m_observers) {
+ if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjectType)
+ continue;
+ ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observer);
#if DCHECK_IS_ON()
- DCHECK_EQ(activeDOMObject->getExecutionContext(), context());
- DCHECK(activeDOMObject->suspendIfNeededCalled());
+ DCHECK_EQ(activeDOMObject->getExecutionContext(), context());
+ DCHECK(activeDOMObject->suspendIfNeededCalled());
#endif
- activeDOMObject->resume();
- }
+ activeDOMObject->resume();
}
}
void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects()
{
- TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll);
- Vector<UntracedMember<ContextLifecycleObserver>> snapshotOfObservers;
- copyToVector(m_observers, snapshotOfObservers);
- for (ContextLifecycleObserver* observer : snapshotOfObservers) {
- // It's possible that the ActiveDOMObject is already destructed.
- // See a FIXME above.
- if (m_observers.contains(observer)) {
- if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjectType)
- continue;
- ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observer);
+ TemporaryChange<IterationState> scope(m_iterationState, AllowingNone);
+ for (ContextLifecycleObserver* observer : m_observers) {
+ if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjectType)
+ continue;
+ ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observer);
#if DCHECK_IS_ON()
- DCHECK_EQ(activeDOMObject->getExecutionContext(), context());
- DCHECK(activeDOMObject->suspendIfNeededCalled());
+ DCHECK_EQ(activeDOMObject->getExecutionContext(), context());
+ DCHECK(activeDOMObject->suspendIfNeededCalled());
#endif
- activeDOMObject->suspend();
- }
+ activeDOMObject->suspend();
}
}
void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects()
{
- TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll);
- Vector<UntracedMember<ContextLifecycleObserver>> snapshotOfObservers;
- copyToVector(m_observers, snapshotOfObservers);
- for (ContextLifecycleObserver* observer : snapshotOfObservers) {
- // It's possible that the ActiveDOMObject is already destructed.
- // See a FIXME above.
- if (m_observers.contains(observer)) {
- if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjectType)
- continue;
- ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observer);
+ // Neither additions nor removals are allowed while iterating.
+ TemporaryChange<IterationState> scope(m_iterationState, AllowingNone);
+ for (ContextLifecycleObserver* observer : m_observers) {
+ if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjectType)
+ continue;
+ ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observer);
#if DCHECK_IS_ON()
- DCHECK_EQ(activeDOMObject->getExecutionContext(), context());
- DCHECK(activeDOMObject->suspendIfNeededCalled());
+ DCHECK_EQ(activeDOMObject->getExecutionContext(), context());
+ DCHECK(activeDOMObject->suspendIfNeededCalled());
#endif
- activeDOMObject->stop();
- }
+ activeDOMObject->stop();
}
}
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/frame/DOMWindowLifecycleNotifier.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698