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

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 in a case where resume() allocates an on-heap ob ject
Mads Ager (chromium) 2014/05/09 08:05:44 NIT: I think you should leave out the part of the
haraken 2014/05/09 08:12:36 Yeah, your observation is correct. An allocation w
74 // and it triggers a GC. Once we move ActiveDOMObject to the heap and
75 // make m_activeDOMObjects a HeapHashSet<WeakMember<ActiveDOMObject>>,
76 // it's no longer possible that ActiveDOMObject is destructed during the iteration,
77 // so we can remove the hack (i.e., we can just iterate m_activeDOMObjec ts without
78 // taking a snapshot). For more details, see https://codereview.chromium .org/247253002/.
79 if (m_activeDOMObjects.contains(*iter)) {
80 ASSERT((*iter)->executionContext() == context());
81 ASSERT((*iter)->suspendIfNeededCalled());
82 (*iter)->resume();
83 }
75 } 84 }
76 } 85 }
77 86
78 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() 87 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects()
79 { 88 {
80 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD OMObjects); 89 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD OMObjects);
81 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); 90 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects;
82 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) { 91 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects);
83 ASSERT((*iter)->executionContext() == context()); 92 for (Vector<ActiveDOMObject*>::iterator iter = snapshotOfActiveDOMObjects.be gin(); iter != snapshotOfActiveDOMObjects.end(); iter++) {
84 ASSERT((*iter)->suspendIfNeededCalled()); 93 // It's possible that the ActiveDOMObject is already destructed.
85 (*iter)->suspend(); 94 // See a FIXME above.
95 if (m_activeDOMObjects.contains(*iter)) {
96 ASSERT((*iter)->executionContext() == context());
97 ASSERT((*iter)->suspendIfNeededCalled());
98 (*iter)->suspend();
99 }
86 } 100 }
87 } 101 }
88 102
89 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() 103 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects()
90 { 104 {
91 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD OMObjects); 105 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverActiveD OMObjects);
92 ActiveDOMObjectSet::iterator activeObjectsEnd = m_activeDOMObjects.end(); 106 Vector<ActiveDOMObject*> snapshotOfActiveDOMObjects;
93 for (ActiveDOMObjectSet::iterator iter = m_activeDOMObjects.begin(); iter != activeObjectsEnd; ++iter) { 107 copyToVector(m_activeDOMObjects, snapshotOfActiveDOMObjects);
94 ASSERT((*iter)->executionContext() == context()); 108 for (Vector<ActiveDOMObject*>::iterator iter = snapshotOfActiveDOMObjects.be gin(); iter != snapshotOfActiveDOMObjects.end(); iter++) {
95 ASSERT((*iter)->suspendIfNeededCalled()); 109 // It's possible that the ActiveDOMObject is already destructed.
96 (*iter)->stop(); 110 // See a FIXME above.
111 if (m_activeDOMObjects.contains(*iter)) {
112 ASSERT((*iter)->executionContext() == context());
113 ASSERT((*iter)->suspendIfNeededCalled());
114 (*iter)->stop();
115 }
97 } 116 }
98 } 117 }
99 118
100 bool ContextLifecycleNotifier::hasPendingActivity() const 119 bool ContextLifecycleNotifier::hasPendingActivity() const
101 { 120 {
102 ActiveDOMObjectSet::const_iterator activeObjectsEnd = activeDOMObjects().end (); 121 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()) 122 if ((*iter)->hasPendingActivity())
105 return true; 123 return true;
106 } 124 }
107
108 return false; 125 return false;
109 } 126 }
110 127
111 } // namespace WebCore 128 } // 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