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 <unordered_map> | 8 #include <unordered_map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 void Notify(const tracked_objects::Location& from_here, | 135 void Notify(const tracked_objects::Location& from_here, |
136 Method m, Params&&... params) { | 136 Method m, Params&&... params) { |
137 Callback<void(ObserverType*)> method = | 137 Callback<void(ObserverType*)> method = |
138 Bind(&internal::Dispatcher<ObserverType, Method>::Run, | 138 Bind(&internal::Dispatcher<ObserverType, Method>::Run, |
139 m, std::forward<Params>(params)...); | 139 m, std::forward<Params>(params)...); |
140 | 140 |
141 AutoLock lock(lock_); | 141 AutoLock lock(lock_); |
142 for (const auto& observer : observers_) { | 142 for (const auto& observer : observers_) { |
143 observer.second->PostTask( | 143 observer.second->PostTask( |
144 from_here, | 144 from_here, |
145 Bind(&ObserverListThreadSafe<ObserverType>::NotifyWrapper, this, | 145 BindOnce(&ObserverListThreadSafe<ObserverType>::NotifyWrapper, this, |
146 observer.first, NotificationData(from_here, method))); | 146 observer.first, NotificationData(from_here, method))); |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 private: | 150 private: |
151 friend class RefCountedThreadSafe<ObserverListThreadSafe<ObserverType>>; | 151 friend class RefCountedThreadSafe<ObserverListThreadSafe<ObserverType>>; |
152 | 152 |
153 struct NotificationData { | 153 struct NotificationData { |
154 NotificationData(const tracked_objects::Location& from_here_in, | 154 NotificationData(const tracked_objects::Location& from_here_in, |
155 const Callback<void(ObserverType*)>& method_in) | 155 const Callback<void(ObserverType*)>& method_in) |
156 : from_here(from_here_in), method(method_in) {} | 156 : from_here(from_here_in), method(method_in) {} |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 // Notification being dispatched on the current thread. | 204 // Notification being dispatched on the current thread. |
205 ThreadLocalPointer<const NotificationData> tls_current_notification_; | 205 ThreadLocalPointer<const NotificationData> tls_current_notification_; |
206 | 206 |
207 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); | 207 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); |
208 }; | 208 }; |
209 | 209 |
210 } // namespace base | 210 } // namespace base |
211 | 211 |
212 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ | 212 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ |
OLD | NEW |