OLD | NEW |
1 $$ This is a pump file for generating file templates. Pump is a python | 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 | 2 $$ script that is part of the Google Test suite of utilities. Description |
3 $$ can be found here: | 3 $$ can be found here: |
4 $$ | 4 $$ |
5 $$ http://code.google.com/p/googletest/wiki/PumpManual | 5 $$ http://code.google.com/p/googletest/wiki/PumpManual |
6 $$ | 6 $$ |
7 | 7 |
8 $$ See comment for MAX_ARITY in base/bind.h.pump. | 8 $$ See comment for MAX_ARITY in base/bind.h.pump. |
9 $var MAX_ARITY = 7 | 9 $var MAX_ARITY = 7 |
10 | 10 |
11 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 12 // Use of this source code is governed by a BSD-style license that can be |
13 // found in the LICENSE file. | 13 // found in the LICENSE file. |
14 | 14 |
15 #ifndef MEDIA_BASE_BIND_TO_LOOP_H_ | 15 #ifndef MEDIA_BASE_BIND_TO_LOOP_H_ |
16 #define MEDIA_BASE_BIND_TO_LOOP_H_ | 16 #define MEDIA_BASE_BIND_TO_LOOP_H_ |
17 | 17 |
18 #include "base/bind.h" | 18 #include "base/bind.h" |
19 #include "base/location.h" | 19 #include "base/location.h" |
20 #include "base/message_loop/message_loop_proxy.h" | 20 #include "base/message_loop/message_loop_proxy.h" |
21 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
22 | 22 |
23 // This is a helper utility for base::Bind()ing callbacks on to particular | 23 // This is a helper utility for base::Bind()ing callbacks to the current |
24 // MessageLoops. A typical use is when |a| (of class |A|) wants to hand a | 24 // MessageLoop. The 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 | 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. | 26 // when |b| executes the callback, it does so on |a|'s current MessageLoop. |
27 // | 27 // |
28 // Typical usage: request to be called back on the current thread: | 28 // Typical usage: request to be called back on the current thread: |
29 // other->StartAsyncProcessAndCallMeBack( | 29 // other->StartAsyncProcessAndCallMeBack( |
30 // media::BindToLoop(MessageLoopProxy::current(), | 30 // media::BindToCurrentLoop(base::Bind(&MyClass::MyMethod, this))); |
31 // base::Bind(&MyClass::MyMethod, this))); | |
32 // | 31 // |
33 // Note that like base::Bind(), BindToLoop() can't bind non-constant references, | 32 // Note that like base::Bind(), BindToCurrentLoop() can't bind non-constant |
34 // and that *unlike* base::Bind(), BindToLoop() makes copies of its arguments, | 33 // references, and that *unlike* base::Bind(), BindToCurrentLoop() makes copies |
35 // and thus can't be used with arrays. | 34 // of its arguments, and thus can't be used with arrays. |
36 | 35 |
37 namespace media { | 36 namespace media { |
38 | 37 |
39 // Mimic base::internal::CallbackForward, replacing p.Pass() with | 38 // Mimic base::internal::CallbackForward, replacing p.Pass() with |
40 // base::Passed(&p) to account for the extra layer of indirection. | 39 // base::Passed(&p) to account for the extra layer of indirection. |
41 namespace internal { | 40 namespace internal { |
42 template <typename T> | 41 template <typename T> |
43 T& TrampolineForward(T& t) { return t; } | 42 T& TrampolineForward(T& t) { return t; } |
44 | 43 |
45 template <typename T> | 44 template <typename T> |
(...skipping 26 matching lines...) Expand all Loading... |
72 $if ARITY != 0 [[, ]] | 71 $if ARITY != 0 [[, ]] |
73 $for ARG , [[internal::TrampolineForward(a$(ARG))]])); | 72 $for ARG , [[internal::TrampolineForward(a$(ARG))]])); |
74 } | 73 } |
75 }; | 74 }; |
76 | 75 |
77 | 76 |
78 ]] $$ for ARITY | 77 ]] $$ for ARITY |
79 | 78 |
80 } // namespace internal | 79 } // namespace internal |
81 | 80 |
82 template<typename T> | 81 // TODO(scherkus): Rename me to something that emphasizes the asynchrony |
83 static base::Callback<T> BindToLoop( | 82 // http://crbug.com/167240 |
84 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | |
85 const base::Callback<T>& cb) { | |
86 return base::Bind(&internal::TrampolineHelper<T>::Run, task_runner, cb); | |
87 } | |
88 | |
89 template<typename T> | 83 template<typename T> |
90 static base::Callback<T> BindToCurrentLoop( | 84 static base::Callback<T> BindToCurrentLoop( |
91 const base::Callback<T>& cb) { | 85 const base::Callback<T>& cb) { |
92 return BindToLoop(base::MessageLoopProxy::current(), cb); | 86 return base::Bind(&internal::TrampolineHelper<T>::Run, |
| 87 base::MessageLoopProxy::current(), cb); |
93 } | 88 } |
94 | 89 |
95 } // namespace media | 90 } // namespace media |
96 | 91 |
97 #endif // MEDIA_BASE_BIND_TO_LOOP_H_ | 92 #endif // MEDIA_BASE_BIND_TO_LOOP_H_ |
OLD | NEW |