Index: media/base/bind_to_loop.h.pump |
diff --git a/media/base/bind_to_loop.h.pump b/media/base/bind_to_loop.h.pump |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a2b48bf0d19d79dacef40ab5ebccaec7efb1c34f |
--- /dev/null |
+++ b/media/base/bind_to_loop.h.pump |
@@ -0,0 +1,71 @@ |
+$$ This is a pump file for generating file templates. Pump is a python |
+$$ script that is part of the Google Test suite of utilities. Description |
+$$ can be found here: |
+$$ |
+$$ http://code.google.com/p/googletest/wiki/PumpManual |
+$$ |
+ |
+$$ See comment for MAX_ARITY in base/bind.h.pump. |
+$var MAX_ARITY = 7 |
+ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_BASE_BIND_TO_LOOP_H_ |
+#define MEDIA_BASE_BIND_TO_LOOP_H_ |
+ |
+#include "base/bind.h" |
+#include "base/callback_internal.h" // Avoid re-inventing CallbackForward. |
+#include "base/location.h" |
+#include "base/message_loop_proxy.h" |
+ |
+// This is a helper utility for base::Bind()ing callbacks on to particular |
+// MessageLoops. A typical use is when |a| (of class |A|) wants to hand a |
+// callback such as base::Bind(&A::AMethod, a) to |b|, but needs to ensure that |
+// when |b| executes the callback, it does so on a particular MessageLoop. |
+// |
+// Typical usage: request to be called back on the current thread: |
+// other->StartAsyncProcessAndCallMeBack( |
+// media::BindToLoop(MessageLoopProxy::current(), |
+// base::Bind(&MyClass::MyMethod, this))); |
+// |
+// Note that like base::Bind(), BindToLoop() can't bind non-constant references, |
+// and that *unlike* base::Bind(), BindToLoop() makes copies of its arguments, |
+// and thus can't be used with arrays. |
+ |
+namespace media { |
+ |
+template <typename T> struct TrampolineHelper; |
+ |
+$range ARITY 0..MAX_ARITY |
+$for ARITY [[ |
+$range ARG 1..ARITY |
+ |
+template <$for ARG , [[typename A$(ARG)]]> |
+struct TrampolineHelper<void($for ARG , [[A$(ARG)]])> { |
+ static void Run( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<void($for ARG , [[A$(ARG)]])>& cb |
+$if ARITY != 0 [[, ]] |
+$for ARG , [[A$(ARG) a$(ARG)]] |
+) { |
+ loop->PostTask(FROM_HERE, base::Bind(cb |
+$if ARITY != 0 [[, ]] |
+$for ARG , [[base::internal::CallbackForward(a$(ARG))]])); |
+ } |
+}; |
+ |
+ |
+]] $$ for ARITY |
+ |
+template<typename T> |
+static base::Callback<T> BindToLoop( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<T>& cb) { |
+ return base::Bind(&TrampolineHelper<T>::Run, loop, cb); |
+} |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_BIND_TO_LOOP_H_ |