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

Side by Side Diff: base/callback_internal.cc

Issue 2289703002: Add Callback::IsCancelled (Closed)
Patch Set: revert to PS5 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 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke, 12 BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
13 void (*destructor)(BindStateBase*)) 13 void (*destructor)(BindStateBase*),
14 bool (*is_cancelled)(const BindStateBase*))
14 : polymorphic_invoke_(polymorphic_invoke), 15 : polymorphic_invoke_(polymorphic_invoke),
15 ref_count_(0), destructor_(destructor) {} 16 ref_count_(0),
17 destructor_(destructor),
18 is_cancelled_(is_cancelled) {}
16 19
17 void BindStateBase::AddRef() { 20 void BindStateBase::AddRef() {
18 AtomicRefCountInc(&ref_count_); 21 AtomicRefCountInc(&ref_count_);
19 } 22 }
20 23
21 void BindStateBase::Release() { 24 void BindStateBase::Release() {
22 if (!AtomicRefCountDec(&ref_count_)) 25 if (!AtomicRefCountDec(&ref_count_))
23 destructor_(this); 26 destructor_(this);
24 } 27 }
25 28
26 CallbackBase<CopyMode::MoveOnly>::CallbackBase(CallbackBase&& c) = default; 29 CallbackBase<CopyMode::MoveOnly>::CallbackBase(CallbackBase&& c) = default;
27 30
28 CallbackBase<CopyMode::MoveOnly>& 31 CallbackBase<CopyMode::MoveOnly>&
29 CallbackBase<CopyMode::MoveOnly>::operator=(CallbackBase&& c) = default; 32 CallbackBase<CopyMode::MoveOnly>::operator=(CallbackBase&& c) = default;
30 33
31 void CallbackBase<CopyMode::MoveOnly>::Reset() { 34 void CallbackBase<CopyMode::MoveOnly>::Reset() {
32 // NULL the bind_state_ last, since it may be holding the last ref to whatever 35 // NULL the bind_state_ last, since it may be holding the last ref to whatever
33 // object owns us, and we may be deleted after that. 36 // object owns us, and we may be deleted after that.
34 bind_state_ = nullptr; 37 bind_state_ = nullptr;
35 } 38 }
36 39
40 bool CallbackBase<CopyMode::MoveOnly>::IsCancelled() const {
41 DCHECK(bind_state_);
42 return bind_state_->IsCancelled();
43 }
44
37 bool CallbackBase<CopyMode::MoveOnly>::EqualsInternal( 45 bool CallbackBase<CopyMode::MoveOnly>::EqualsInternal(
38 const CallbackBase& other) const { 46 const CallbackBase& other) const {
39 return bind_state_ == other.bind_state_; 47 return bind_state_ == other.bind_state_;
40 } 48 }
41 49
42 CallbackBase<CopyMode::MoveOnly>::CallbackBase( 50 CallbackBase<CopyMode::MoveOnly>::CallbackBase(
43 BindStateBase* bind_state) 51 BindStateBase* bind_state)
44 : bind_state_(bind_state) { 52 : bind_state_(bind_state) {
45 DCHECK(!bind_state_.get() || bind_state_->ref_count_ == 1); 53 DCHECK(!bind_state_.get() || bind_state_->ref_count_ == 1);
46 } 54 }
(...skipping 15 matching lines...) Expand all
62 } 70 }
63 71
64 CallbackBase<CopyMode::Copyable>& 72 CallbackBase<CopyMode::Copyable>&
65 CallbackBase<CopyMode::Copyable>::operator=(CallbackBase&& c) = default; 73 CallbackBase<CopyMode::Copyable>::operator=(CallbackBase&& c) = default;
66 74
67 template class CallbackBase<CopyMode::MoveOnly>; 75 template class CallbackBase<CopyMode::MoveOnly>;
68 template class CallbackBase<CopyMode::Copyable>; 76 template class CallbackBase<CopyMode::Copyable>;
69 77
70 } // namespace internal 78 } // namespace internal
71 } // namespace base 79 } // 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