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

Side by Side Diff: base/callback_internal.cc

Issue 2317563002: Move CallbackBase::polymorphic_invoke_ into BindStateBase (Closed)
Patch Set: rebase Created 4 years, 3 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
« no previous file with comments | « base/callback_internal.h ('k') | base/callback_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 void CallbackBase<CopyMode::MoveOnly>::Reset() { 26 void CallbackBase<CopyMode::MoveOnly>::Reset() {
27 polymorphic_invoke_ = nullptr;
28 // NULL the bind_state_ last, since it may be holding the last ref to whatever 27 // 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. 28 // object owns us, and we may be deleted after that.
30 bind_state_ = nullptr; 29 bind_state_ = nullptr;
31 } 30 }
32 31
33 bool CallbackBase<CopyMode::MoveOnly>::EqualsInternal( 32 bool CallbackBase<CopyMode::MoveOnly>::EqualsInternal(
34 const CallbackBase& other) const { 33 const CallbackBase& other) const {
35 // Ignore |polymorphic_invoke_| value in null case. 34 return bind_state_ == other.bind_state_;
36 if (!bind_state_ || !other.bind_state_)
37 return bind_state_ == other.bind_state_;
38 return bind_state_ == other.bind_state_ &&
39 polymorphic_invoke_ == other.polymorphic_invoke_;
40 } 35 }
41 36
42 CallbackBase<CopyMode::MoveOnly>::CallbackBase( 37 CallbackBase<CopyMode::MoveOnly>::CallbackBase(
43 BindStateBase* bind_state) 38 BindStateBase* bind_state)
44 : bind_state_(bind_state) { 39 : bind_state_(bind_state) {
45 DCHECK(!bind_state_.get() || bind_state_->ref_count_ == 1); 40 DCHECK(!bind_state_.get() || bind_state_->ref_count_ == 1);
46 } 41 }
47 42
48 CallbackBase<CopyMode::MoveOnly>::~CallbackBase() {} 43 CallbackBase<CopyMode::MoveOnly>::~CallbackBase() {}
49 44
50 CallbackBase<CopyMode::Copyable>::CallbackBase( 45 CallbackBase<CopyMode::Copyable>::CallbackBase(
51 const CallbackBase& c) 46 const CallbackBase& c)
52 : CallbackBase<CopyMode::MoveOnly>(nullptr) { 47 : CallbackBase<CopyMode::MoveOnly>(nullptr) {
53 bind_state_ = c.bind_state_; 48 bind_state_ = c.bind_state_;
54 polymorphic_invoke_ = c.polymorphic_invoke_;
55 } 49 }
56 50
57 CallbackBase<CopyMode::Copyable>::CallbackBase(CallbackBase&& c) = default; 51 CallbackBase<CopyMode::Copyable>::CallbackBase(CallbackBase&& c) = default;
58 52
59 CallbackBase<CopyMode::Copyable>& 53 CallbackBase<CopyMode::Copyable>&
60 CallbackBase<CopyMode::Copyable>::operator=(const CallbackBase& c) { 54 CallbackBase<CopyMode::Copyable>::operator=(const CallbackBase& c) {
61 bind_state_ = c.bind_state_; 55 bind_state_ = c.bind_state_;
62 polymorphic_invoke_ = c.polymorphic_invoke_;
63 return *this; 56 return *this;
64 } 57 }
65 58
66 CallbackBase<CopyMode::Copyable>& 59 CallbackBase<CopyMode::Copyable>&
67 CallbackBase<CopyMode::Copyable>::operator=(CallbackBase&& c) = default; 60 CallbackBase<CopyMode::Copyable>::operator=(CallbackBase&& c) = default;
68 61
69 template class CallbackBase<CopyMode::MoveOnly>; 62 template class CallbackBase<CopyMode::MoveOnly>;
70 template class CallbackBase<CopyMode::Copyable>; 63 template class CallbackBase<CopyMode::Copyable>;
71 64
72 } // namespace internal 65 } // namespace internal
73 } // namespace base 66 } // namespace base
OLDNEW
« no previous file with comments | « base/callback_internal.h ('k') | base/callback_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698