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/message_loop_proxy.h" |
| 20 |
| 21 // This is a helper utility for base::Bind()ing callbacks on to particular |
| 22 // MessageLoops. A typical use is when |a| (of class |A|) wants to hand a |
| 23 // callback such as base::Bind(&A::AMethod, a) to |b|, but needs to ensure that |
| 24 // when |b| executes the callback, it does so on a particular MessageLoop. |
| 25 // |
| 26 // Typical usage: request to be called back on the current thread: |
| 27 // other->StartAsyncProcessAndCallMeBack( |
| 28 // media::BindToLoop(MessageLoopProxy::current(), |
| 29 // base::Bind(&MyClass::MyMethod, this))); |
| 30 |
| 31 namespace media { |
| 32 |
| 33 $range ARITY 0..MAX_ARITY |
| 34 $for ARITY [[ |
| 35 $range ARG 1..ARITY |
| 36 |
| 37 $if ARITY == 0 [[ |
| 38 |
| 39 static void TrampolineRun( |
| 40 scoped_refptr<base::MessageLoopProxy> loop, const base::Closure& cb) { |
| 41 loop->PostTask(FROM_HERE, base::Bind(cb)); |
| 42 } |
| 43 |
| 44 static base::Closure BindToLoop( |
| 45 scoped_refptr<base::MessageLoopProxy> loop, const base::Closure& cb) { |
| 46 return base::Bind(&TrampolineRun, loop, cb); |
| 47 } |
| 48 |
| 49 ]] $else [[ |
| 50 |
| 51 template<$for ARG , [[typename A$(ARG)]]> |
| 52 static void TrampolineRun( |
| 53 scoped_refptr<base::MessageLoopProxy> loop, |
| 54 const base::Callback<void($for ARG , [[A$(ARG)]])>& cb, |
| 55 $for ARG , [[A$(ARG) a$(ARG)]]) { |
| 56 loop->PostTask(FROM_HERE, base::Bind(cb, $for ARG , [[a$(ARG)]])); |
| 57 } |
| 58 |
| 59 template<$for ARG , [[typename A$(ARG)]]> |
| 60 static base::Callback<void($for ARG , [[A$(ARG)]])> BindToLoop( |
| 61 scoped_refptr<base::MessageLoopProxy> loop, |
| 62 const base::Callback<void($for ARG , [[A$(ARG)]])>& cb) { |
| 63 return base::Bind(&TrampolineRun<$for ARG , [[A$(ARG)]]>, loop, cb); |
| 64 } |
| 65 |
| 66 ]] |
| 67 |
| 68 ]] $$ for ARITY |
| 69 |
| 70 } // namespace media |
| 71 |
| 72 #endif // MEDIA_BASE_BIND_TO_LOOP_H_ |
OLD | NEW |