| 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 10 matching lines...) Expand all Loading... |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 * | 25 * |
| 26 */ | 26 */ |
| 27 #ifndef LifecycleNotifier_h | 27 #ifndef LifecycleNotifier_h |
| 28 #define LifecycleNotifier_h | 28 #define LifecycleNotifier_h |
| 29 | 29 |
| 30 #include "platform/heap/Handle.h" | 30 #include "platform/heap/Handle.h" |
| 31 #include "wtf/AutoReset.h" |
| 31 #include "wtf/HashSet.h" | 32 #include "wtf/HashSet.h" |
| 32 #include "wtf/TemporaryChange.h" | |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 template<typename T, typename Observer> | 36 template<typename T, typename Observer> |
| 37 class LifecycleNotifier : public virtual GarbageCollectedMixin { | 37 class LifecycleNotifier : public virtual GarbageCollectedMixin { |
| 38 public: | 38 public: |
| 39 virtual ~LifecycleNotifier(); | 39 virtual ~LifecycleNotifier(); |
| 40 | 40 |
| 41 void addObserver(Observer*); | 41 void addObserver(Observer*); |
| 42 void removeObserver(Observer*); | 42 void removeObserver(Observer*); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 inline LifecycleNotifier<T, Observer>::~LifecycleNotifier() | 87 inline LifecycleNotifier<T, Observer>::~LifecycleNotifier() |
| 88 { | 88 { |
| 89 // FIXME: Enable the following ASSERT. Also see a FIXME in Document::detach(
). | 89 // FIXME: Enable the following ASSERT. Also see a FIXME in Document::detach(
). |
| 90 // ASSERT(!m_observers.size()); | 90 // ASSERT(!m_observers.size()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 template<typename T, typename Observer> | 93 template<typename T, typename Observer> |
| 94 inline void LifecycleNotifier<T, Observer>::notifyContextDestroyed() | 94 inline void LifecycleNotifier<T, Observer>::notifyContextDestroyed() |
| 95 { | 95 { |
| 96 // Observer unregistration is allowed, but effectively a no-op. | 96 // Observer unregistration is allowed, but effectively a no-op. |
| 97 TemporaryChange<IterationState> scope(m_iterationState, AllowingRemoval); | 97 AutoReset<IterationState> scope(&m_iterationState, AllowingRemoval); |
| 98 ObserverSet observers; | 98 ObserverSet observers; |
| 99 m_observers.swap(observers); | 99 m_observers.swap(observers); |
| 100 for (Observer* observer : observers) { | 100 for (Observer* observer : observers) { |
| 101 ASSERT(observer->lifecycleContext() == context()); | 101 ASSERT(observer->lifecycleContext() == context()); |
| 102 observer->contextDestroyed(); | 102 observer->contextDestroyed(); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 template<typename T, typename Observer> | 106 template<typename T, typename Observer> |
| 107 inline void LifecycleNotifier<T, Observer>::addObserver(Observer* observer) | 107 inline void LifecycleNotifier<T, Observer>::addObserver(Observer* observer) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 131 // the table is likely to become garbage soon. | 131 // the table is likely to become garbage soon. |
| 132 ThreadState::NoAllocationScope scope(ThreadState::current()); | 132 ThreadState::NoAllocationScope scope(ThreadState::current()); |
| 133 observers.removeAll(m_observers); | 133 observers.removeAll(m_observers); |
| 134 } | 134 } |
| 135 m_observers.swap(observers); | 135 m_observers.swap(observers); |
| 136 } | 136 } |
| 137 | 137 |
| 138 } // namespace blink | 138 } // namespace blink |
| 139 | 139 |
| 140 #endif // LifecycleNotifier_h | 140 #endif // LifecycleNotifier_h |
| OLD | NEW |