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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 bool isIteratingOverObservers() const { return m_iterating != IteratingNone;
} | 58 bool isIteratingOverObservers() const { return m_iterating != IteratingNone;
} |
59 | 59 |
60 protected: | 60 protected: |
61 explicit LifecycleNotifier(Context* context) | 61 explicit LifecycleNotifier(Context* context) |
62 : m_iterating(IteratingNone) | 62 : m_iterating(IteratingNone) |
63 , m_context(context) | 63 , m_context(context) |
64 { | 64 { |
65 } | 65 } |
66 | 66 |
| 67 virtual void removeAndNotifyAllObservers(); |
| 68 |
67 Context* context() const { return m_context; } | 69 Context* context() const { return m_context; } |
68 | 70 |
69 enum IterationType { | 71 enum IterationType { |
70 IteratingNone, | 72 IteratingNone, |
71 IteratingOverAll, | 73 IteratingOverAll, |
72 IteratingOverActiveDOMObjects, | 74 IteratingOverActiveDOMObjects, |
73 IteratingOverContextObservers, | 75 IteratingOverContextObservers, |
74 IteratingOverDocumentObservers, | 76 IteratingOverDocumentObservers, |
75 IteratingOverPageObservers, | 77 IteratingOverPageObservers, |
76 IteratingOverDOMWindowObservers | 78 IteratingOverDOMWindowObservers |
77 }; | 79 }; |
78 | 80 |
79 IterationType m_iterating; | 81 IterationType m_iterating; |
80 | 82 |
81 private: | 83 private: |
82 typedef HashSet<Observer*> ObserverSet; | 84 typedef HashSet<Observer*> ObserverSet; |
83 | 85 |
84 ObserverSet m_observers; | 86 ObserverSet m_observers; |
85 Context* m_context; | 87 Context* m_context; |
86 }; | 88 }; |
87 | 89 |
88 template<typename T> | 90 template<typename T> |
89 inline LifecycleNotifier<T>::~LifecycleNotifier() | 91 inline void LifecycleNotifier<T>::removeAndNotifyAllObservers() |
90 { | 92 { |
91 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverAll); | 93 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverAll); |
92 for (typename ObserverSet::iterator it = m_observers.begin(); it != m_observ
ers.end(); it = m_observers.begin()) { | 94 for (typename ObserverSet::iterator it = m_observers.begin(); it != m_observ
ers.end(); it = m_observers.begin()) { |
93 Observer* observer = *it; | 95 Observer* observer = *it; |
94 m_observers.remove(observer); | 96 m_observers.remove(observer); |
95 ASSERT(observer->lifecycleContext() == m_context); | 97 ASSERT(observer->lifecycleContext() == m_context); |
96 observer->contextDestroyed(); | 98 observer->contextDestroyed(); |
97 } | 99 } |
98 } | 100 } |
99 | 101 |
100 template<typename T> | 102 template<typename T> |
| 103 inline LifecycleNotifier<T>::~LifecycleNotifier() |
| 104 { |
| 105 removeAndNotifyAllObservers(); |
| 106 } |
| 107 |
| 108 template<typename T> |
101 inline void LifecycleNotifier<T>::addObserver(typename LifecycleNotifier<T>::Obs
erver* observer) | 109 inline void LifecycleNotifier<T>::addObserver(typename LifecycleNotifier<T>::Obs
erver* observer) |
102 { | 110 { |
103 RELEASE_ASSERT(m_iterating != IteratingOverAll); | 111 RELEASE_ASSERT(m_iterating != IteratingOverAll); |
104 m_observers.add(observer); | 112 m_observers.add(observer); |
105 } | 113 } |
106 | 114 |
107 template<typename T> | 115 template<typename T> |
108 inline void LifecycleNotifier<T>::removeObserver(typename LifecycleNotifier<T>::
Observer* observer) | 116 inline void LifecycleNotifier<T>::removeObserver(typename LifecycleNotifier<T>::
Observer* observer) |
109 { | 117 { |
110 RELEASE_ASSERT(m_iterating != IteratingOverAll); | 118 RELEASE_ASSERT(m_iterating != IteratingOverAll); |
111 m_observers.remove(observer); | 119 m_observers.remove(observer); |
112 } | 120 } |
113 | 121 |
114 | 122 |
115 | 123 |
116 } // namespace WebCore | 124 } // namespace WebCore |
117 | 125 |
118 #endif // LifecycleNotifier_h | 126 #endif // LifecycleNotifier_h |
OLD | NEW |