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

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

Issue 2629593004: Disambiguate LifecycleObserver::contextDestroyed (Closed)
Patch Set: temp Created 3 years, 11 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 template <typename T, typename Observer> 85 template <typename T, typename Observer>
86 inline void LifecycleNotifier<T, Observer>::notifyContextDestroyed() { 86 inline void LifecycleNotifier<T, Observer>::notifyContextDestroyed() {
87 // Observer unregistration is allowed, but effectively a no-op. 87 // Observer unregistration is allowed, but effectively a no-op.
88 AutoReset<IterationState> scope(&m_iterationState, AllowingRemoval); 88 AutoReset<IterationState> scope(&m_iterationState, AllowingRemoval);
89 ObserverSet observers; 89 ObserverSet observers;
90 m_observers.swap(observers); 90 m_observers.swap(observers);
91 for (Observer* observer : observers) { 91 for (Observer* observer : observers) {
92 DCHECK(observer->lifecycleContext() == context()); 92 DCHECK(observer->lifecycleContext() == context());
93 observer->contextDestroyed(); 93 observer->contextDestroyed(context());
94 observer->clearContext(); 94 observer->clearContext();
95 } 95 }
96 } 96 }
97 97
98 template <typename T, typename Observer> 98 template <typename T, typename Observer>
99 inline void LifecycleNotifier<T, Observer>::addObserver(Observer* observer) { 99 inline void LifecycleNotifier<T, Observer>::addObserver(Observer* observer) {
100 RELEASE_ASSERT(m_iterationState & AllowingAddition); 100 RELEASE_ASSERT(m_iterationState & AllowingAddition);
101 m_observers.add(observer); 101 m_observers.add(observer);
102 } 102 }
103 103
104 template <typename T, typename Observer> 104 template <typename T, typename Observer>
105 inline void LifecycleNotifier<T, Observer>::removeObserver(Observer* observer) { 105 inline void LifecycleNotifier<T, Observer>::removeObserver(Observer* observer) {
106 // If immediate removal isn't currently allowed, 106 // If immediate removal isn't currently allowed,
107 // |observer| is recorded for pending removal. 107 // |observer| is recorded for pending removal.
108 if (m_iterationState & AllowPendingRemoval) { 108 if (m_iterationState & AllowPendingRemoval) {
109 m_observers.add(observer); 109 m_observers.add(observer);
110 return; 110 return;
111 } 111 }
112 RELEASE_ASSERT(m_iterationState & AllowingRemoval); 112 RELEASE_ASSERT(m_iterationState & AllowingRemoval);
113 m_observers.remove(observer); 113 m_observers.remove(observer);
114 } 114 }
115 115
116 } // namespace blink 116 } // namespace blink
117 117
118 #endif // LifecycleNotifier_h 118 #endif // LifecycleNotifier_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/LifecycleContextTest.cpp ('k') | third_party/WebKit/Source/platform/LifecycleObserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698