OLD | NEW |
---|---|
(Empty) | |
1 $$ This is a pump file for generating file templates. Pump is a python | |
2 $$ script that is part of the Google Test suite of utilities. Description | |
3 $$ can be found here: | |
4 $$ | |
5 $$ http://code.google.com/p/googletest/wiki/PumpManual | |
6 $$ | |
7 | |
8 $$ See comment for MAX_ARITY in base/bind.h.pump. | |
9 $var MAX_ARITY = 7 | |
10 | |
11 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
12 // Use of this source code is governed by a BSD-style license that can be | |
13 // found in the LICENSE file. | |
14 | |
15 #ifndef MEDIA_BASE_BIND_TO_LOOP_H_ | |
16 #define MEDIA_BASE_BIND_TO_LOOP_H_ | |
17 | |
18 #include "base/bind.h" | |
19 #include "base/callback_internal.h" // Avoid re-inventing CallbackForward/Forwar dType. | |
awong
2012/08/17 18:27:18
80-chars
Also you don't use ForwardType
Ami GONE FROM CHROMIUM
2012/08/17 23:55:46
Done.
| |
20 #include "base/location.h" | |
21 #include "base/message_loop_proxy.h" | |
22 | |
23 // This is a helper utility for base::Bind()ing callbacks on to particular | |
24 // MessageLoops. A typical use is when |a| (of class |A|) wants to hand a | |
25 // callback such as base::Bind(&A::AMethod, a) to |b|, but needs to ensure that | |
26 // when |b| executes the callback, it does so on a particular MessageLoop. | |
27 // | |
28 // Typical usage: request to be called back on the current thread: | |
29 // other->StartAsyncProcessAndCallMeBack( | |
30 // media::BindToLoop(MessageLoopProxy::current(), | |
31 // base::Bind(&MyClass::MyMethod, this))); | |
32 // | |
33 // Note that like base::Bind(), BindToLoop() can't bind non-constant references, | |
34 // and that *unlike* base::Bind(), BindToLoop() makes copies of its arguments, | |
35 // and thus can't be used with arrays. | |
36 | |
37 namespace media { | |
38 | |
39 template <typename T> struct TrampolineHelper; | |
40 | |
41 $range ARITY 0..MAX_ARITY | |
42 $for ARITY [[ | |
43 $range ARG 1..ARITY | |
44 | |
45 template <$for ARG , [[typename A$(ARG)]]> | |
46 struct TrampolineHelper<void($for ARG , [[A$(ARG)]])> { | |
47 static void Do( | |
awong
2012/08/17 18:27:18
Rename to Run()?
Ami GONE FROM CHROMIUM
2012/08/17 23:55:46
Done.
| |
48 const scoped_refptr<base::MessageLoopProxy>& loop, | |
49 const base::Callback<void($for ARG , [[A$(ARG)]])>& cb | |
50 $if ARITY != 0 [[, ]] | |
51 $for ARG , [[A$(ARG) a$(ARG)]] | |
52 ) { | |
53 loop->PostTask(FROM_HERE, base::Bind(cb | |
54 $if ARITY != 0 [[, ]] | |
55 $for ARG , [[base::internal::CallbackForward(a$(ARG))]])); | |
56 } | |
57 }; | |
58 | |
awong
2012/08/17 18:27:18
drope one newline?
Ami GONE FROM CHROMIUM
2012/08/17 23:55:46
Done.
| |
59 | |
60 ]] $$ for ARITY | |
61 | |
62 template<typename T> | |
63 static base::Callback<T> BindToLoop( | |
64 const scoped_refptr<base::MessageLoopProxy>& loop, | |
65 const base::Callback<T>& cb) { | |
66 return base::Bind(&TrampolineHelper<T>::Do, loop, cb); | |
67 } | |
68 | |
69 } // namespace media | |
70 | |
71 #endif // MEDIA_BASE_BIND_TO_LOOP_H_ | |
OLD | NEW |