summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-22 00:19:18 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-22 00:19:18 +0000
commita571d3d39325f0ae3b2e060f3d274b5903cbafcf (patch)
tree6adaed8b87c549299fbb679e1bb728de9118269a /base
parent952ec4b4ac9a7a92fd3014f782ce0a0ba0ef7b83 (diff)
downloadchromium_src-a571d3d39325f0ae3b2e060f3d274b5903cbafcf.zip
chromium_src-a571d3d39325f0ae3b2e060f3d274b5903cbafcf.tar.gz
chromium_src-a571d3d39325f0ae3b2e060f3d274b5903cbafcf.tar.bz2
Const-ify RefCountedThreadSafe::AddRef and Release.
Review URL: http://codereview.chromium.org/3869003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63457 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/message_loop.h5
-rw-r--r--base/message_loop_proxy.cc2
-rw-r--r--base/message_loop_proxy.h4
-rw-r--r--base/message_loop_proxy_impl.cc2
-rw-r--r--base/message_loop_proxy_impl.h4
-rw-r--r--base/message_loop_proxy_impl_unittest.cc10
-rw-r--r--base/ref_counted.h10
-rw-r--r--base/task.h8
8 files changed, 23 insertions, 22 deletions
diff --git a/base/message_loop.h b/base/message_loop.h
index 94e0096..37e4b81 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -146,7 +146,7 @@ class MessageLoop : public base::MessagePump::Delegate {
// as the thread that calls PostDelayedTask(FROM_HERE, ), then T MUST inherit
// from RefCountedThreadSafe<T>!
template <class T>
- void DeleteSoon(const tracked_objects::Location& from_here, T* object) {
+ void DeleteSoon(const tracked_objects::Location& from_here, const T* object) {
PostNonNestableTask(from_here, new DeleteTask<T>(object));
}
@@ -161,7 +161,8 @@ class MessageLoop : public base::MessagePump::Delegate {
// PostDelayedTask(FROM_HERE, ), then T MUST inherit from
// RefCountedThreadSafe<T>!
template <class T>
- void ReleaseSoon(const tracked_objects::Location& from_here, T* object) {
+ void ReleaseSoon(const tracked_objects::Location& from_here,
+ const T* object) {
PostNonNestableTask(from_here, new ReleaseTask<T>(object));
}
diff --git a/base/message_loop_proxy.cc b/base/message_loop_proxy.cc
index bc7088d..a38db39 100644
--- a/base/message_loop_proxy.cc
+++ b/base/message_loop_proxy.cc
@@ -12,7 +12,7 @@ MessageLoopProxy::MessageLoopProxy() {
MessageLoopProxy::~MessageLoopProxy() {
}
-void MessageLoopProxy::OnDestruct() {
+void MessageLoopProxy::OnDestruct() const {
delete this;
}
diff --git a/base/message_loop_proxy.h b/base/message_loop_proxy.h
index 5d6708e..4d38155 100644
--- a/base/message_loop_proxy.h
+++ b/base/message_loop_proxy.h
@@ -64,11 +64,11 @@ class MessageLoopProxy
// Called when the proxy is about to be deleted. Subclasses can override this
// to provide deletion on specific threads.
- virtual void OnDestruct();
+ virtual void OnDestruct() const;
};
struct MessageLoopProxyTraits {
- static void Destruct(MessageLoopProxy* proxy) {
+ static void Destruct(const MessageLoopProxy* proxy) {
proxy->OnDestruct();
}
};
diff --git a/base/message_loop_proxy_impl.cc b/base/message_loop_proxy_impl.cc
index 983a406..761cc71 100644
--- a/base/message_loop_proxy_impl.cc
+++ b/base/message_loop_proxy_impl.cc
@@ -71,7 +71,7 @@ bool MessageLoopProxyImpl::PostTaskHelper(
return ret;
}
-void MessageLoopProxyImpl::OnDestruct() {
+void MessageLoopProxyImpl::OnDestruct() const {
bool delete_later = false;
{
AutoLock lock(message_loop_lock_);
diff --git a/base/message_loop_proxy_impl.h b/base/message_loop_proxy_impl.h
index b93bb64..87ae70a 100644
--- a/base/message_loop_proxy_impl.h
+++ b/base/message_loop_proxy_impl.h
@@ -39,7 +39,7 @@ class MessageLoopProxyImpl : public MessageLoopProxy,
protected:
// Override OnDestruct so that we can delete the object on the target message
// loop if it still exists.
- virtual void OnDestruct();
+ virtual void OnDestruct() const;
private:
MessageLoopProxyImpl();
@@ -50,7 +50,7 @@ class MessageLoopProxyImpl : public MessageLoopProxy,
friend class MessageLoopProxy;
// The lock that protects access to target_message_loop_.
- Lock message_loop_lock_;
+ mutable Lock message_loop_lock_;
MessageLoop* target_message_loop_;
DISALLOW_COPY_AND_ASSIGN(MessageLoopProxyImpl);
diff --git a/base/message_loop_proxy_impl_unittest.cc b/base/message_loop_proxy_impl_unittest.cc
index a3cb800..8d8ef4e 100644
--- a/base/message_loop_proxy_impl_unittest.cc
+++ b/base/message_loop_proxy_impl_unittest.cc
@@ -12,20 +12,20 @@
class MessageLoopProxyImplTest : public testing::Test {
public:
- void Release() {
+ void Release() const {
AssertOnIOThread();
Quit();
}
- void Quit() {
+ void Quit() const {
loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask);
}
- void AssertOnIOThread() {
+ void AssertOnIOThread() const {
ASSERT_TRUE(io_thread_->message_loop_proxy()->BelongsToCurrentThread());
}
- void AssertOnFileThread() {
+ void AssertOnFileThread() const {
ASSERT_TRUE(file_thread_->message_loop_proxy()->BelongsToCurrentThread());
}
@@ -79,7 +79,7 @@ class MessageLoopProxyImplTest : public testing::Test {
scoped_ptr<base::Thread> file_thread_;
private:
- MessageLoop loop_;
+ mutable MessageLoop loop_;
};
diff --git a/base/ref_counted.h b/base/ref_counted.h
index 2cc4029..9c84efa 100644
--- a/base/ref_counted.h
+++ b/base/ref_counted.h
@@ -106,7 +106,7 @@ template <class T, typename Traits> class RefCountedThreadSafe;
// count reaches 0. Overload to delete it on a different thread etc.
template<typename T>
struct DefaultRefCountedThreadSafeTraits {
- static void Destruct(T* x) {
+ static void Destruct(const T* x) {
// Delete through RefCountedThreadSafe to make child classes only need to be
// friend with RefCountedThreadSafe instead of this struct, which is an
// implementation detail.
@@ -133,19 +133,19 @@ class RefCountedThreadSafe : public subtle::RefCountedThreadSafeBase {
RefCountedThreadSafe() { }
~RefCountedThreadSafe() { }
- void AddRef() {
+ void AddRef() const {
subtle::RefCountedThreadSafeBase::AddRef();
}
- void Release() {
+ void Release() const {
if (subtle::RefCountedThreadSafeBase::Release()) {
- Traits::Destruct(static_cast<T*>(this));
+ Traits::Destruct(static_cast<const T*>(this));
}
}
private:
friend struct DefaultRefCountedThreadSafeTraits<T>;
- static void DeleteInternal(T* x) { delete x; }
+ static void DeleteInternal(const T* x) { delete x; }
DISALLOW_COPY_AND_ASSIGN(RefCountedThreadSafe);
};
diff --git a/base/task.h b/base/task.h
index e6ac33c..28d15fc 100644
--- a/base/task.h
+++ b/base/task.h
@@ -180,7 +180,7 @@ class ScopedRunnableMethodFactory {
template<class T>
class DeleteTask : public CancelableTask {
public:
- explicit DeleteTask(T* obj) : obj_(obj) {
+ explicit DeleteTask(const T* obj) : obj_(obj) {
}
virtual void Run() {
delete obj_;
@@ -190,14 +190,14 @@ class DeleteTask : public CancelableTask {
}
private:
- T* obj_;
+ const T* obj_;
};
// Task to Release() an object
template<class T>
class ReleaseTask : public CancelableTask {
public:
- explicit ReleaseTask(T* obj) : obj_(obj) {
+ explicit ReleaseTask(const T* obj) : obj_(obj) {
}
virtual void Run() {
if (obj_)
@@ -208,7 +208,7 @@ class ReleaseTask : public CancelableTask {
}
private:
- T* obj_;
+ const T* obj_;
};
// RunnableMethodTraits --------------------------------------------------------