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

Side by Side Diff: base/observer_list_threadsafe.h

Issue 821453003: Update legacy Tuple-using code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: media Created 6 years 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 // 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
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> 170 template <class Method>
171 void Notify(Method m) { 171 void Notify(Method m) {
Nico 2014/12/22 17:03:12 can possibly be a variadic template
172 UnboundMethod<ObserverType, Method, Tuple0> method(m, MakeTuple()); 172 UnboundMethod<ObserverType, Method, Tuple<>> method(m, MakeTuple());
173 Notify<Method, Tuple0>(method); 173 Notify<Method, Tuple<>>(method);
174 } 174 }
175 175
176 template <class Method, class A> 176 template <class Method, class A>
177 void Notify(Method m, const A& a) { 177 void Notify(Method m, const A& a) {
178 UnboundMethod<ObserverType, Method, Tuple1<A> > method(m, MakeTuple(a)); 178 UnboundMethod<ObserverType, Method, Tuple<A> > method(m, MakeTuple(a));
179 Notify<Method, Tuple1<A> >(method); 179 Notify<Method, Tuple<A> >(method);
180 } 180 }
181 181
182 template <class Method, class A, class B> 182 template <class Method, class A, class B>
183 void Notify(Method m, const A& a, const B& b) { 183 void Notify(Method m, const A& a, const B& b) {
184 UnboundMethod<ObserverType, Method, Tuple2<A, B> > method( 184 UnboundMethod<ObserverType, Method, Tuple<A, B> > method(
185 m, MakeTuple(a, b)); 185 m, MakeTuple(a, b));
186 Notify<Method, Tuple2<A, B> >(method); 186 Notify<Method, Tuple<A, B> >(method);
187 } 187 }
188 188
189 template <class Method, class A, class B, class C> 189 template <class Method, class A, class B, class C>
190 void Notify(Method m, const A& a, const B& b, const C& c) { 190 void Notify(Method m, const A& a, const B& b, const C& c) {
191 UnboundMethod<ObserverType, Method, Tuple3<A, B, C> > method( 191 UnboundMethod<ObserverType, Method, Tuple<A, B, C> > method(
192 m, MakeTuple(a, b, c)); 192 m, MakeTuple(a, b, c));
193 Notify<Method, Tuple3<A, B, C> >(method); 193 Notify<Method, Tuple<A, B, C> >(method);
194 } 194 }
195 195
196 template <class Method, class A, class B, class C, class D> 196 template <class Method, class A, class B, class C, class D>
197 void Notify(Method m, const A& a, const B& b, const C& c, const D& d) { 197 void Notify(Method m, const A& a, const B& b, const C& c, const D& d) {
198 UnboundMethod<ObserverType, Method, Tuple4<A, B, C, D> > method( 198 UnboundMethod<ObserverType, Method, Tuple<A, B, C, D> > method(
199 m, MakeTuple(a, b, c, d)); 199 m, MakeTuple(a, b, c, d));
200 Notify<Method, Tuple4<A, B, C, D> >(method); 200 Notify<Method, Tuple<A, B, C, D> >(method);
201 } 201 }
202 202
203 // TODO(mbelshe): Add more wrappers for Notify() with more arguments. 203 // TODO(mbelshe): Add more wrappers for Notify() with more arguments.
204 204
205 private: 205 private:
206 // See comment above ObserverListThreadSafeTraits' definition. 206 // See comment above ObserverListThreadSafeTraits' definition.
207 friend struct ObserverListThreadSafeTraits<ObserverType>; 207 friend struct ObserverListThreadSafeTraits<ObserverType>;
208 208
209 struct ObserverListContext { 209 struct ObserverListContext {
210 explicit ObserverListContext(NotificationType type) 210 explicit ObserverListContext(NotificationType type)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 ObserversListMap; 286 ObserversListMap;
287 287
288 mutable base::Lock list_lock_; // Protects the observer_lists_. 288 mutable base::Lock list_lock_; // Protects the observer_lists_.
289 ObserversListMap observer_lists_; 289 ObserversListMap observer_lists_;
290 const NotificationType type_; 290 const NotificationType type_;
291 291
292 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); 292 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe);
293 }; 293 };
294 294
295 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ 295 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698