Chromium Code Reviews| 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 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_); | |
|
alex clarke (OOO till 29th)
2016/09/07 15:53:53
Can we do this instead of the DCHECK?
if (!bind_s
dcheng
2016/09/07 21:40:27
If there's a null callback posted to the task queu
tzik
2016/09/08 03:55:10
Hmm, right, it doesn't matter for the intended usa
dcheng
2016/09/08 04:01:33
What is the use case where we'd want to call this
tzik
2016/09/08 05:21:45
There will be no actual use case for it. I just th
| |
| 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 Loading... | |
| 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 |
| OLD | NEW |