summaryrefslogtreecommitdiffstats
path: root/base/bind.h
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-30 09:09:34 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-30 09:09:34 +0000
commitcea20fe4e5ee8e0b81c9d4f0ff7750cb8ef64aef (patch)
tree48ce1068ad3c94af442bdb9b373329ff3300ef5f /base/bind.h
parentf3f0da43dfff66771f894b48c45c8c567062244f (diff)
downloadchromium_src-cea20fe4e5ee8e0b81c9d4f0ff7750cb8ef64aef.zip
chromium_src-cea20fe4e5ee8e0b81c9d4f0ff7750cb8ef64aef.tar.gz
chromium_src-cea20fe4e5ee8e0b81c9d4f0ff7750cb8ef64aef.tar.bz2
Allow Bind() to take a Callback<> and bind all its free parameters.
Basically, turns base::Callback<void(...)> to base::Closure. It turns out there are a number of use caess where an API takes a callback, and then wants to invoke the Callback on another thread. This piece of syntactic sugar removes the need for custom helper functions. This isn't quite full currying, however it is much simpler to implement. BUG=87287 TEST=none Review URL: http://codereview.chromium.org/8073012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103446 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/bind.h')
-rw-r--r--base/bind.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/base/bind.h b/base/bind.h
index cd9eb19..f023308e 100644
--- a/base/bind.h
+++ b/base/bind.h
@@ -3,6 +3,7 @@
// DO NOT EDIT BY HAND!!!
+
// Copyright (c) 2011 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.
@@ -94,6 +95,51 @@ Bind(Sig f, const P1& p1, const P2& p2, const P3& p3, const P4& p4,
f, p1, p2, p3, p4, p5, p6));
}
+// Specializations to allow binding all the free arguments in a
+// pre-existing base::Callback<>. This does not give full support for
+// currying, but is significantly simpler and addresses the use case
+// where a base::Callback<> needs to be invoked on another context/thread.
+template <typename Sig, typename P1>
+base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1) {
+ return base::Bind(&internal::BindMoreFunc1<Sig, P1>, callback, p1);
+}
+
+template <typename Sig, typename P1, typename P2>
+base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1,
+ const P2& p2) {
+ return base::Bind(&internal::BindMoreFunc2<Sig, P1, P2>, callback, p1, p2);
+}
+
+template <typename Sig, typename P1, typename P2, typename P3>
+base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1,
+ const P2& p2, const P3& p3) {
+ return base::Bind(&internal::BindMoreFunc3<Sig, P1, P2, P3>, callback, p1,
+ p2, p3);
+}
+
+template <typename Sig, typename P1, typename P2, typename P3, typename P4>
+base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1,
+ const P2& p2, const P3& p3, const P4& p4) {
+ return base::Bind(&internal::BindMoreFunc4<Sig, P1, P2, P3, P4>, callback,
+ p1, p2, p3, p4);
+}
+
+template <typename Sig, typename P1, typename P2, typename P3, typename P4,
+ typename P5>
+base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1,
+ const P2& p2, const P3& p3, const P4& p4, const P5& p5) {
+ return base::Bind(&internal::BindMoreFunc5<Sig, P1, P2, P3, P4, P5>,
+ callback, p1, p2, p3, p4, p5);
+}
+
+template <typename Sig, typename P1, typename P2, typename P3, typename P4,
+ typename P5, typename P6>
+base::Closure Bind(const base::Callback<Sig>& callback, const P1& p1,
+ const P2& p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6) {
+ return base::Bind(&internal::BindMoreFunc6<Sig, P1, P2, P3, P4, P5, P6>,
+ callback, p1, p2, p3, p4, p5, p6);
+}
+
} // namespace base
#endif // BASE_BIND_H_