Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Unified Diff: base/callback_internal.h

Issue 1699773002: Extend base::Callback to have a move-only variant (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: msvc work around Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/callback_internal.h
diff --git a/base/callback_internal.h b/base/callback_internal.h
index 3e8ee82e4f246c5a875ba97d5ae219097e745f19..fbeac185a1037d163d6d2745bc7d330f6aea0135 100644
--- a/base/callback_internal.h
+++ b/base/callback_internal.h
@@ -22,7 +22,7 @@
namespace base {
namespace internal {
-class CallbackBase;
+class MoveOnlyCallbackBase;
// BindStateBase is used to provide an opaque handle that the Callback
// class can use to represent a function object with bound arguments. It
@@ -43,7 +43,7 @@ class BindStateBase {
private:
friend class scoped_refptr<BindStateBase>;
- friend class CallbackBase;
+ friend class MoveOnlyCallbackBase;
void AddRef();
void Release();
@@ -58,10 +58,12 @@ class BindStateBase {
// Holds the Callback methods that don't require specialization to reduce
// template bloat.
-class BASE_EXPORT CallbackBase {
+// MoveOnlyCallbackBase is a direct base class of MoveOnly callbacks, and
+// CopyableCallbackBase uses MoveOnlyCallbackBase for its implementation.
+class BASE_EXPORT MoveOnlyCallbackBase {
public:
- CallbackBase(const CallbackBase& c);
- CallbackBase& operator=(const CallbackBase& c);
+ MoveOnlyCallbackBase(MoveOnlyCallbackBase&& c);
+ MoveOnlyCallbackBase& operator=(MoveOnlyCallbackBase&& c);
// Returns true if Callback is null (doesn't refer to anything).
bool is_null() const { return bind_state_.get() == NULL; }
@@ -77,21 +79,31 @@ class BASE_EXPORT CallbackBase {
using InvokeFuncStorage = void(*)();
// Returns true if this callback equals |other|. |other| may be null.
- bool Equals(const CallbackBase& other) const;
+ bool EqualsInternal(const MoveOnlyCallbackBase& 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.
- explicit CallbackBase(BindStateBase* bind_state);
+ void set_bind_state(BindStateBase* bind_state);
+
+ MoveOnlyCallbackBase();
// Force the destructor to be instantiated inside this translation unit so
// that our subclasses will not get inlined versions. Avoids more template
// bloat.
- ~CallbackBase();
+ ~MoveOnlyCallbackBase();
scoped_refptr<BindStateBase> bind_state_;
- InvokeFuncStorage polymorphic_invoke_;
+ InvokeFuncStorage polymorphic_invoke_ = nullptr;
+};
+
+// CopyableCallbackBase is a direct base class of Copyable Callbacks.
+class BASE_EXPORT CopyableCallbackBase : public MoveOnlyCallbackBase {
+ public:
+ CopyableCallbackBase(const CopyableCallbackBase& c);
+ CopyableCallbackBase(CopyableCallbackBase&& c);
+ CopyableCallbackBase& operator=(const CopyableCallbackBase& c);
+ CopyableCallbackBase& operator=(CopyableCallbackBase&& c);
+ protected:
+ CopyableCallbackBase() {}
+ ~CopyableCallbackBase() {}
};
// A helper template to determine if given type is non-const move-only-type,

Powered by Google App Engine
This is Rietveld 408576698