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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 | 43 |
44 // notifyContextDestroyed() should be explicitly dispatched from an | 44 // notifyContextDestroyed() should be explicitly dispatched from an |
45 // observed context to notify observers that contextDestroyed(). | 45 // observed context to notify observers that contextDestroyed(). |
46 // | 46 // |
47 // When contextDestroyed() is called, the observer's lifecycleContext() | 47 // When contextDestroyed() is called, the observer's lifecycleContext() |
48 // is still valid and safe to use during the notification. | 48 // is still valid and safe to use during the notification. |
49 virtual void notifyContextDestroyed(); | 49 virtual void notifyContextDestroyed(); |
50 | 50 |
51 DEFINE_INLINE_VIRTUAL_TRACE() | 51 DEFINE_INLINE_VIRTUAL_TRACE() |
52 { | 52 { |
53 #if ENABLE(OILPAN) | |
54 visitor->trace(m_observers); | 53 visitor->trace(m_observers); |
55 #endif | |
56 } | 54 } |
57 | 55 |
58 bool isIteratingOverObservers() const { return m_iterating != IteratingNone; } | 56 bool isIteratingOverObservers() const { return m_iterating != IteratingNone; } |
59 | 57 |
60 protected: | 58 protected: |
61 LifecycleNotifier() | 59 LifecycleNotifier() |
62 : m_iterating(IteratingNone) | 60 : m_iterating(IteratingNone) |
63 , m_didCallContextDestroyed(false) | 61 , m_didCallContextDestroyed(false) |
64 { | 62 { |
65 } | 63 } |
(...skipping 16 matching lines...) Expand all Loading... | |
82 | 80 |
83 private: | 81 private: |
84 bool m_didCallContextDestroyed; | 82 bool m_didCallContextDestroyed; |
85 }; | 83 }; |
86 | 84 |
87 template<typename T, typename Observer> | 85 template<typename T, typename Observer> |
88 inline LifecycleNotifier<T, Observer>::~LifecycleNotifier() | 86 inline LifecycleNotifier<T, Observer>::~LifecycleNotifier() |
89 { | 87 { |
90 // FIXME: Enable the following ASSERT. Also see a FIXME in Document::detach( ). | 88 // FIXME: Enable the following ASSERT. Also see a FIXME in Document::detach( ). |
91 // ASSERT(!m_observers.size() || m_didCallContextDestroyed); | 89 // ASSERT(!m_observers.size() || m_didCallContextDestroyed); |
92 | |
93 #if !ENABLE(OILPAN) | |
94 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); | |
95 for (Observer* observer : m_observers) { | |
96 observer->clearLifecycleContext(); | |
97 } | |
98 #endif | |
99 } | 90 } |
100 | 91 |
101 template<typename T, typename Observer> | 92 template<typename T, typename Observer> |
102 inline void LifecycleNotifier<T, Observer>::notifyContextDestroyed() | 93 inline void LifecycleNotifier<T, Observer>::notifyContextDestroyed() |
103 { | 94 { |
104 // Don't notify contextDestroyed() twice. | 95 // Don't notify contextDestroyed() twice. |
105 if (m_didCallContextDestroyed) | 96 if (m_didCallContextDestroyed) |
106 return; | 97 return; |
107 | 98 |
108 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); | 99 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); |
109 Vector<UntracedMember<Observer>> snapshotOfObservers; | 100 Vector<UntracedMember<Observer>> snapshotOfObservers; |
110 copyToVector(m_observers, snapshotOfObservers); | 101 copyToVector(m_observers, snapshotOfObservers); |
111 for (Observer* observer : snapshotOfObservers) { | 102 for (Observer* observer : snapshotOfObservers) { |
112 // FIXME: Oilpan: At the moment, it's possible that the Observer is | 103 if (!m_observers.contains(observer)) |
sof
2016/04/04 09:47:32
Removed this FIXME as it doesn't hold (&something
| |
113 // destructed during the iteration. | 104 continue; |
114 // Once we enable Oilpan by default for Observers *and* | 105 |
115 // Observer::contextDestroyed() does not call removeObserver(), | 106 ASSERT(observer->lifecycleContext() == context()); |
116 // we can remove the hack by making m_observers | 107 observer->contextDestroyed(); |
117 // a HeapHashSet<WeakMember<Observers>>. (i.e., we can just iterate | |
118 // m_observers without taking a snapshot). | |
119 if (m_observers.contains(observer)) { | |
120 ASSERT(observer->lifecycleContext() == context()); | |
121 observer->contextDestroyed(); | |
122 } | |
123 } | 108 } |
124 | 109 |
125 m_didCallContextDestroyed = true; | 110 m_didCallContextDestroyed = true; |
126 } | 111 } |
127 | 112 |
128 template<typename T, typename Observer> | 113 template<typename T, typename Observer> |
129 inline void LifecycleNotifier<T, Observer>::addObserver(Observer* observer) | 114 inline void LifecycleNotifier<T, Observer>::addObserver(Observer* observer) |
130 { | 115 { |
131 RELEASE_ASSERT(m_iterating != IteratingOverAll); | 116 RELEASE_ASSERT(m_iterating != IteratingOverAll); |
132 m_observers.add(observer); | 117 m_observers.add(observer); |
133 } | 118 } |
134 | 119 |
135 template<typename T, typename Observer> | 120 template<typename T, typename Observer> |
136 inline void LifecycleNotifier<T, Observer>::removeObserver(Observer* observer) | 121 inline void LifecycleNotifier<T, Observer>::removeObserver(Observer* observer) |
137 { | 122 { |
138 m_observers.remove(observer); | 123 m_observers.remove(observer); |
139 } | 124 } |
140 | 125 |
141 } // namespace blink | 126 } // namespace blink |
142 | 127 |
143 #endif // LifecycleNotifier_h | 128 #endif // LifecycleNotifier_h |
OLD | NEW |