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

Side by Side Diff: Source/core/dom/ContextLifecycleNotifier.cpp

Issue 247253002: Allow ActiveDOMObjects to be destructed while iterating the list of ActiveDOMObjects (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 m_activeDOMObjects.add(static_cast<ActiveDOMObject*>(observer)); 52 m_activeDOMObjects.add(static_cast<ActiveDOMObject*>(observer));
53 } 53 }
54 } 54 }
55 55
56 void ContextLifecycleNotifier::removeObserver(ContextLifecycleNotifier::Observer * observer) 56 void ContextLifecycleNotifier::removeObserver(ContextLifecycleNotifier::Observer * observer)
57 { 57 {
58 LifecycleNotifier<ExecutionContext>::removeObserver(observer); 58 LifecycleNotifier<ExecutionContext>::removeObserver(observer);
59 59
60 RELEASE_ASSERT(m_iterating != IteratingOverContextObservers); 60 RELEASE_ASSERT(m_iterating != IteratingOverContextObservers);
61 if (observer->observerType() == Observer::ActiveDOMObjectType) { 61 if (observer->observerType() == Observer::ActiveDOMObjectType) {
62 RELEASE_ASSERT(m_iterating != IteratingOverActiveDOMObjects);
63 m_activeDOMObjects.remove(static_cast<ActiveDOMObject*>(observer)); 62 m_activeDOMObjects.remove(static_cast<ActiveDOMObject*>(observer));
64 } 63 }
65 } 64 }
66 65
67 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() 66 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects()
68 { 67 {
69 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD OMObjects); 68 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD OMObjects);
70 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); 69 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects;
71 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) { 70 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects);
72 ASSERT((*iter)->executionContext() == context()); 71 for (Vector<ActiveDOMObject*>::iterator iter = snapshotOfActiveDOMObjects.be gin(); iter != snapshotOfActiveDOMObjects.end(); iter++) {
73 ASSERT((*iter)->suspendIfNeededCalled()); 72 // FIXME: Oilpan: At the moment, it's possible that the ActiveDOMObject is destructed
74 (*iter)->resume(); 73 // during the iteration. Once we move ActiveDOMObject to the heap and
74 // make m_activeDOMObjects a HeapHashSet<WeakMember<ActiveDOMObject>>,
75 // it's no longer possible that ActiveDOMObject is destructed during the iteration,
76 // so we can remove the hack (i.e., we can just iterate m_activeDOMObjec ts without
77 // taking a snapshot). For more details, see https://codereview.chromium .org/247253002/.
78 if (m_activeDOMObjects.contains(*iter)) {
79 ASSERT((*iter)->executionContext() == context());
80 ASSERT((*iter)->suspendIfNeededCalled());
81 (*iter)->resume();
82 }
75 } 83 }
76 } 84 }
77 85
78 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() 86 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects()
79 { 87 {
80 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD OMObjects); 88 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD OMObjects);
81 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); 89 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects;
82 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) { 90 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects);
83 ASSERT((*iter)->executionContext() == context()); 91 for (Vector<ActiveDOMObject*>::iterator iter = snapshotOfActiveDOMObjects.be gin(); iter != snapshotOfActiveDOMObjects.end(); iter++) {
84 ASSERT((*iter)->suspendIfNeededCalled()); 92 // It's possible that the ActiveDOMObject is already destructed.
85 (*iter)->suspend(); 93 // See a FIXME above.
94 if (m_activeDOMObjects.contains(*iter)) {
95 ASSERT((*iter)->executionContext() == context());
96 ASSERT((*iter)->suspendIfNeededCalled());
97 (*iter)->suspend();
98 }
86 } 99 }
87 } 100 }
88 101
89 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() 102 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects()
90 { 103 {
91 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD OMObjects); 104 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD OMObjects);
92 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); 105 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects;
93 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) { 106 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects);
94 ASSERT((*iter)->executionContext() == context()); 107 for (Vector<ActiveDOMObject*>::iterator iter = snapshotOfActiveDOMObjects.be gin(); iter != snapshotOfActiveDOMObjects.end(); iter++) {
95 ASSERT((*iter)->suspendIfNeededCalled()); 108 // It's possible that the ActiveDOMObject is already destructed.
96 (*iter)->stop(); 109 // See a FIXME above.
110 if (m_activeDOMObjects.contains(*iter)) {
111 ASSERT((*iter)->executionContext() == context());
112 ASSERT((*iter)->suspendIfNeededCalled());
113 (*iter)->stop();
114 }
97 } 115 }
abarth-chromium 2014/05/09 13:54:39 I'm worried that ActiveDOMObjects created during t
haraken 2014/05/09 14:05:15 Creation during iteration is already forbidden by
98 } 116 }
99 117
100 bool ContextLifecycleNotifier::hasPendingActivity() const 118 bool ContextLifecycleNotifier::hasPendingActivity() const
101 { 119 {
102 ActiveDOMObjectSet::const_iterator activeObjectsEnd = activeDOMObjects().end (); 120 for (ActiveDOMObjectSet::const_iterator iter = m_activeDOMObjects.begin(); i ter != m_activeDOMObjects.end(); ++iter) {
103 for (ActiveDOMObjectSet::const_iterator iter = activeDOMObjects().begin(); i ter != activeObjectsEnd; ++iter) {
104 if ((*iter)->hasPendingActivity()) 121 if ((*iter)->hasPendingActivity())
105 return true; 122 return true;
106 } 123 }
107
108 return false; 124 return false;
109 } 125 }
110 126
111 } // namespace WebCore 127 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698