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

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

Issue 2365463004: Revert of Clear LifecycleObserver::m_context when LifecycleObserver::contextDestroyed gets called (Closed)
Patch Set: Created 4 years, 2 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 55
56 bool isIteratingOverObservers() const { return m_iterationState != NotIterat ing; } 56 bool isIteratingOverObservers() const { return m_iterationState != NotIterat ing; }
57 57
58 protected: 58 protected:
59 LifecycleNotifier() 59 LifecycleNotifier()
60 : m_iterationState(NotIterating) 60 : m_iterationState(NotIterating)
61 { 61 {
62 } 62 }
63 63
64 #if DCHECK_IS_ON()
64 T* context() { return static_cast<T*>(this); } 65 T* context() { return static_cast<T*>(this); }
66 #endif
65 67
66 using ObserverSet = HeapHashSet<WeakMember<Observer>>; 68 using ObserverSet = HeapHashSet<WeakMember<Observer>>;
67 69
68 void removePending(ObserverSet&); 70 void removePending(ObserverSet&);
69 71
70 enum IterationState { 72 enum IterationState {
71 AllowingNone = 0, 73 AllowingNone = 0,
72 AllowingAddition = 1, 74 AllowingAddition = 1,
73 AllowingRemoval = 2, 75 AllowingRemoval = 2,
74 NotIterating = AllowingAddition | AllowingRemoval, 76 NotIterating = AllowingAddition | AllowingRemoval,
(...skipping 14 matching lines...) Expand all
89 } 91 }
90 92
91 template<typename T, typename Observer> 93 template<typename T, typename Observer>
92 inline void LifecycleNotifier<T, Observer>::notifyContextDestroyed() 94 inline void LifecycleNotifier<T, Observer>::notifyContextDestroyed()
93 { 95 {
94 // Observer unregistration is allowed, but effectively a no-op. 96 // Observer unregistration is allowed, but effectively a no-op.
95 AutoReset<IterationState> scope(&m_iterationState, AllowingRemoval); 97 AutoReset<IterationState> scope(&m_iterationState, AllowingRemoval);
96 ObserverSet observers; 98 ObserverSet observers;
97 m_observers.swap(observers); 99 m_observers.swap(observers);
98 for (Observer* observer : observers) { 100 for (Observer* observer : observers) {
99 DCHECK(observer->lifecycleContext() == context()); 101 ASSERT(observer->lifecycleContext() == context());
100 observer->contextDestroyed(); 102 observer->contextDestroyed();
101 observer->clearContext();
102 } 103 }
103 } 104 }
104 105
105 template<typename T, typename Observer> 106 template<typename T, typename Observer>
106 inline void LifecycleNotifier<T, Observer>::addObserver(Observer* observer) 107 inline void LifecycleNotifier<T, Observer>::addObserver(Observer* observer)
107 { 108 {
108 RELEASE_ASSERT(m_iterationState & AllowingAddition); 109 RELEASE_ASSERT(m_iterationState & AllowingAddition);
109 m_observers.add(observer); 110 m_observers.add(observer);
110 } 111 }
111 112
(...skipping 18 matching lines...) Expand all
130 // the table is likely to become garbage soon. 131 // the table is likely to become garbage soon.
131 ThreadState::NoAllocationScope scope(ThreadState::current()); 132 ThreadState::NoAllocationScope scope(ThreadState::current());
132 observers.removeAll(m_observers); 133 observers.removeAll(m_observers);
133 } 134 }
134 m_observers.swap(observers); 135 m_observers.swap(observers);
135 } 136 }
136 137
137 } // namespace blink 138 } // namespace blink
138 139
139 #endif // LifecycleNotifier_h 140 #endif // LifecycleNotifier_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/websockets/DOMWebSocket.cpp ('k') | third_party/WebKit/Source/platform/LifecycleObserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698