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

Side by Side Diff: base/callback_internal.cc

Issue 2042223002: Introduce OnceClosure and BindOnce (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update docs Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/callback_internal.h" 5 #include "base/callback_internal.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace base { 9 namespace base {
10 namespace internal { 10 namespace internal {
11 11
12 void BindStateBase::AddRef() { 12 void BindStateBase::AddRef() {
13 AtomicRefCountInc(&ref_count_); 13 AtomicRefCountInc(&ref_count_);
14 } 14 }
15 15
16 void BindStateBase::Release() { 16 void BindStateBase::Release() {
17 if (!AtomicRefCountDec(&ref_count_)) 17 if (!AtomicRefCountDec(&ref_count_))
18 destructor_(this); 18 destructor_(this);
19 } 19 }
20 20
21 CallbackBase<CopyMode::MoveOnly>::CallbackBase(CallbackBase&& c) = default; 21 CallbackBase<CopyMode::MoveOnly>::CallbackBase(CallbackBase&& c) = default;
22 22
23 CallbackBase<CopyMode::MoveOnly>& 23 CallbackBase<CopyMode::MoveOnly>&
24 CallbackBase<CopyMode::MoveOnly>::operator=(CallbackBase&& c) = default; 24 CallbackBase<CopyMode::MoveOnly>::operator=(CallbackBase&& c) = default;
25 25
26 CallbackBase<CopyMode::MoveOnly>::CallbackBase(
27 const CallbackBase<CopyMode::Copyable>& c)
28 : bind_state_(c.bind_state_), polymorphic_invoke_(c.polymorphic_invoke_) {}
29
30 CallbackBase<CopyMode::MoveOnly>& CallbackBase<CopyMode::MoveOnly>::operator=(
31 const CallbackBase<CopyMode::Copyable>& c) {
32 bind_state_ = c.bind_state_;
33 polymorphic_invoke_ = c.polymorphic_invoke_;
34 return *this;
35 }
Yuta Kitamura 2016/08/16 07:44:12 Is there any reason why these can't be defined wit
tzik 2016/08/16 15:19:00 "= default" is not available for them, since they
Yuta Kitamura 2016/08/17 05:18:07 Ah okay. I was dumb.
36
26 void CallbackBase<CopyMode::MoveOnly>::Reset() { 37 void CallbackBase<CopyMode::MoveOnly>::Reset() {
27 polymorphic_invoke_ = nullptr; 38 polymorphic_invoke_ = nullptr;
28 // NULL the bind_state_ last, since it may be holding the last ref to whatever 39 // NULL the bind_state_ last, since it may be holding the last ref to whatever
29 // object owns us, and we may be deleted after that. 40 // object owns us, and we may be deleted after that.
30 bind_state_ = nullptr; 41 bind_state_ = nullptr;
31 } 42 }
32 43
33 bool CallbackBase<CopyMode::MoveOnly>::EqualsInternal( 44 bool CallbackBase<CopyMode::MoveOnly>::EqualsInternal(
34 const CallbackBase& other) const { 45 const CallbackBase& other) const {
35 // Ignore |polymorphic_invoke_| value in null case. 46 // Ignore |polymorphic_invoke_| value in null case.
(...skipping 28 matching lines...) Expand all
64 } 75 }
65 76
66 CallbackBase<CopyMode::Copyable>& 77 CallbackBase<CopyMode::Copyable>&
67 CallbackBase<CopyMode::Copyable>::operator=(CallbackBase&& c) = default; 78 CallbackBase<CopyMode::Copyable>::operator=(CallbackBase&& c) = default;
68 79
69 template class CallbackBase<CopyMode::MoveOnly>; 80 template class CallbackBase<CopyMode::MoveOnly>;
70 template class CallbackBase<CopyMode::Copyable>; 81 template class CallbackBase<CopyMode::Copyable>;
71 82
72 } // namespace internal 83 } // namespace internal
73 } // namespace base 84 } // namespace base
OLDNEW
« base/callback.h ('K') | « base/callback_internal.h ('k') | base/callback_unittest.nc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698