Index: media/base/bind_to_loop.h |
diff --git a/media/base/bind_to_loop.h b/media/base/bind_to_loop.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..24f941968f8005c08a6d791f3cc961018e46d246 |
--- /dev/null |
+++ b/media/base/bind_to_loop.h |
@@ -0,0 +1,159 @@ |
+// This file was GENERATED by command: |
+// pump.py bind_to_loop.h.pump |
+// DO NOT EDIT BY HAND!!! |
+ |
+ |
+// 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; |
+ |
+template <> |
+struct TrampolineHelper<void()> { |
+ static void Run( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<void()>& cb) { |
+ loop->PostTask(FROM_HERE, base::Bind(cb)); |
+ } |
+}; |
+ |
+ |
+template <typename A1> |
+struct TrampolineHelper<void(A1)> { |
+ static void Run( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<void(A1)>& cb, A1 a1) { |
+ loop->PostTask(FROM_HERE, base::Bind(cb, |
+ base::internal::CallbackForward(a1))); |
+ } |
+}; |
+ |
+ |
+template <typename A1, typename A2> |
+struct TrampolineHelper<void(A1, A2)> { |
+ static void Run( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<void(A1, A2)>& cb, A1 a1, A2 a2) { |
+ loop->PostTask(FROM_HERE, base::Bind(cb, |
+ base::internal::CallbackForward(a1), |
+ base::internal::CallbackForward(a2))); |
+ } |
+}; |
+ |
+ |
+template <typename A1, typename A2, typename A3> |
+struct TrampolineHelper<void(A1, A2, A3)> { |
+ static void Run( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<void(A1, A2, A3)>& cb, A1 a1, A2 a2, A3 a3) { |
+ loop->PostTask(FROM_HERE, base::Bind(cb, |
+ base::internal::CallbackForward(a1), |
+ base::internal::CallbackForward(a2), |
+ base::internal::CallbackForward(a3))); |
+ } |
+}; |
+ |
+ |
+template <typename A1, typename A2, typename A3, typename A4> |
+struct TrampolineHelper<void(A1, A2, A3, A4)> { |
+ static void Run( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<void(A1, A2, A3, A4)>& cb, A1 a1, A2 a2, A3 a3, |
+ A4 a4) { |
+ loop->PostTask(FROM_HERE, base::Bind(cb, |
+ base::internal::CallbackForward(a1), |
+ base::internal::CallbackForward(a2), |
+ base::internal::CallbackForward(a3), |
+ base::internal::CallbackForward(a4))); |
+ } |
+}; |
+ |
+ |
+template <typename A1, typename A2, typename A3, typename A4, typename A5> |
+struct TrampolineHelper<void(A1, A2, A3, A4, A5)> { |
+ static void Run( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<void(A1, A2, A3, A4, A5)>& cb, A1 a1, A2 a2, A3 a3, |
+ A4 a4, A5 a5) { |
+ loop->PostTask(FROM_HERE, base::Bind(cb, |
+ base::internal::CallbackForward(a1), |
+ base::internal::CallbackForward(a2), |
+ base::internal::CallbackForward(a3), |
+ base::internal::CallbackForward(a4), |
+ base::internal::CallbackForward(a5))); |
+ } |
+}; |
+ |
+ |
+template <typename A1, typename A2, typename A3, typename A4, typename A5, |
+ typename A6> |
+struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6)> { |
+ static void Run( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<void(A1, A2, A3, A4, A5, A6)>& cb, A1 a1, A2 a2, |
+ A3 a3, A4 a4, A5 a5, A6 a6) { |
+ loop->PostTask(FROM_HERE, base::Bind(cb, |
+ base::internal::CallbackForward(a1), |
+ base::internal::CallbackForward(a2), |
+ base::internal::CallbackForward(a3), |
+ base::internal::CallbackForward(a4), |
+ base::internal::CallbackForward(a5), |
+ base::internal::CallbackForward(a6))); |
+ } |
+}; |
+ |
+ |
+template <typename A1, typename A2, typename A3, typename A4, typename A5, |
+ typename A6, typename A7> |
+struct TrampolineHelper<void(A1, A2, A3, A4, A5, A6, A7)> { |
+ static void Run( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<void(A1, A2, A3, A4, A5, A6, A7)>& cb, A1 a1, A2 a2, |
+ A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { |
+ loop->PostTask(FROM_HERE, base::Bind(cb, |
+ base::internal::CallbackForward(a1), |
+ base::internal::CallbackForward(a2), |
+ base::internal::CallbackForward(a3), |
+ base::internal::CallbackForward(a4), |
+ base::internal::CallbackForward(a5), |
+ base::internal::CallbackForward(a6), |
+ base::internal::CallbackForward(a7))); |
+ } |
+}; |
+ |
+ |
+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_ |