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 21 matching lines...) Expand all Loading... | |
| 32 #include "wtf/TemporaryChange.h" | 32 #include "wtf/TemporaryChange.h" |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() | 36 void ContextLifecycleNotifier::notifyResumingActiveDOMObjects() |
| 37 { | 37 { |
| 38 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); | 38 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); |
| 39 Vector<ContextLifecycleObserver*> snapshotOfObservers; | 39 Vector<ContextLifecycleObserver*> snapshotOfObservers; |
| 40 copyToVector(m_observers, snapshotOfObservers); | 40 copyToVector(m_observers, snapshotOfObservers); |
| 41 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 41 for (ContextLifecycleObserver* observer : snapshotOfObservers) { |
| 42 #if !ENABLE(OILPAN) | |
| 43 if (!isObserverAlive(observer)) | |
| 44 continue; | |
| 45 #endif | |
| 42 // FIXME: Oilpan: At the moment, it's possible that a ActiveDOMObject | 46 // FIXME: Oilpan: At the moment, it's possible that a ActiveDOMObject |
|
haraken
2015/05/09 14:50:33
Not related to this CL, I think this FIXME is vali
| |
| 43 // observer is destructed while iterating. Once we enable Oilpan by defa ult | 47 // observer is destructed while iterating. Once we enable Oilpan by defa ult |
| 44 // for all LifecycleObserver<T>s, we can remove the hack by making m_obs ervers | 48 // for all LifecycleObserver<T>s, we can remove the hack by making m_obs ervers |
| 45 // a HeapHashSet<WeakMember<LifecycleObserver<T>>>. | 49 // a HeapHashSet<WeakMember<LifecycleObserver<T>>>. |
| 46 // (i.e., we can just iterate m_observers without taking a snapshot). | 50 // (i.e., we can just iterate m_observers without taking a snapshot). |
| 47 // For more details, see https://codereview.chromium.org/247253002/. | 51 // For more details, see https://codereview.chromium.org/247253002/. |
| 48 if (m_observers.contains(observer)) { | 52 if (m_observers.contains(observer)) { |
| 49 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO bjectType) | 53 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO bjectType) |
| 50 continue; | 54 continue; |
| 51 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs erver); | 55 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs erver); |
| 52 ASSERT(activeDOMObject->executionContext() == context()); | 56 ASSERT(activeDOMObject->executionContext() == context()); |
| 53 ASSERT(activeDOMObject->suspendIfNeededCalled()); | 57 ASSERT(activeDOMObject->suspendIfNeededCalled()); |
| 54 activeDOMObject->resume(); | 58 activeDOMObject->resume(); |
| 55 } | 59 } |
| 56 } | 60 } |
| 57 } | 61 } |
| 58 | 62 |
| 59 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() | 63 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() |
| 60 { | 64 { |
| 61 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); | 65 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); |
| 62 Vector<ContextLifecycleObserver*> snapshotOfObservers; | 66 Vector<ContextLifecycleObserver*> snapshotOfObservers; |
| 63 copyToVector(m_observers, snapshotOfObservers); | 67 copyToVector(m_observers, snapshotOfObservers); |
| 64 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 68 for (ContextLifecycleObserver* observer : snapshotOfObservers) { |
| 69 #if !ENABLE(OILPAN) | |
| 70 if (!isObserverAlive(observer)) | |
| 71 continue; | |
| 72 #endif | |
| 65 // It's possible that the ActiveDOMObject is already destructed. | 73 // It's possible that the ActiveDOMObject is already destructed. |
| 66 // See a FIXME above. | 74 // See a FIXME above. |
| 67 if (m_observers.contains(observer)) { | 75 if (m_observers.contains(observer)) { |
| 68 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO bjectType) | 76 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO bjectType) |
| 69 continue; | 77 continue; |
| 70 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs erver); | 78 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs erver); |
| 71 ASSERT(activeDOMObject->executionContext() == context()); | 79 ASSERT(activeDOMObject->executionContext() == context()); |
| 72 ASSERT(activeDOMObject->suspendIfNeededCalled()); | 80 ASSERT(activeDOMObject->suspendIfNeededCalled()); |
| 73 activeDOMObject->suspend(); | 81 activeDOMObject->suspend(); |
| 74 } | 82 } |
| 75 } | 83 } |
| 76 } | 84 } |
| 77 | 85 |
| 78 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() | 86 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() |
| 79 { | 87 { |
| 80 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); | 88 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); |
| 81 Vector<ContextLifecycleObserver*> snapshotOfObservers; | 89 Vector<ContextLifecycleObserver*> snapshotOfObservers; |
| 82 copyToVector(m_observers, snapshotOfObservers); | 90 copyToVector(m_observers, snapshotOfObservers); |
| 83 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 91 for (ContextLifecycleObserver* observer : snapshotOfObservers) { |
| 92 #if !ENABLE(OILPAN) | |
| 93 if (!isObserverAlive(observer)) | |
| 94 continue; | |
| 95 #endif | |
| 84 // It's possible that the ActiveDOMObject is already destructed. | 96 // It's possible that the ActiveDOMObject is already destructed. |
| 85 // See a FIXME above. | 97 // See a FIXME above. |
| 86 if (m_observers.contains(observer)) { | 98 if (m_observers.contains(observer)) { |
| 87 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO bjectType) | 99 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO bjectType) |
| 88 continue; | 100 continue; |
| 89 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs erver); | 101 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs erver); |
| 90 ASSERT(activeDOMObject->executionContext() == context()); | 102 ASSERT(activeDOMObject->executionContext() == context()); |
| 91 ASSERT(activeDOMObject->suspendIfNeededCalled()); | 103 ASSERT(activeDOMObject->suspendIfNeededCalled()); |
| 92 activeDOMObject->stop(); | 104 activeDOMObject->stop(); |
| 93 } | 105 } |
| 94 } | 106 } |
| 95 } | 107 } |
| 96 | 108 |
| 97 unsigned ContextLifecycleNotifier::activeDOMObjectCount() const | 109 unsigned ContextLifecycleNotifier::activeDOMObjectCount() const |
| 98 { | 110 { |
| 99 unsigned activeDOMObjects = 0; | 111 unsigned activeDOMObjects = 0; |
| 100 for (ContextLifecycleObserver* observer : m_observers) { | 112 for (ContextLifecycleObserver* observer : m_observers) { |
| 113 #if !ENABLE(OILPAN) | |
| 114 if (!isObserverAlive(observer)) | |
| 115 continue; | |
| 116 #endif | |
| 101 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType) | 117 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType) |
| 102 continue; | 118 continue; |
| 103 activeDOMObjects++; | 119 activeDOMObjects++; |
| 104 } | 120 } |
| 105 return activeDOMObjects; | 121 return activeDOMObjects; |
| 106 } | 122 } |
| 107 | 123 |
| 108 bool ContextLifecycleNotifier::hasPendingActivity() const | 124 bool ContextLifecycleNotifier::hasPendingActivity() const |
| 109 { | 125 { |
| 110 for (ContextLifecycleObserver* observer : m_observers) { | 126 for (ContextLifecycleObserver* observer : m_observers) { |
| 127 #if !ENABLE(OILPAN) | |
| 128 if (!isObserverAlive(observer)) | |
| 129 continue; | |
| 130 #endif | |
| 111 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType) | 131 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType) |
| 112 continue; | 132 continue; |
| 113 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe r); | 133 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe r); |
| 114 if (activeDOMObject->hasPendingActivity()) | 134 if (activeDOMObject->hasPendingActivity()) |
| 115 return true; | 135 return true; |
| 116 } | 136 } |
| 117 return false; | 137 return false; |
| 118 } | 138 } |
| 119 | 139 |
| 120 #if ENABLE(ASSERT) | 140 #if ENABLE(ASSERT) |
| 121 bool ContextLifecycleNotifier::contains(ActiveDOMObject* object) const | 141 bool ContextLifecycleNotifier::contains(ActiveDOMObject* object) const |
| 122 { | 142 { |
| 123 for (ContextLifecycleObserver* observer : m_observers) { | 143 for (ContextLifecycleObserver* observer : m_observers) { |
| 144 #if !ENABLE(OILPAN) | |
| 145 if (!isObserverAlive(observer)) | |
| 146 continue; | |
| 147 #endif | |
| 124 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType) | 148 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMObjec tType) |
| 125 continue; | 149 continue; |
| 126 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe r); | 150 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe r); |
| 127 if (activeDOMObject == object) | 151 if (activeDOMObject == object) |
| 128 return true; | 152 return true; |
| 129 } | 153 } |
| 130 return false; | 154 return false; |
| 131 } | 155 } |
| 132 #endif | 156 #endif |
| 133 | 157 |
| 134 } // namespace blink | 158 } // namespace blink |
| OLD | NEW |