diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-17 00:31:09 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-17 00:31:09 +0000 |
commit | d52e9709573bc7279ff6a3c13b2d31e9b62f97bb (patch) | |
tree | d3934ce825d9487b91d0bcdbca4ddbc1c0754b01 /base/weak_ptr.h | |
parent | d26e0dc9edbb20145628cb25c65db63dc2664844 (diff) | |
download | chromium_src-d52e9709573bc7279ff6a3c13b2d31e9b62f97bb.zip chromium_src-d52e9709573bc7279ff6a3c13b2d31e9b62f97bb.tar.gz chromium_src-d52e9709573bc7279ff6a3c13b2d31e9b62f97bb.tar.bz2 |
Make WeakPtr harder to misuse.
Well, I managed to misuse it (issue caught in review), and these DCHECKS
will catch it.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/207005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26422 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/weak_ptr.h')
-rw-r--r-- | base/weak_ptr.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/base/weak_ptr.h b/base/weak_ptr.h index 720beb5..2fd670b 100644 --- a/base/weak_ptr.h +++ b/base/weak_ptr.h @@ -72,16 +72,34 @@ class WeakReference { } void Invalidate() { - if (flag_) + if (flag_) { + DCHECK(flag_->CalledOnValidThread()); flag_->data = false; + } } - bool is_valid() const { return flag_ && flag_->data; } + bool is_valid() const { + if (flag_) { + DCHECK(flag_->CalledOnValidThread()); + return flag_->data; + } + return false; + } private: // A reference counted boolean that is true when the weak reference is valid // and false otherwise. class Flag : public RefCountedData<bool>, public NonThreadSafe { + public: + void AddRef() { + DCHECK(CalledOnValidThread()); + RefCountedData<bool>::AddRef(); + } + + void Release() { + DCHECK(CalledOnValidThread()); + RefCountedData<bool>::Release(); + } }; scoped_refptr<Flag> flag_; |