Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Unified Diff: media/base/bind_to_loop.h

Issue 10855188: media::BindToLoop() is born, with example uses to slim down WebMediaPlayerProxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: now with macro Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/base/bind_to_loop.h.pump » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5de025ed2fc5f2eec56b0d83185484552adb1fc5
--- /dev/null
+++ b/media/base/bind_to_loop.h
@@ -0,0 +1,149 @@
+// 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.
Ami GONE FROM CHROMIUM 2012/08/16 20:25:53 Now with tests!
+// 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/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)));
+
+namespace media {
+
+static void TrampolineRun(
awong 2012/08/16 17:19:21 Should these be in an internal namespace? Also, s
Ami GONE FROM CHROMIUM 2012/08/16 20:25:53 The "static"s are leftover from prototyping. Gone
Ami GONE FROM CHROMIUM 2012/08/16 20:25:53 You mean put TrampolineRun in media::internal but
+ scoped_refptr<base::MessageLoopProxy> loop, const base::Closure& cb) {
awong 2012/08/16 17:19:21 Can |loop| be a const ref?
Ami GONE FROM CHROMIUM 2012/08/16 20:25:53 Done.
+ loop->PostTask(FROM_HERE, base::Bind(cb));
+}
+
+static base::Closure BindToLoop(
+ scoped_refptr<base::MessageLoopProxy> loop, const base::Closure& cb) {
+ return base::Bind(&TrampolineRun, loop, cb);
+}
+
+template<typename A1>
+static void TrampolineRun(
+ scoped_refptr<base::MessageLoopProxy> loop,
+ const base::Callback<void(A1)>& cb,
+ A1 a1) {
awong 2012/08/16 17:19:21 We're not unwrapping A1 into a ForwardType like Ca
Ami GONE FROM CHROMIUM 2012/08/16 20:25:53 I'd rather things worked across the board, and I w
+ loop->PostTask(FROM_HERE, base::Bind(cb, a1));
+}
+
+template<typename A1>
+static base::Callback<void(A1)> BindToLoop(
+ scoped_refptr<base::MessageLoopProxy> loop,
+ const base::Callback<void(A1)>& cb) {
+ return base::Bind(&TrampolineRun<A1>, loop, cb);
+}
+
+template<typename A1, typename A2>
+static void TrampolineRun(
+ scoped_refptr<base::MessageLoopProxy> loop,
+ const base::Callback<void(A1, A2)>& cb,
+ A1 a1, A2 a2) {
+ loop->PostTask(FROM_HERE, base::Bind(cb, a1, a2));
+}
+
+template<typename A1, typename A2>
+static base::Callback<void(A1, A2)> BindToLoop(
+ scoped_refptr<base::MessageLoopProxy> loop,
+ const base::Callback<void(A1, A2)>& cb) {
+ return base::Bind(&TrampolineRun<A1, A2>, loop, cb);
+}
+
+template<typename A1, typename A2, typename A3>
+static void TrampolineRun(
awong 2012/08/16 17:19:21 If you use the funciton-signature trick to make Tr
Ami GONE FROM CHROMIUM 2012/08/16 20:25:53 Nice, done.
+ 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, a1, a2, a3));
+}
+
+template<typename A1, typename A2, typename A3>
+static base::Callback<void(A1, A2, A3)> BindToLoop(
+ scoped_refptr<base::MessageLoopProxy> loop,
+ const base::Callback<void(A1, A2, A3)>& cb) {
+ return base::Bind(&TrampolineRun<A1, A2, A3>, loop, cb);
+}
+
+template<typename A1, typename A2, typename A3, typename A4>
+static void TrampolineRun(
+ 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, a1, a2, a3, a4));
+}
+
+template<typename A1, typename A2, typename A3, typename A4>
+static base::Callback<void(A1, A2, A3, A4)> BindToLoop(
+ scoped_refptr<base::MessageLoopProxy> loop,
+ const base::Callback<void(A1, A2, A3, A4)>& cb) {
+ return base::Bind(&TrampolineRun<A1, A2, A3, A4>, loop, cb);
+}
+
+template<typename A1, typename A2, typename A3, typename A4, typename A5>
+static void TrampolineRun(
+ 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, a1, a2, a3, a4, a5));
+}
+
+template<typename A1, typename A2, typename A3, typename A4, typename A5>
+static base::Callback<void(A1, A2, A3, A4, A5)> BindToLoop(
+ scoped_refptr<base::MessageLoopProxy> loop,
+ const base::Callback<void(A1, A2, A3, A4, A5)>& cb) {
+ return base::Bind(&TrampolineRun<A1, A2, A3, A4, A5>, loop, cb);
+}
+
+template<typename A1, typename A2, typename A3, typename A4, typename A5,
+ typename A6>
+static void TrampolineRun(
+ 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, a1, a2, a3, a4, a5, a6));
+}
+
+template<typename A1, typename A2, typename A3, typename A4, typename A5,
+ typename A6>
+static base::Callback<void(A1, A2, A3, A4, A5, A6)> BindToLoop(
+ scoped_refptr<base::MessageLoopProxy> loop,
+ const base::Callback<void(A1, A2, A3, A4, A5, A6)>& cb) {
+ return base::Bind(&TrampolineRun<A1, A2, A3, A4, A5, A6>, loop, cb);
+}
+
+template<typename A1, typename A2, typename A3, typename A4, typename A5,
+ typename A6, typename A7>
+static void TrampolineRun(
+ 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, a1, a2, a3, a4, a5, a6, a7));
+}
+
+template<typename A1, typename A2, typename A3, typename A4, typename A5,
+ typename A6, typename A7>
+static base::Callback<void(A1, A2, A3, A4, A5, A6, A7)> BindToLoop(
+ scoped_refptr<base::MessageLoopProxy> loop,
+ const base::Callback<void(A1, A2, A3, A4, A5, A6, A7)>& cb) {
+ return base::Bind(&TrampolineRun<A1, A2, A3, A4, A5, A6, A7>, loop, cb);
+}
+
+} // namespace media
+
+#endif // MEDIA_BASE_BIND_TO_LOOP_H_
« no previous file with comments | « no previous file | media/base/bind_to_loop.h.pump » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698