OLD | NEW |
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 } |
| 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 Loading... |
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 |
OLD | NEW |