summaryrefslogtreecommitdiffstats
path: root/chromium/base/bind_internal.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-06 12:48:11 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:33:43 +0000
commit7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (patch)
treefa14ba0ca8d2683ba2efdabd246dc9b18a1229c6 /chromium/base/bind_internal.h
parent79b4f909db1049fca459c07cca55af56a9b54fe3 (diff)
BASELINE: Update Chromium to 84.0.4147.141
Change-Id: Ib85eb4cfa1cbe2b2b81e5022c8cad5c493969535 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/base/bind_internal.h')
-rw-r--r--chromium/base/bind_internal.h34
1 files changed, 31 insertions, 3 deletions
diff --git a/chromium/base/bind_internal.h b/chromium/base/bind_internal.h
index cb56382055f..d9a6a23a5c2 100644
--- a/chromium/base/bind_internal.h
+++ b/chromium/base/bind_internal.h
@@ -16,6 +16,7 @@
#include "base/bind.h"
#include "base/callback_internal.h"
#include "base/compiler_specific.h"
+#include "base/logging.h"
#include "base/memory/raw_scoped_refptr_mismatch_checker.h"
#include "base/memory/weak_ptr.h"
#include "base/template_util.h"
@@ -369,6 +370,7 @@ struct FunctorTraits<Functor,
using RunType = ExtractCallableRunType<Functor>;
static constexpr bool is_method = false;
static constexpr bool is_nullable = false;
+ static constexpr bool is_callback = false;
template <typename RunFunctor, typename... RunArgs>
static ExtractReturnType<RunType> Invoke(RunFunctor&& functor,
@@ -383,6 +385,7 @@ struct FunctorTraits<R (*)(Args...)> {
using RunType = R(Args...);
static constexpr bool is_method = false;
static constexpr bool is_nullable = true;
+ static constexpr bool is_callback = false;
template <typename Function, typename... RunArgs>
static R Invoke(Function&& function, RunArgs&&... args) {
@@ -398,6 +401,7 @@ struct FunctorTraits<R(__stdcall*)(Args...)> {
using RunType = R(Args...);
static constexpr bool is_method = false;
static constexpr bool is_nullable = true;
+ static constexpr bool is_callback = false;
template <typename... RunArgs>
static R Invoke(R(__stdcall* function)(Args...), RunArgs&&... args) {
@@ -411,6 +415,7 @@ struct FunctorTraits<R(__fastcall*)(Args...)> {
using RunType = R(Args...);
static constexpr bool is_method = false;
static constexpr bool is_nullable = true;
+ static constexpr bool is_callback = false;
template <typename... RunArgs>
static R Invoke(R(__fastcall* function)(Args...), RunArgs&&... args) {
@@ -440,6 +445,7 @@ struct FunctorTraits<R (^)(Args...)> {
using RunType = R(Args...);
static constexpr bool is_method = false;
static constexpr bool is_nullable = true;
+ static constexpr bool is_callback = false;
template <typename BlockType, typename... RunArgs>
static R Invoke(BlockType&& block, RunArgs&&... args) {
@@ -461,6 +467,7 @@ struct FunctorTraits<base::mac::ScopedBlock<R (^)(Args...)>> {
using RunType = R(Args...);
static constexpr bool is_method = false;
static constexpr bool is_nullable = true;
+ static constexpr bool is_callback = false;
template <typename BlockType, typename... RunArgs>
static R Invoke(BlockType&& block, RunArgs&&... args) {
@@ -481,6 +488,7 @@ struct FunctorTraits<R (Receiver::*)(Args...)> {
using RunType = R(Receiver*, Args...);
static constexpr bool is_method = true;
static constexpr bool is_nullable = true;
+ static constexpr bool is_callback = false;
template <typename Method, typename ReceiverPtr, typename... RunArgs>
static R Invoke(Method method,
@@ -496,6 +504,7 @@ struct FunctorTraits<R (Receiver::*)(Args...) const> {
using RunType = R(const Receiver*, Args...);
static constexpr bool is_method = true;
static constexpr bool is_nullable = true;
+ static constexpr bool is_callback = false;
template <typename Method, typename ReceiverPtr, typename... RunArgs>
static R Invoke(Method method,
@@ -513,6 +522,7 @@ struct FunctorTraits<R (__stdcall Receiver::*)(Args...)> {
using RunType = R(Receiver*, Args...);
static constexpr bool is_method = true;
static constexpr bool is_nullable = true;
+ static constexpr bool is_callback = false;
template <typename Method, typename ReceiverPtr, typename... RunArgs>
static R Invoke(Method method,
@@ -528,6 +538,7 @@ struct FunctorTraits<R (__stdcall Receiver::*)(Args...) const> {
using RunType = R(const Receiver*, Args...);
static constexpr bool is_method = true;
static constexpr bool is_nullable = true;
+ static constexpr bool is_callback = false;
template <typename Method, typename ReceiverPtr, typename... RunArgs>
static R Invoke(Method method,
@@ -577,6 +588,7 @@ struct FunctorTraits<OnceCallback<R(Args...)>> {
using RunType = R(Args...);
static constexpr bool is_method = false;
static constexpr bool is_nullable = true;
+ static constexpr bool is_callback = true;
template <typename CallbackType, typename... RunArgs>
static R Invoke(CallbackType&& callback, RunArgs&&... args) {
@@ -592,6 +604,7 @@ struct FunctorTraits<RepeatingCallback<R(Args...)>> {
using RunType = R(Args...);
static constexpr bool is_method = false;
static constexpr bool is_nullable = true;
+ static constexpr bool is_callback = true;
template <typename CallbackType, typename... RunArgs>
static R Invoke(CallbackType&& callback, RunArgs&&... args) {
@@ -829,7 +842,6 @@ struct BindState final : BindStateBase {
using IsCancellable = bool_constant<
CallbackCancellationTraits<Functor,
std::tuple<BoundArgs...>>::is_cancellable>;
-
template <typename ForwardFunctor, typename... ForwardBoundArgs>
static BindState* Create(BindStateBase::InvokeFuncStorage invoke_func,
ForwardFunctor&& functor,
@@ -850,6 +862,9 @@ struct BindState final : BindStateBase {
std::tuple<BoundArgs...> bound_args_;
private:
+ static constexpr bool is_nested_callback =
+ internal::MakeFunctorTraits<Functor>::is_callback;
+
template <typename ForwardFunctor, typename... ForwardBoundArgs>
explicit BindState(std::true_type,
BindStateBase::InvokeFuncStorage invoke_func,
@@ -860,7 +875,15 @@ struct BindState final : BindStateBase {
&QueryCancellationTraits<BindState>),
functor_(std::forward<ForwardFunctor>(functor)),
bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) {
- DCHECK(!IsNull(functor_));
+ // We check the validity of nested callbacks (e.g., Bind(callback, ...)) in
+ // release builds to avoid null pointers from ending up in posted tasks,
+ // causing hard-to-diagnose crashes. Ideally we'd do this for all functors
+ // here, but that would have a large binary size impact.
+ if (is_nested_callback) {
+ CHECK(!IsNull(functor_));
+ } else {
+ DCHECK(!IsNull(functor_));
+ }
}
template <typename ForwardFunctor, typename... ForwardBoundArgs>
@@ -871,7 +894,12 @@ struct BindState final : BindStateBase {
: BindStateBase(invoke_func, &Destroy),
functor_(std::forward<ForwardFunctor>(functor)),
bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) {
- DCHECK(!IsNull(functor_));
+ // See above for CHECK/DCHECK rationale.
+ if (is_nested_callback) {
+ CHECK(!IsNull(functor_));
+ } else {
+ DCHECK(!IsNull(functor_));
+ }
}
~BindState() = default;