Expand base::internal::{Copy,Repeat}Mode into base::Callback
This CL removes base::internal::CopyMode and base::internal::RepeatMode,
and splits base::Callback into base::OnceCallback and base::RepeatingCallback.
These enums are introduced to reduces duplicated implementations of
variants of base::Callback, and for cleaner conversion policy between them.
However, there are only two variants for now, and no plan to increase it to
more than three.
As these parameters makes crash logs and stack traces less readable, it's
nice to have individual classes to these Callback variants.
Bug:
Change-Id: I1f34a882204b92f5018720645b4d04dee194615e
Reviewed-on: https://chromium-review.googlesource.com/636726
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#497826}
CrOS-Libchrome-Original-Commit: d4bb5b7d539bb934156b1c78f7f475e917955c33
diff --git a/base/bind_internal.h b/base/bind_internal.h
index 756f890..c19f759 100644
--- a/base/bind_internal.h
+++ b/base/bind_internal.h
@@ -225,10 +225,24 @@
}
};
-// For Callbacks.
-template <typename R, typename... Args,
- CopyMode copy_mode, RepeatMode repeat_mode>
-struct FunctorTraits<Callback<R(Args...), copy_mode, repeat_mode>> {
+// For OnceCallbacks.
+template <typename R, typename... Args>
+struct FunctorTraits<OnceCallback<R(Args...)>> {
+ using RunType = R(Args...);
+ static constexpr bool is_method = false;
+ static constexpr bool is_nullable = true;
+
+ template <typename CallbackType, typename... RunArgs>
+ static R Invoke(CallbackType&& callback, RunArgs&&... args) {
+ DCHECK(!callback.is_null());
+ return std::forward<CallbackType>(callback).Run(
+ std::forward<RunArgs>(args)...);
+ }
+};
+
+// For RepeatingCallbacks.
+template <typename R, typename... Args>
+struct FunctorTraits<RepeatingCallback<R(Args...)>> {
using RunType = R(Args...);
static constexpr bool is_method = false;
static constexpr bool is_nullable = true;