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

Unified Diff: base/callback_internal.cc

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.cc
diff --git a/base/callback_internal.cc b/base/callback_internal.cc
index 2553fe7e1b64bf20c67dde90800377dc44b58fc2..bf68e636812621ef0e273275b6021a29fe380913 100644
--- a/base/callback_internal.cc
+++ b/base/callback_internal.cc
@@ -18,28 +18,60 @@ void BindStateBase::Release() {
destructor_(this);
}
-CallbackBase::CallbackBase(const CallbackBase& c) = default;
-CallbackBase& CallbackBase::operator=(const CallbackBase& c) = default;
+MoveOnlyCallbackBase::MoveOnlyCallbackBase(MoveOnlyCallbackBase&& c)
+ : bind_state_(std::move(c.bind_state_)),
+ polymorphic_invoke_(c.polymorphic_invoke_) {
+ c.polymorphic_invoke_ = nullptr;
+}
+
+MoveOnlyCallbackBase& MoveOnlyCallbackBase::operator=(
+ MoveOnlyCallbackBase&& c) {
+ bind_state_ = std::move(c.bind_state_);
+ polymorphic_invoke_ = c.polymorphic_invoke_;
+ c.polymorphic_invoke_ = nullptr;
+ return *this;
+}
-void CallbackBase::Reset() {
- polymorphic_invoke_ = NULL;
+void MoveOnlyCallbackBase::Reset() {
+ polymorphic_invoke_ = nullptr;
// NULL the bind_state_ last, since it may be holding the last ref to whatever
// object owns us, and we may be deleted after that.
- bind_state_ = NULL;
+ bind_state_ = nullptr;
}
-bool CallbackBase::Equals(const CallbackBase& other) const {
+bool MoveOnlyCallbackBase::EqualsInternal(
+ const MoveOnlyCallbackBase& other) const {
return bind_state_.get() == other.bind_state_.get() &&
polymorphic_invoke_ == other.polymorphic_invoke_;
}
-CallbackBase::CallbackBase(BindStateBase* bind_state)
- : bind_state_(bind_state),
- polymorphic_invoke_(NULL) {
+void MoveOnlyCallbackBase::set_bind_state(BindStateBase* bind_state) {
+ bind_state_ = bind_state;
DCHECK(!bind_state_.get() || bind_state_->ref_count_ == 1);
}
-CallbackBase::~CallbackBase() {
+MoveOnlyCallbackBase::MoveOnlyCallbackBase() {}
+MoveOnlyCallbackBase::~MoveOnlyCallbackBase() {}
+
+CopyableCallbackBase::CopyableCallbackBase(CopyableCallbackBase&& c)
+ : MoveOnlyCallbackBase(std::move(c)) {}
+
+CopyableCallbackBase& CopyableCallbackBase::operator=(
+ CopyableCallbackBase&& c) {
+ *static_cast<MoveOnlyCallbackBase*>(this) = std::move(c);
+ return *this;
+}
+
+CopyableCallbackBase::CopyableCallbackBase(const CopyableCallbackBase& c) {
+ bind_state_ = c.bind_state_;
+ polymorphic_invoke_ = c.polymorphic_invoke_;
+}
+
+CopyableCallbackBase& CopyableCallbackBase::operator=(
+ const CopyableCallbackBase& c) {
+ bind_state_ = c.bind_state_;
+ polymorphic_invoke_ = c.polymorphic_invoke_;
+ return *this;
}
} // namespace internal

Powered by Google App Engine
This is Rietveld 408576698