| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "core/dom/ContextLifecycleNotifier.h" | 28 #include "core/dom/ContextLifecycleNotifier.h" |
| 29 | 29 |
| 30 #include "core/dom/ActiveDOMObject.h" | 30 #include "core/dom/ActiveDOMObject.h" |
| 31 #include "wtf/TemporaryChange.h" | 31 #include "wtf/TemporaryChange.h" |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() | 35 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() |
| 36 { | 36 { |
| 37 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); | 37 TemporaryChange<IterationState> scope(m_iterationState, AllowingNone); |
| 38 Vector<UntracedMember<ContextLifecycleObserver>> snapshotOfObservers; | 38 for (ContextLifecycleObserver* observer : m_observers) { |
| 39 copyToVector(m_observers, snapshotOfObservers); | 39 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) |
| 40 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 40 continue; |
| 41 // FIXME: Oilpan: At the moment, it's possible that a ActiveDOMObject | 41 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); |
| 42 // observer is destructed while iterating. Once we enable Oilpan by defa
ult | |
| 43 // for all LifecycleObserver<T>s, we can remove the hack by making m_obs
ervers | |
| 44 // a HeapHashSet<WeakMember<LifecycleObserver<T>>>. | |
| 45 // (i.e., we can just iterate m_observers without taking a snapshot). | |
| 46 // For more details, see https://codereview.chromium.org/247253002/. | |
| 47 if (m_observers.contains(observer)) { | |
| 48 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) | |
| 49 continue; | |
| 50 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); | |
| 51 #if DCHECK_IS_ON() | 42 #if DCHECK_IS_ON() |
| 52 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); | 43 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); |
| 53 DCHECK(activeDOMObject->suspendIfNeededCalled()); | 44 DCHECK(activeDOMObject->suspendIfNeededCalled()); |
| 54 #endif | 45 #endif |
| 55 activeDOMObject->resume(); | 46 activeDOMObject->resume(); |
| 56 } | |
| 57 } | 47 } |
| 58 } | 48 } |
| 59 | 49 |
| 60 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() | 50 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() |
| 61 { | 51 { |
| 62 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); | 52 TemporaryChange<IterationState> scope(m_iterationState, AllowingNone); |
| 63 Vector<UntracedMember<ContextLifecycleObserver>> snapshotOfObservers; | 53 for (ContextLifecycleObserver* observer : m_observers) { |
| 64 copyToVector(m_observers, snapshotOfObservers); | 54 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) |
| 65 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 55 continue; |
| 66 // It's possible that the ActiveDOMObject is already destructed. | 56 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); |
| 67 // See a FIXME above. | |
| 68 if (m_observers.contains(observer)) { | |
| 69 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) | |
| 70 continue; | |
| 71 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); | |
| 72 #if DCHECK_IS_ON() | 57 #if DCHECK_IS_ON() |
| 73 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); | 58 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); |
| 74 DCHECK(activeDOMObject->suspendIfNeededCalled()); | 59 DCHECK(activeDOMObject->suspendIfNeededCalled()); |
| 75 #endif | 60 #endif |
| 76 activeDOMObject->suspend(); | 61 activeDOMObject->suspend(); |
| 77 } | |
| 78 } | 62 } |
| 79 } | 63 } |
| 80 | 64 |
| 81 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() | 65 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() |
| 82 { | 66 { |
| 83 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); | 67 // Neither additions nor removals are allowed while iterating. |
| 84 Vector<UntracedMember<ContextLifecycleObserver>> snapshotOfObservers; | 68 TemporaryChange<IterationState> scope(m_iterationState, AllowingNone); |
| 85 copyToVector(m_observers, snapshotOfObservers); | 69 for (ContextLifecycleObserver* observer : m_observers) { |
| 86 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 70 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) |
| 87 // It's possible that the ActiveDOMObject is already destructed. | 71 continue; |
| 88 // See a FIXME above. | 72 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); |
| 89 if (m_observers.contains(observer)) { | |
| 90 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) | |
| 91 continue; | |
| 92 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); | |
| 93 #if DCHECK_IS_ON() | 73 #if DCHECK_IS_ON() |
| 94 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); | 74 DCHECK_EQ(activeDOMObject->getExecutionContext(), context()); |
| 95 DCHECK(activeDOMObject->suspendIfNeededCalled()); | 75 DCHECK(activeDOMObject->suspendIfNeededCalled()); |
| 96 #endif | 76 #endif |
| 97 activeDOMObject->stop(); | 77 activeDOMObject->stop(); |
| 98 } | |
| 99 } | 78 } |
| 100 } | 79 } |
| 101 | 80 |
| 102 unsigned ContextLifecycleNotifier::activeDOMObjectCount() const | 81 unsigned ContextLifecycleNotifier::activeDOMObjectCount() const |
| 103 { | 82 { |
| 104 unsigned activeDOMObjects = 0; | 83 unsigned activeDOMObjects = 0; |
| 105 for (ContextLifecycleObserver* observer : m_observers) { | 84 for (ContextLifecycleObserver* observer : m_observers) { |
| 106 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) | 85 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) |
| 107 continue; | 86 continue; |
| 108 activeDOMObjects++; | 87 activeDOMObjects++; |
| 109 } | 88 } |
| 110 return activeDOMObjects; | 89 return activeDOMObjects; |
| 111 } | 90 } |
| 112 | 91 |
| 113 #if DCHECK_IS_ON() | 92 #if DCHECK_IS_ON() |
| 114 bool ContextLifecycleNotifier::contains(ActiveDOMObject* object) const | 93 bool ContextLifecycleNotifier::contains(ActiveDOMObject* object) const |
| 115 { | 94 { |
| 116 for (ContextLifecycleObserver* observer : m_observers) { | 95 for (ContextLifecycleObserver* observer : m_observers) { |
| 117 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) | 96 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec
tType) |
| 118 continue; | 97 continue; |
| 119 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); | 98 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); |
| 120 if (activeDOMObject == object) | 99 if (activeDOMObject == object) |
| 121 return true; | 100 return true; |
| 122 } | 101 } |
| 123 return false; | 102 return false; |
| 124 } | 103 } |
| 125 #endif | 104 #endif |
| 126 | 105 |
| 127 } // namespace blink | 106 } // namespace blink |
| OLD | NEW |