summaryrefslogtreecommitdiffstats
path: root/chromium/base/bind_internal.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-08-01 12:59:39 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-08-04 12:40:43 +0000
commit28b1110370900897ab652cb420c371fab8857ad4 (patch)
tree41b32127d23b0df4f2add2a27e12dc87bddb260e /chromium/base/bind_internal.h
parent399c965b6064c440ddcf4015f5f8e9d131c7a0a6 (diff)
BASELINE: Update Chromium to 53.0.2785.41
Also adds a few extra files for extensions. Change-Id: Iccdd55d98660903331cf8b7b29188da781830af4 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/base/bind_internal.h')
-rw-r--r--chromium/base/bind_internal.h162
1 files changed, 78 insertions, 84 deletions
diff --git a/chromium/base/bind_internal.h b/chromium/base/bind_internal.h
index 6e0a425eab0..c7d6c3b4adc 100644
--- a/chromium/base/bind_internal.h
+++ b/chromium/base/bind_internal.h
@@ -7,6 +7,7 @@
#include <stddef.h>
+#include <tuple>
#include <type_traits>
#include "base/bind_helpers.h"
@@ -63,22 +64,6 @@ namespace internal {
// into the Bind() system, doing most of the type resolution.
// There are ARITY BindState types.
-// HasNonConstReferenceParam selects true_type when any of the parameters in
-// |Sig| is a non-const reference.
-// Implementation note: This non-specialized case handles zero-arity case only.
-// Non-zero-arity cases should be handled by the specialization below.
-template <typename List>
-struct HasNonConstReferenceItem : std::false_type {};
-
-// Implementation note: Select true_type if the first parameter is a non-const
-// reference. Otherwise, skip the first parameter and check rest of parameters
-// recursively.
-template <typename T, typename... Args>
-struct HasNonConstReferenceItem<TypeList<T, Args...>>
- : std::conditional<is_non_const_reference<T>::value,
- std::true_type,
- HasNonConstReferenceItem<TypeList<Args...>>>::type {};
-
// HasRefCountedTypeAsRawPtr selects true_type when any of the |Args| is a raw
// pointer to a RefCounted type.
// Implementation note: This non-specialized case handles zero-arity case only.
@@ -155,7 +140,7 @@ class RunnableAdapter<R(*)(Args...)> {
}
template <typename... RunArgs>
- R Run(RunArgs&&... args) {
+ R Run(RunArgs&&... args) const {
return function_(std::forward<RunArgs>(args)...);
}
@@ -177,7 +162,7 @@ class RunnableAdapter<R(T::*)(Args...)> {
}
template <typename Receiver, typename... RunArgs>
- R Run(Receiver&& receiver_ptr, RunArgs&&... args) {
+ R Run(Receiver&& receiver_ptr, RunArgs&&... args) const {
// Clang skips CV qualifier check on a method pointer invocation when the
// receiver is a subclass. Store the receiver into a const reference to
// T to ensure the CV check works.
@@ -202,7 +187,7 @@ class RunnableAdapter<R(T::*)(Args...) const> {
}
template <typename Receiver, typename... RunArgs>
- R Run(Receiver&& receiver_ptr, RunArgs&&... args) {
+ R Run(Receiver&& receiver_ptr, RunArgs&&... args) const {
// Clang skips CV qualifier check on a method pointer invocation when the
// receiver is a subclass. Store the receiver into a unqualified reference
// to T to ensure the CV check works.
@@ -293,42 +278,43 @@ MakeRunnable(const Callback<T>& t) {
//
// WeakCalls similarly need special syntax that is applied to the first
// argument to check if they should no-op themselves.
-template <bool IsWeakCall, typename ReturnType, typename Runnable>
+template <bool is_weak_call, typename ReturnType>
struct InvokeHelper;
-template <typename ReturnType, typename Runnable>
-struct InvokeHelper<false, ReturnType, Runnable> {
- template <typename... RunArgs>
- static ReturnType MakeItSo(Runnable runnable, RunArgs&&... args) {
- return runnable.Run(std::forward<RunArgs>(args)...);
+template <typename ReturnType>
+struct InvokeHelper<false, ReturnType> {
+ template <typename Runnable, typename... RunArgs>
+ static inline ReturnType MakeItSo(Runnable&& runnable, RunArgs&&... args) {
+ return std::forward<Runnable>(runnable).Run(std::forward<RunArgs>(args)...);
}
};
-template <typename Runnable>
-struct InvokeHelper<false, void, Runnable> {
- template <typename... RunArgs>
- static void MakeItSo(Runnable runnable, RunArgs&&... args) {
- runnable.Run(std::forward<RunArgs>(args)...);
+template <>
+struct InvokeHelper<false, void> {
+ template <typename Runnable, typename... RunArgs>
+ static inline void MakeItSo(Runnable&& runnable, RunArgs&&... args) {
+ std::forward<Runnable>(runnable).Run(std::forward<RunArgs>(args)...);
}
};
-template <typename Runnable>
-struct InvokeHelper<true, void, Runnable> {
- template <typename BoundWeakPtr, typename... RunArgs>
- static void MakeItSo(Runnable runnable,
- BoundWeakPtr weak_ptr,
+template <>
+struct InvokeHelper<true, void> {
+ template <typename Runnable, typename BoundWeakPtr, typename... RunArgs>
+ static void MakeItSo(Runnable&& runnable,
+ BoundWeakPtr&& weak_ptr,
RunArgs&&... args) {
- if (!weak_ptr.get()) {
+ if (!weak_ptr) {
return;
}
- runnable.Run(weak_ptr.get(), std::forward<RunArgs>(args)...);
+ std::forward<Runnable>(runnable).Run(
+ std::forward<BoundWeakPtr>(weak_ptr), std::forward<RunArgs>(args)...);
}
};
#if !defined(_MSC_VER)
-template <typename ReturnType, typename Runnable>
-struct InvokeHelper<true, ReturnType, Runnable> {
+template <typename ReturnType>
+struct InvokeHelper<true, ReturnType> {
// WeakCalls are only supported for functions with a void return type.
// Otherwise, the function result would be undefined if the the WeakPtr<>
// is invalidated.
@@ -341,26 +327,42 @@ struct InvokeHelper<true, ReturnType, Runnable> {
// Invoker<>
//
// See description at the top of the file.
-template <typename BoundIndices, typename StorageType,
- typename InvokeHelperType, typename UnboundForwardRunType>
+template <typename StorageType, typename UnboundRunType>
struct Invoker;
-template <size_t... bound_indices,
- typename StorageType,
- typename InvokeHelperType,
- typename R,
- typename... UnboundArgs>
-struct Invoker<IndexSequence<bound_indices...>,
- StorageType,
- InvokeHelperType,
- R(UnboundArgs...)> {
+template <typename StorageType, typename R, typename... UnboundArgs>
+struct Invoker<StorageType, R(UnboundArgs...)> {
static R Run(BindStateBase* base, UnboundArgs&&... unbound_args) {
- StorageType* storage = static_cast<StorageType*>(base);
// Local references to make debugger stepping easier. If in a debugger,
// you really want to warp ahead and step through the
// InvokeHelper<>::MakeItSo() call below.
- return InvokeHelperType::MakeItSo(
- storage->runnable_, Unwrap(get<bound_indices>(storage->bound_args_))...,
+ const StorageType* storage = static_cast<StorageType*>(base);
+ static constexpr size_t num_bound_args =
+ std::tuple_size<decltype(storage->bound_args_)>::value;
+ return RunImpl(storage->runnable_,
+ storage->bound_args_,
+ MakeIndexSequence<num_bound_args>(),
+ std::forward<UnboundArgs>(unbound_args)...);
+ }
+
+ template <typename Runnable, typename BoundArgsTuple, size_t... indices>
+ static inline R RunImpl(Runnable&& runnable,
+ BoundArgsTuple&& bound,
+ IndexSequence<indices...>,
+ UnboundArgs&&... unbound_args) {
+ static constexpr bool is_method =
+ HasIsMethodTag<typename std::decay<Runnable>::type>::value;
+
+ using DecayedArgsTuple = typename std::decay<BoundArgsTuple>::type;
+ static constexpr bool is_weak_call =
+ IsWeakMethod<is_method,
+ typename std::tuple_element<
+ indices,
+ DecayedArgsTuple>::type...>::value;
+
+ return InvokeHelper<is_weak_call, R>::MakeItSo(
+ std::forward<Runnable>(runnable),
+ Unwrap(std::get<indices>(std::forward<BoundArgsTuple>(bound)))...,
std::forward<UnboundArgs>(unbound_args)...);
}
};
@@ -384,51 +386,36 @@ template <bool is_method, typename... BoundArgs>
using MakeArgsStorage = typename MakeArgsStorageImpl<
is_method, typename std::decay<BoundArgs>::type...>::Type;
+// Used to implement MakeUnboundRunType.
+template <typename Functor, typename... BoundArgs>
+struct MakeUnboundRunTypeImpl {
+ using RunType = typename FunctorTraits<Functor>::RunType;
+ using ReturnType = ExtractReturnType<RunType>;
+ using Args = ExtractArgs<RunType>;
+ using UnboundArgs = DropTypeListItem<sizeof...(BoundArgs), Args>;
+ using Type = MakeFunctionType<ReturnType, UnboundArgs>;
+};
+
// BindState<>
//
// This stores all the state passed into Bind() and is also where most
// of the template resolution magic occurs.
//
// Runnable is the functor we are binding arguments to.
-// RunType is type of the Run() function that the Invoker<> should use.
-// Normally, this is the same as the RunType of the Runnable, but it can
-// be different if an adapter like IgnoreResult() has been used.
//
// BoundArgs contains the storage type for all the bound arguments.
-template <typename Runnable, typename RunType, typename... BoundArgs>
-struct BindState;
-
-template <typename Runnable,
- typename R,
- typename... Args,
- typename... BoundArgs>
-struct BindState<Runnable, R(Args...), BoundArgs...> final
- : public BindStateBase {
+template <typename Runnable, typename... BoundArgs>
+struct BindState final : public BindStateBase {
private:
- using StorageType = BindState<Runnable, R(Args...), BoundArgs...>;
- using RunnableType = Runnable;
-
- enum { is_method = HasIsMethodTag<Runnable>::value };
-
- // true_type if Runnable is a method invocation and the first bound argument
- // is a WeakPtr.
- using IsWeakCall =
- IsWeakMethod<is_method, typename std::decay<BoundArgs>::type...>;
+ using RunnableType = typename std::decay<Runnable>::type;
- using BoundIndices = MakeIndexSequence<sizeof...(BoundArgs)>;
- using InvokeHelperType = InvokeHelper<IsWeakCall::value, R, Runnable>;
-
- using UnboundArgs = DropTypeListItem<sizeof...(BoundArgs), TypeList<Args...>>;
+ static constexpr bool is_method = HasIsMethodTag<RunnableType>::value;
public:
- using UnboundRunType = MakeFunctionType<R, UnboundArgs>;
- using InvokerType =
- Invoker<BoundIndices, StorageType, InvokeHelperType, UnboundRunType>;
-
template <typename... ForwardArgs>
- BindState(const Runnable& runnable, ForwardArgs&&... bound_args)
+ explicit BindState(RunnableType runnable, ForwardArgs&&... bound_args)
: BindStateBase(&Destroy),
- runnable_(runnable),
+ runnable_(std::move(runnable)),
bound_args_(std::forward<ForwardArgs>(bound_args)...) {}
RunnableType runnable_;
@@ -443,6 +430,13 @@ struct BindState<Runnable, R(Args...), BoundArgs...> final
};
} // namespace internal
+
+// Returns a RunType of bound functor.
+// E.g. MakeUnboundRunType<R(A, B, C), A, B> is evaluated to R(C).
+template <typename Functor, typename... BoundArgs>
+using MakeUnboundRunType =
+ typename internal::MakeUnboundRunTypeImpl<Functor, BoundArgs...>::Type;
+
} // namespace base
#endif // BASE_BIND_INTERNAL_H_