summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortzik <tzik@chromium.org>2016-09-21 08:06:54 (GMT)
committerCommit bot <commit-bot@chromium.org>2016-09-21 08:08:47 (GMT)
commit30e0c31970dd7d31877f455d8cdb65c8e35f880f (patch)
treedd4aaa1e6499baad109c724ba62de21767c1a583
parent2de615143194a25287de1c4831215255cea7afe4 (diff)
downloadchromium-30e0c31970dd7d31877f455d8cdb65c8e35f880f.tar.gz
chromium-30e0c31970dd7d31877f455d8cdb65c8e35f880f.tar.xz
Add const to BindStateBase to align to RefCounted constness
Review-Url: https://codereview.chromium.org/2344143002 Cr-Commit-Position: refs/heads/master@{#420005}
-rw-r--r--base/bind_internal.h4
-rw-r--r--base/callback_internal.cc8
-rw-r--r--base/callback_internal.h12
-rw-r--r--base/callback_unittest.cc8
4 files changed, 16 insertions, 16 deletions
diff --git a/base/bind_internal.h b/base/bind_internal.h
index 5845a4d..17f78a3d 100644
--- a/base/bind_internal.h
+++ b/base/bind_internal.h
@@ -470,8 +470,8 @@ struct BindState final : BindStateBase {
~BindState() {}
- static void Destroy(BindStateBase* self) {
- delete static_cast<BindState*>(self);
+ static void Destroy(const BindStateBase* self) {
+ delete static_cast<const BindState*>(self);
}
};
diff --git a/base/callback_internal.cc b/base/callback_internal.cc
index 5759a74..4afd567 100644
--- a/base/callback_internal.cc
+++ b/base/callback_internal.cc
@@ -18,23 +18,23 @@ bool ReturnFalse(const BindStateBase*) {
} // namespace
BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
- void (*destructor)(BindStateBase*))
+ void (*destructor)(const BindStateBase*))
: BindStateBase(polymorphic_invoke, destructor, &ReturnFalse) {
}
BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
- void (*destructor)(BindStateBase*),
+ void (*destructor)(const BindStateBase*),
bool (*is_cancelled)(const BindStateBase*))
: polymorphic_invoke_(polymorphic_invoke),
ref_count_(0),
destructor_(destructor),
is_cancelled_(is_cancelled) {}
-void BindStateBase::AddRef() {
+void BindStateBase::AddRef() const {
AtomicRefCountInc(&ref_count_);
}
-void BindStateBase::Release() {
+void BindStateBase::Release() const {
if (!AtomicRefCountDec(&ref_count_))
destructor_(this);
}
diff --git a/base/callback_internal.h b/base/callback_internal.h
index afed81c..f7501f9 100644
--- a/base/callback_internal.h
+++ b/base/callback_internal.h
@@ -36,9 +36,9 @@ class BASE_EXPORT BindStateBase {
protected:
BindStateBase(InvokeFuncStorage polymorphic_invoke,
- void (*destructor)(BindStateBase*));
+ void (*destructor)(const BindStateBase*));
BindStateBase(InvokeFuncStorage polymorphic_invoke,
- void (*destructor)(BindStateBase*),
+ void (*destructor)(const BindStateBase*),
bool (*is_cancelled)(const BindStateBase*));
~BindStateBase() = default;
@@ -51,8 +51,8 @@ class BASE_EXPORT BindStateBase {
return is_cancelled_(this);
}
- void AddRef();
- void Release();
+ void AddRef() const;
+ void Release() const;
// In C++, it is safe to cast function pointers to function pointers of
// another type. It is not okay to use void*. We create a InvokeFuncStorage
@@ -60,10 +60,10 @@ class BASE_EXPORT BindStateBase {
// the original type on usage.
InvokeFuncStorage polymorphic_invoke_;
- AtomicRefCount ref_count_;
+ mutable AtomicRefCount ref_count_;
// Pointer to a function that will properly destroy |this|.
- void (*destructor_)(BindStateBase*);
+ void (*destructor_)(const BindStateBase*);
bool (*is_cancelled_)(const BindStateBase*);
DISALLOW_COPY_AND_ASSIGN(BindStateBase);
diff --git a/base/callback_unittest.cc b/base/callback_unittest.cc
index ad0430f..783f3ba 100644
--- a/base/callback_unittest.cc
+++ b/base/callback_unittest.cc
@@ -25,8 +25,8 @@ struct FakeBindState1 : internal::BindStateBase {
FakeBindState1() : BindStateBase(&NopInvokeFunc, &Destroy, &IsCancelled) {}
private:
~FakeBindState1() {}
- static void Destroy(internal::BindStateBase* self) {
- delete static_cast<FakeBindState1*>(self);
+ static void Destroy(const internal::BindStateBase* self) {
+ delete static_cast<const FakeBindState1*>(self);
}
static bool IsCancelled(const internal::BindStateBase*) {
return false;
@@ -37,8 +37,8 @@ struct FakeBindState2 : internal::BindStateBase {
FakeBindState2() : BindStateBase(&NopInvokeFunc, &Destroy, &IsCancelled) {}
private:
~FakeBindState2() {}
- static void Destroy(internal::BindStateBase* self) {
- delete static_cast<FakeBindState2*>(self);
+ static void Destroy(const internal::BindStateBase* self) {
+ delete static_cast<const FakeBindState2*>(self);
}
static bool IsCancelled(const internal::BindStateBase*) {
return false;