| 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 | 10 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 base::AutoLock lock(list_lock_); | 161 base::AutoLock lock(list_lock_); |
| 162 DCHECK(observer_lists_.empty()); | 162 DCHECK(observer_lists_.empty()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 // Notify methods. | 165 // Notify methods. |
| 166 // Make a thread-safe callback to each Observer in the list. | 166 // Make a thread-safe callback to each Observer in the list. |
| 167 // Note, these calls are effectively asynchronous. You cannot assume | 167 // Note, these calls are effectively asynchronous. You cannot assume |
| 168 // that at the completion of the Notify call that all Observers have | 168 // that at the completion of the Notify call that all Observers have |
| 169 // been Notified. The notification may still be pending delivery. | 169 // been Notified. The notification may still be pending delivery. |
| 170 template <class Method, class... Params> | 170 template <class Method, class... Params> |
| 171 void Notify(Method m, const Params&... params) { | 171 void Notify(const tracked_objects::Location& from_here, |
| 172 Method m, |
| 173 const Params&... params) { |
| 172 UnboundMethod<ObserverType, Method, Tuple<Params...>> method( | 174 UnboundMethod<ObserverType, Method, Tuple<Params...>> method( |
| 173 m, MakeTuple(params...)); | 175 m, MakeTuple(params...)); |
| 174 | 176 |
| 175 base::AutoLock lock(list_lock_); | 177 base::AutoLock lock(list_lock_); |
| 176 for (const auto& entry : observer_lists_) { | 178 for (const auto& entry : observer_lists_) { |
| 177 ObserverListContext* context = entry.second; | 179 ObserverListContext* context = entry.second; |
| 178 context->loop->PostTask( | 180 context->loop->PostTask( |
| 179 FROM_HERE, | 181 from_here, |
| 180 base::Bind( | 182 base::Bind( |
| 181 &ObserverListThreadSafe<ObserverType>::template NotifyWrapper< | 183 &ObserverListThreadSafe<ObserverType>::template NotifyWrapper< |
| 182 Method, Tuple<Params...>>, | 184 Method, Tuple<Params...>>, |
| 183 this, context, method)); | 185 this, context, method)); |
| 184 } | 186 } |
| 185 } | 187 } |
| 186 | 188 |
| 187 private: | 189 private: |
| 188 // See comment above ObserverListThreadSafeTraits' definition. | 190 // See comment above ObserverListThreadSafeTraits' definition. |
| 189 friend struct ObserverListThreadSafeTraits<ObserverType>; | 191 friend struct ObserverListThreadSafeTraits<ObserverType>; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 ObserversListMap; | 257 ObserversListMap; |
| 256 | 258 |
| 257 mutable base::Lock list_lock_; // Protects the observer_lists_. | 259 mutable base::Lock list_lock_; // Protects the observer_lists_. |
| 258 ObserversListMap observer_lists_; | 260 ObserversListMap observer_lists_; |
| 259 const NotificationType type_; | 261 const NotificationType type_; |
| 260 | 262 |
| 261 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); | 263 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); |
| 262 }; | 264 }; |
| 263 | 265 |
| 264 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ | 266 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ |
| OLD | NEW |