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

Unified Diff: media/base/bind_to_loop.h.pump

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
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..97ddbf14ec3378bc21dfb9b6a120b7455a452537
--- /dev/null
+++ b/media/base/bind_to_loop.h.pump
@@ -0,0 +1,72 @@
+$$ 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/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 {
+
+$range ARITY 0..MAX_ARITY
+$for ARITY [[
+$range ARG 1..ARITY
+
+$if ARITY == 0 [[
+
+static void TrampolineRun(
+ scoped_refptr<base::MessageLoopProxy> loop, const base::Closure& cb) {
+ 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);
+}
+
+]] $else [[
+
+template<$for ARG , [[typename A$(ARG)]]>
+static void TrampolineRun(
+ scoped_refptr<base::MessageLoopProxy> loop,
+ const base::Callback<void($for ARG , [[A$(ARG)]])>& cb,
+ $for ARG , [[A$(ARG) a$(ARG)]]) {
+ loop->PostTask(FROM_HERE, base::Bind(cb, $for ARG , [[a$(ARG)]]));
+}
+
+template<$for ARG , [[typename A$(ARG)]]>
+static base::Callback<void($for ARG , [[A$(ARG)]])> BindToLoop(
+ scoped_refptr<base::MessageLoopProxy> loop,
+ const base::Callback<void($for ARG , [[A$(ARG)]])>& cb) {
+ return base::Bind(&TrampolineRun<$for ARG , [[A$(ARG)]]>, loop, cb);
+}
+
+]]
+
+]] $$ for ARITY
+
+} // namespace media
+
+#endif // MEDIA_BASE_BIND_TO_LOOP_H_
« media/base/bind_to_loop.h ('K') | « media/base/bind_to_loop.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698