| Index: base/callback_internal.h
|
| diff --git a/base/callback_internal.h b/base/callback_internal.h
|
| index 0fe0b2d9e198716690365dc8d6a4c82508a79188..dfc6b3a19ed324a0e0951051ace039b0596f7412 100644
|
| --- a/base/callback_internal.h
|
| +++ b/base/callback_internal.h
|
| @@ -31,9 +31,14 @@ class CallbackBase;
|
| // of bloat. Its only task is to call the destructor which can be done with a
|
| // function pointer.
|
| class BindStateBase {
|
| + public:
|
| + using InvokeFuncStorage = void(*)();
|
| +
|
| protected:
|
| - explicit BindStateBase(void (*destructor)(BindStateBase*))
|
| - : ref_count_(0), destructor_(destructor) {}
|
| + BindStateBase(InvokeFuncStorage polymorphic_invoke,
|
| + void (*destructor)(BindStateBase*))
|
| + : polymorphic_invoke_(polymorphic_invoke),
|
| + ref_count_(0), destructor_(destructor) {}
|
| ~BindStateBase() = default;
|
|
|
| private:
|
| @@ -44,6 +49,12 @@ class BindStateBase {
|
| void AddRef();
|
| void Release();
|
|
|
| + // In C++, it is safe to cast function pointers to function pointers of
|
| + // another type. It is not okay to use void*. We create a InvokeFuncStorage
|
| + // that that can store our function pointer, and then cast it back to
|
| + // the original type on usage.
|
| + InvokeFuncStorage polymorphic_invoke_;
|
| +
|
| AtomicRefCount ref_count_;
|
|
|
| // Pointer to a function that will properly destroy |this|.
|
| @@ -70,28 +81,25 @@ class BASE_EXPORT CallbackBase<CopyMode::MoveOnly> {
|
| void Reset();
|
|
|
| protected:
|
| - // In C++, it is safe to cast function pointers to function pointers of
|
| - // another type. It is not okay to use void*. We create a InvokeFuncStorage
|
| - // that that can store our function pointer, and then cast it back to
|
| - // the original type on usage.
|
| - using InvokeFuncStorage = void(*)();
|
| + using InvokeFuncStorage = BindStateBase::InvokeFuncStorage;
|
|
|
| // Returns true if this callback equals |other|. |other| may be null.
|
| bool EqualsInternal(const CallbackBase& other) const;
|
|
|
| // Allow initializing of |bind_state_| via the constructor to avoid default
|
| - // initialization of the scoped_refptr. We do not also initialize
|
| - // |polymorphic_invoke_| here because doing a normal assignment in the
|
| - // derived Callback templates makes for much nicer compiler errors.
|
| + // initialization of the scoped_refptr.
|
| explicit CallbackBase(BindStateBase* bind_state);
|
|
|
| + InvokeFuncStorage polymorphic_invoke() const {
|
| + return bind_state_->polymorphic_invoke_;
|
| + }
|
| +
|
| // Force the destructor to be instantiated inside this translation unit so
|
| // that our subclasses will not get inlined versions. Avoids more template
|
| // bloat.
|
| ~CallbackBase();
|
|
|
| scoped_refptr<BindStateBase> bind_state_;
|
| - InvokeFuncStorage polymorphic_invoke_ = nullptr;
|
| };
|
|
|
| // CallbackBase<Copyable> is a direct base class of Copyable Callbacks.
|
|
|