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

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

Issue 960223002: Detach SpeechRecognitionController upon page detach. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Adjust assert and allow repeated observer detaches Created 5 years, 10 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
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 , m_didCallContextDestroyed(false) 64 , m_didCallContextDestroyed(false)
65 { 65 {
66 } 66 }
67 67
68 void detachObservers();
69
68 Context* context() const { return m_context; } 70 Context* context() const { return m_context; }
69 71
70 enum IterationType { 72 enum IterationType {
71 IteratingNone, 73 IteratingNone,
72 IteratingOverAll, 74 IteratingOverAll,
73 IteratingOverActiveDOMObjects, 75 IteratingOverActiveDOMObjects,
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 bool m_didCallContextDestroyed; 88 bool m_didCallContextDestroyed;
87 }; 89 };
88 90
89 template<typename T> 91 template<typename T>
90 inline LifecycleNotifier<T>::~LifecycleNotifier() 92 inline LifecycleNotifier<T>::~LifecycleNotifier()
91 { 93 {
92 // FIXME: Enable the following ASSERT. Also see a FIXME in Document::detach( ). 94 // FIXME: Enable the following ASSERT. Also see a FIXME in Document::detach( ).
93 // ASSERT(!m_observers.size() || m_didCallContextDestroyed); 95 // ASSERT(!m_observers.size() || m_didCallContextDestroyed);
94 96
95 #if !ENABLE(OILPAN) 97 #if !ENABLE(OILPAN)
96 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverAll); 98 detachObservers();
97 for (Observer* observer : m_observers) {
98 ASSERT(observer->lifecycleContext() == m_context);
99 observer->clearLifecycleContext();
100 }
101 #endif 99 #endif
102 } 100 }
103 101
104 template<typename T> 102 template<typename T>
103 inline void LifecycleNotifier<T>::detachObservers()
104 {
105 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverAll);
106 for (Observer* observer : m_observers) {
107 ASSERT(!observer->lifecycleContext() || observer->lifecycleContext() == m_context);
108 observer->clearLifecycleContext();
109 }
110 }
111
112 template<typename T>
105 inline void LifecycleNotifier<T>::notifyContextDestroyed() 113 inline void LifecycleNotifier<T>::notifyContextDestroyed()
106 { 114 {
107 // Don't notify contextDestroyed() twice. 115 // Don't notify contextDestroyed() twice.
108 if (m_didCallContextDestroyed) 116 if (m_didCallContextDestroyed)
109 return; 117 return;
110 118
111 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverAll); 119 TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverAll);
112 Vector<Observer*> snapshotOfObservers; 120 Vector<Observer*> snapshotOfObservers;
113 copyToVector(m_observers, snapshotOfObservers); 121 copyToVector(m_observers, snapshotOfObservers);
114 for (Observer* observer : snapshotOfObservers) { 122 for (Observer* observer : snapshotOfObservers) {
(...skipping 19 matching lines...) Expand all
134 142
135 template<typename T> 143 template<typename T>
136 inline void LifecycleNotifier<T>::removeObserver(typename LifecycleNotifier<T>:: Observer* observer) 144 inline void LifecycleNotifier<T>::removeObserver(typename LifecycleNotifier<T>:: Observer* observer)
137 { 145 {
138 m_observers.remove(observer); 146 m_observers.remove(observer);
139 } 147 }
140 148
141 } // namespace blink 149 } // namespace blink
142 150
143 #endif // LifecycleNotifier_h 151 #endif // LifecycleNotifier_h
OLDNEW
« Source/core/page/Page.cpp ('K') | « Source/modules/speech/SpeechRecognitionController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698