Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Side by Side Diff: Source/platform/LifecycleNotifier.h

Issue 203393002: Revert of Explicit notification and removal of lifecycle observers. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/workers/WorkerThread.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
69 Context* context() const { return m_context; } 67 Context* context() const { return m_context; }
70 68
71 enum IterationType { 69 enum IterationType {
72 IteratingNone, 70 IteratingNone,
73 IteratingOverAll, 71 IteratingOverAll,
74 IteratingOverActiveDOMObjects, 72 IteratingOverActiveDOMObjects,
75 IteratingOverContextObservers, 73 IteratingOverContextObservers,
76 IteratingOverDocumentObservers, 74 IteratingOverDocumentObservers,
77 IteratingOverPageObservers, 75 IteratingOverPageObservers,
78 IteratingOverDOMWindowObservers 76 IteratingOverDOMWindowObservers
79 }; 77 };
80 78
81 IterationType m_iterating; 79 IterationType m_iterating;
82 80
83 private: 81 private:
84 typedef HashSet<Observer*> ObserverSet; 82 typedef HashSet<Observer*> ObserverSet;
85 83
86 ObserverSet m_observers; 84 ObserverSet m_observers;
87 Context* m_context; 85 Context* m_context;
88 }; 86 };
89 87
90 template<typename T> 88 template<typename T>
91 inline void LifecycleNotifier<T>::removeAndNotifyAllObservers() 89 inline LifecycleNotifier<T>::~LifecycleNotifier()
92 { 90 {
93 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverAll); 91 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverAll);
94 for (typename ObserverSet::iterator it = m_observers.begin(); it != m_observ ers.end(); it = m_observers.begin()) { 92 for (typename ObserverSet::iterator it = m_observers.begin(); it != m_observ ers.end(); it = m_observers.begin()) {
95 Observer* observer = *it; 93 Observer* observer = *it;
96 m_observers.remove(observer); 94 m_observers.remove(observer);
97 ASSERT(observer->lifecycleContext() == m_context); 95 ASSERT(observer->lifecycleContext() == m_context);
98 observer->contextDestroyed(); 96 observer->contextDestroyed();
99 } 97 }
100 } 98 }
101 99
102 template<typename T> 100 template<typename T>
103 inline LifecycleNotifier<T>::~LifecycleNotifier()
104 {
105 removeAndNotifyAllObservers();
106 }
107
108 template<typename T>
109 inline void LifecycleNotifier<T>::addObserver(typename LifecycleNotifier<T>::Obs erver* observer) 101 inline void LifecycleNotifier<T>::addObserver(typename LifecycleNotifier<T>::Obs erver* observer)
110 { 102 {
111 RELEASE_ASSERT(m_iterating != IteratingOverAll); 103 RELEASE_ASSERT(m_iterating != IteratingOverAll);
112 m_observers.add(observer); 104 m_observers.add(observer);
113 } 105 }
114 106
115 template<typename T> 107 template<typename T>
116 inline void LifecycleNotifier<T>::removeObserver(typename LifecycleNotifier<T>:: Observer* observer) 108 inline void LifecycleNotifier<T>::removeObserver(typename LifecycleNotifier<T>:: Observer* observer)
117 { 109 {
118 RELEASE_ASSERT(m_iterating != IteratingOverAll); 110 RELEASE_ASSERT(m_iterating != IteratingOverAll);
119 m_observers.remove(observer); 111 m_observers.remove(observer);
120 } 112 }
121 113
122 114
123 115
124 } // namespace WebCore 116 } // namespace WebCore
125 117
126 #endif // LifecycleNotifier_h 118 #endif // LifecycleNotifier_h
OLDNEW
« no previous file with comments | « Source/core/workers/WorkerThread.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698