Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| OLD | NEW |