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

Side by Side Diff: base/callback_internal.cc

Issue 2723423002: Start BindStateBase ref count from 1 instead of 0 (Closed)
Patch Set: +test Created 3 years, 9 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 | « no previous file | base/memory/ref_counted.h » ('j') | base/memory/ref_counted.h » ('J')
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 {
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 23
24 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke, 24 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
25 void (*destructor)(const BindStateBase*)) 25 void (*destructor)(const BindStateBase*))
26 : BindStateBase(polymorphic_invoke, destructor, &ReturnFalse) { 26 : BindStateBase(polymorphic_invoke, destructor, &ReturnFalse) {
27 } 27 }
28 28
29 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke, 29 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
30 void (*destructor)(const BindStateBase*), 30 void (*destructor)(const BindStateBase*),
31 bool (*is_cancelled)(const BindStateBase*)) 31 bool (*is_cancelled)(const BindStateBase*))
32 : polymorphic_invoke_(polymorphic_invoke), 32 : RefCountedThreadSafe(1 /* initial_ref_count */),
33 polymorphic_invoke_(polymorphic_invoke),
33 destructor_(destructor), 34 destructor_(destructor),
34 is_cancelled_(is_cancelled) {} 35 is_cancelled_(is_cancelled) {}
35 36
36 CallbackBase<CopyMode::MoveOnly>::CallbackBase(CallbackBase&& c) = default; 37 CallbackBase<CopyMode::MoveOnly>::CallbackBase(CallbackBase&& c) = default;
37 38
38 CallbackBase<CopyMode::MoveOnly>& 39 CallbackBase<CopyMode::MoveOnly>&
39 CallbackBase<CopyMode::MoveOnly>::operator=(CallbackBase&& c) = default; 40 CallbackBase<CopyMode::MoveOnly>::operator=(CallbackBase&& c) = default;
40 41
41 CallbackBase<CopyMode::MoveOnly>::CallbackBase( 42 CallbackBase<CopyMode::MoveOnly>::CallbackBase(
42 const CallbackBase<CopyMode::Copyable>& c) 43 const CallbackBase<CopyMode::Copyable>& c)
(...skipping 24 matching lines...) Expand all
67 bool CallbackBase<CopyMode::MoveOnly>::IsCancelled() const { 68 bool CallbackBase<CopyMode::MoveOnly>::IsCancelled() const {
68 DCHECK(bind_state_); 69 DCHECK(bind_state_);
69 return bind_state_->IsCancelled(); 70 return bind_state_->IsCancelled();
70 } 71 }
71 72
72 bool CallbackBase<CopyMode::MoveOnly>::EqualsInternal( 73 bool CallbackBase<CopyMode::MoveOnly>::EqualsInternal(
73 const CallbackBase& other) const { 74 const CallbackBase& other) const {
74 return bind_state_ == other.bind_state_; 75 return bind_state_ == other.bind_state_;
75 } 76 }
76 77
77 CallbackBase<CopyMode::MoveOnly>::CallbackBase( 78 CallbackBase<CopyMode::MoveOnly>::CallbackBase(BindStateBase* bind_state)
78 BindStateBase* bind_state) 79 : bind_state_(AdoptRef(bind_state)) {
79 : bind_state_(bind_state) {
80 DCHECK(!bind_state_.get() || bind_state_->HasOneRef()); 80 DCHECK(!bind_state_.get() || bind_state_->HasOneRef());
81 } 81 }
82 82
83 CallbackBase<CopyMode::MoveOnly>::~CallbackBase() {} 83 CallbackBase<CopyMode::MoveOnly>::~CallbackBase() {}
84 84
85 CallbackBase<CopyMode::Copyable>::CallbackBase( 85 CallbackBase<CopyMode::Copyable>::CallbackBase(
86 const CallbackBase& c) 86 const CallbackBase& c)
87 : CallbackBase<CopyMode::MoveOnly>(nullptr) { 87 : CallbackBase<CopyMode::MoveOnly>(nullptr) {
88 bind_state_ = c.bind_state_; 88 bind_state_ = c.bind_state_;
89 } 89 }
90 90
91 CallbackBase<CopyMode::Copyable>::CallbackBase(CallbackBase&& c) = default; 91 CallbackBase<CopyMode::Copyable>::CallbackBase(CallbackBase&& c) = default;
92 92
93 CallbackBase<CopyMode::Copyable>& 93 CallbackBase<CopyMode::Copyable>&
94 CallbackBase<CopyMode::Copyable>::operator=(const CallbackBase& c) { 94 CallbackBase<CopyMode::Copyable>::operator=(const CallbackBase& c) {
95 bind_state_ = c.bind_state_; 95 bind_state_ = c.bind_state_;
96 return *this; 96 return *this;
97 } 97 }
98 98
99 CallbackBase<CopyMode::Copyable>& 99 CallbackBase<CopyMode::Copyable>&
100 CallbackBase<CopyMode::Copyable>::operator=(CallbackBase&& c) = default; 100 CallbackBase<CopyMode::Copyable>::operator=(CallbackBase&& c) = default;
101 101
102 template class CallbackBase<CopyMode::MoveOnly>; 102 template class CallbackBase<CopyMode::MoveOnly>;
103 template class CallbackBase<CopyMode::Copyable>; 103 template class CallbackBase<CopyMode::Copyable>;
104 104
105 } // namespace internal 105 } // namespace internal
106 } // namespace base 106 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/memory/ref_counted.h » ('j') | base/memory/ref_counted.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698