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