blob: 2553fe7e1b64bf20c67dde90800377dc44b58fc2 [file] [log] [blame]
[email protected]0f450362012-06-09 02:11:011// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]59eff912011-02-18 23:29:312// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/callback_internal.h"
6
[email protected]e24f8762011-12-20 00:10:047#include "base/logging.h"
8
[email protected]59eff912011-02-18 23:29:319namespace base {
10namespace internal {
11
taptede7e804c2015-05-14 08:03:3212void BindStateBase::AddRef() {
13 AtomicRefCountInc(&ref_count_);
14}
15
16void BindStateBase::Release() {
17 if (!AtomicRefCountDec(&ref_count_))
18 destructor_(this);
19}
20
dchengf8836042014-11-26 05:04:5521CallbackBase::CallbackBase(const CallbackBase& c) = default;
22CallbackBase& CallbackBase::operator=(const CallbackBase& c) = default;
23
[email protected]59eff912011-02-18 23:29:3124void CallbackBase::Reset() {
[email protected]59eff912011-02-18 23:29:3125 polymorphic_invoke_ = NULL;
[email protected]31d926652012-06-13 23:15:1626 // NULL the bind_state_ last, since it may be holding the last ref to whatever
27 // object owns us, and we may be deleted after that.
28 bind_state_ = NULL;
[email protected]59eff912011-02-18 23:29:3129}
30
31bool CallbackBase::Equals(const CallbackBase& other) const {
[email protected]7296f2762011-11-21 19:23:4432 return bind_state_.get() == other.bind_state_.get() &&
[email protected]59eff912011-02-18 23:29:3133 polymorphic_invoke_ == other.polymorphic_invoke_;
34}
35
[email protected]e24f8762011-12-20 00:10:0436CallbackBase::CallbackBase(BindStateBase* bind_state)
37 : bind_state_(bind_state),
38 polymorphic_invoke_(NULL) {
taptede7e804c2015-05-14 08:03:3239 DCHECK(!bind_state_.get() || bind_state_->ref_count_ == 1);
[email protected]59eff912011-02-18 23:29:3140}
41
42CallbackBase::~CallbackBase() {
43}
44
[email protected]59eff912011-02-18 23:29:3145} // namespace internal
[email protected]0f450362012-06-09 02:11:0146} // namespace base