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