Index: base/bind.h |
diff --git a/base/bind.h b/base/bind.h |
index 86f624e49c80ae376112a73f88ef007e44d7342c..ec707a0618f288431e373ffe56b3813c409754a3 100644 |
--- a/base/bind.h |
+++ b/base/bind.h |
@@ -23,15 +23,38 @@ |
// terms and concepts. |
namespace base { |
+namespace internal { |
+// Bind as OnceCallback. |
template <typename Functor, typename... Args> |
-inline base::Callback<MakeUnboundRunType<Functor, Args...>> Bind( |
- Functor&& functor, |
- Args&&... args) { |
+inline OnceCallback<MakeUnboundRunType<Functor, Args...>> |
+BindOnce(Functor&& functor, Args&&... args) { |
using BindState = internal::MakeBindStateType<Functor, Args...>; |
using UnboundRunType = MakeUnboundRunType<Functor, Args...>; |
using Invoker = internal::Invoker<BindState, UnboundRunType>; |
- using CallbackType = Callback<UnboundRunType>; |
+ using CallbackType = OnceCallback<UnboundRunType>; |
+ |
+ // Store the invoke func into PolymorphicInvoke before casting it to |
+ // InvokeFuncStorage, so that we can ensure its type matches to |
+ // PolymorphicInvoke, to which CallbackType will cast back. |
+ using PolymorphicInvoke = typename CallbackType::PolymorphicInvoke; |
+ PolymorphicInvoke invoke_func = &Invoker::RunOnce; |
+ |
+ using InvokeFuncStorage = internal::BindStateBase::InvokeFuncStorage; |
+ return CallbackType(new BindState( |
+ reinterpret_cast<InvokeFuncStorage>(invoke_func), |
+ std::forward<Functor>(functor), |
+ std::forward<Args>(args)...)); |
+} |
+ |
+// Bind as RepeatingCallback. |
+template <typename Functor, typename... Args> |
+inline RepeatingCallback<MakeUnboundRunType<Functor, Args...>> |
+BindRepeating(Functor&& functor, Args&&... args) { |
+ using BindState = internal::MakeBindStateType<Functor, Args...>; |
+ using UnboundRunType = MakeUnboundRunType<Functor, Args...>; |
+ using Invoker = internal::Invoker<BindState, UnboundRunType>; |
+ using CallbackType = RepeatingCallback<UnboundRunType>; |
// Store the invoke func into PolymorphicInvoke before casting it to |
// InvokeFuncStorage, so that we can ensure its type matches to |
@@ -46,6 +69,18 @@ inline base::Callback<MakeUnboundRunType<Functor, Args...>> Bind( |
std::forward<Args>(args)...)); |
} |
+} // namespace internal |
+ |
+// Unannotated Bind. |
+// TODO(tzik): Deprecate this and migrate to OnceCallback and |
+// RepeatingCallback, once they get ready. |
+template <typename Functor, typename... Args> |
+inline Callback<MakeUnboundRunType<Functor, Args...>> |
+Bind(Functor&& functor, Args&&... args) { |
+ return internal::BindRepeating(std::forward<Functor>(functor), |
+ std::forward<Args>(args)...); |
+} |
+ |
} // namespace base |
#endif // BASE_BIND_H_ |