OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_OBSERVER_LIST_THREADSAFE_H_ | 5 #ifndef BASE_OBSERVER_LIST_THREADSAFE_H_ |
6 #define BASE_OBSERVER_LIST_THREADSAFE_H_ | 6 #define BASE_OBSERVER_LIST_THREADSAFE_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <map> | 9 #include <map> |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 observer_lists_.find(PlatformThread::CurrentId()); | 215 observer_lists_.find(PlatformThread::CurrentId()); |
216 | 216 |
217 // The ObserverList could have been removed already. In fact, it could | 217 // The ObserverList could have been removed already. In fact, it could |
218 // have been removed and then re-added! If the master list's loop | 218 // have been removed and then re-added! If the master list's loop |
219 // does not match this one, then we do not need to finish this | 219 // does not match this one, then we do not need to finish this |
220 // notification. | 220 // notification. |
221 if (it == observer_lists_.end() || it->second != context) | 221 if (it == observer_lists_.end() || it->second != context) |
222 return; | 222 return; |
223 } | 223 } |
224 | 224 |
225 { | 225 for (auto& observer : context->list) { |
226 typename ObserverList<ObserverType>::Iterator it(&context->list); | 226 method.Run(&observer); |
227 ObserverType* obs; | |
228 while ((obs = it.GetNext()) != nullptr) | |
229 method.Run(obs); | |
230 } | 227 } |
231 | 228 |
232 // If there are no more observers on the list, we can now delete it. | 229 // If there are no more observers on the list, we can now delete it. |
233 if (context->list.size() == 0) { | 230 if (context->list.size() == 0) { |
234 { | 231 { |
235 AutoLock lock(list_lock_); | 232 AutoLock lock(list_lock_); |
236 // Remove |list| if it's not already removed. | 233 // Remove |list| if it's not already removed. |
237 // This can happen if multiple observers got removed in a notification. | 234 // This can happen if multiple observers got removed in a notification. |
238 // See http://crbug.com/55725. | 235 // See http://crbug.com/55725. |
239 typename ObserversListMap::iterator it = | 236 typename ObserversListMap::iterator it = |
(...skipping 15 matching lines...) Expand all Loading... |
255 mutable Lock list_lock_; // Protects the observer_lists_. | 252 mutable Lock list_lock_; // Protects the observer_lists_. |
256 ObserversListMap observer_lists_; | 253 ObserversListMap observer_lists_; |
257 const NotificationType type_; | 254 const NotificationType type_; |
258 | 255 |
259 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); | 256 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); |
260 }; | 257 }; |
261 | 258 |
262 } // namespace base | 259 } // namespace base |
263 | 260 |
264 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ | 261 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ |
OLD | NEW |