| 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 17 matching lines...) Expand all Loading... |
| 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<IterationType> scope(m_iterating, IteratingOverAll); |
| 38 Vector<RawPtrWillBeUntracedMember<ContextLifecycleObserver>> snapshotOfObser
vers; | 38 Vector<UntracedMember<ContextLifecycleObserver>> snapshotOfObservers; |
| 39 copyToVector(m_observers, snapshotOfObservers); | 39 copyToVector(m_observers, snapshotOfObservers); |
| 40 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 40 for (ContextLifecycleObserver* observer : snapshotOfObservers) { |
| 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->executionContext() == context()); | 51 ASSERT(activeDOMObject->executionContext() == context()); |
| 52 ASSERT(activeDOMObject->suspendIfNeededCalled()); | 52 ASSERT(activeDOMObject->suspendIfNeededCalled()); |
| 53 activeDOMObject->resume(); | 53 activeDOMObject->resume(); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() | 58 void ContextLifecycleNotifier::notifySuspendingActiveDOMObjects() |
| 59 { | 59 { |
| 60 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); | 60 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); |
| 61 Vector<RawPtrWillBeUntracedMember<ContextLifecycleObserver>> snapshotOfObser
vers; | 61 Vector<UntracedMember<ContextLifecycleObserver>> snapshotOfObservers; |
| 62 copyToVector(m_observers, snapshotOfObservers); | 62 copyToVector(m_observers, snapshotOfObservers); |
| 63 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 63 for (ContextLifecycleObserver* observer : snapshotOfObservers) { |
| 64 // It's possible that the ActiveDOMObject is already destructed. | 64 // It's possible that the ActiveDOMObject is already destructed. |
| 65 // See a FIXME above. | 65 // See a FIXME above. |
| 66 if (m_observers.contains(observer)) { | 66 if (m_observers.contains(observer)) { |
| 67 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) | 67 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) |
| 68 continue; | 68 continue; |
| 69 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); | 69 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); |
| 70 ASSERT(activeDOMObject->executionContext() == context()); | 70 ASSERT(activeDOMObject->executionContext() == context()); |
| 71 ASSERT(activeDOMObject->suspendIfNeededCalled()); | 71 ASSERT(activeDOMObject->suspendIfNeededCalled()); |
| 72 activeDOMObject->suspend(); | 72 activeDOMObject->suspend(); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() | 77 void ContextLifecycleNotifier::notifyStoppingActiveDOMObjects() |
| 78 { | 78 { |
| 79 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); | 79 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); |
| 80 Vector<RawPtrWillBeUntracedMember<ContextLifecycleObserver>> snapshotOfObser
vers; | 80 Vector<UntracedMember<ContextLifecycleObserver>> snapshotOfObservers; |
| 81 copyToVector(m_observers, snapshotOfObservers); | 81 copyToVector(m_observers, snapshotOfObservers); |
| 82 for (ContextLifecycleObserver* observer : snapshotOfObservers) { | 82 for (ContextLifecycleObserver* observer : snapshotOfObservers) { |
| 83 // It's possible that the ActiveDOMObject is already destructed. | 83 // It's possible that the ActiveDOMObject is already destructed. |
| 84 // See a FIXME above. | 84 // See a FIXME above. |
| 85 if (m_observers.contains(observer)) { | 85 if (m_observers.contains(observer)) { |
| 86 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) | 86 if (observer->observerType() != ContextLifecycleObserver::ActiveDOMO
bjectType) |
| 87 continue; | 87 continue; |
| 88 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); | 88 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(obs
erver); |
| 89 ASSERT(activeDOMObject->executionContext() == context()); | 89 ASSERT(activeDOMObject->executionContext() == context()); |
| 90 ASSERT(activeDOMObject->suspendIfNeededCalled()); | 90 ASSERT(activeDOMObject->suspendIfNeededCalled()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 continue; | 124 continue; |
| 125 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); | 125 ActiveDOMObject* activeDOMObject = static_cast<ActiveDOMObject*>(observe
r); |
| 126 if (activeDOMObject == object) | 126 if (activeDOMObject == object) |
| 127 return true; | 127 return true; |
| 128 } | 128 } |
| 129 return false; | 129 return false; |
| 130 } | 130 } |
| 131 #endif | 131 #endif |
| 132 | 132 |
| 133 } // namespace blink | 133 } // namespace blink |
| OLD | NEW |