diff options
author | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-07 20:17:33 +0000 |
---|---|---|
committer | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-07 20:17:33 +0000 |
commit | 8ff672519df7fb4bfe32c4bf4639b383edfe45b9 (patch) | |
tree | 5d1d29c7876d2bcc287a552587a7e1dc04615271 /base/weak_ptr.h | |
parent | ccdf73e09a56a183b94a4a679041765f0bbaa2b5 (diff) | |
download | chromium_src-8ff672519df7fb4bfe32c4bf4639b383edfe45b9.zip chromium_src-8ff672519df7fb4bfe32c4bf4639b383edfe45b9.tar.gz chromium_src-8ff672519df7fb4bfe32c4bf4639b383edfe45b9.tar.bz2 |
Make ~GoogleURLChangeNotifier happen on the I/O thread.
Also change the test code to allow for its destruction.
One key problem was that the object containing WeakPtr is created on the UI
thread but then always used on the I/O thread like everything else that hangs
off of ResourceMessageFilter. The solution was to allow WeakPtr to detach
from its thread (and automatically re-attach the next time the thread is
checked).
BUG=38475
TEST=base_unittest --gtest_filter=NonThread*:ThreadChecker*
unit_tests --gtest_filter=SearchProviderInstallData*
Review URL: http://codereview.chromium.org/3627001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61836 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/weak_ptr.h')
-rw-r--r-- | base/weak_ptr.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/base/weak_ptr.h b/base/weak_ptr.h index 4ae7972..ed9ef66 100644 --- a/base/weak_ptr.h +++ b/base/weak_ptr.h @@ -74,6 +74,8 @@ class WeakReference { void Invalidate() { handle_ = NULL; } bool is_valid() const { return handle_ != NULL; } + void DetachFromThread() { NonThreadSafe::DetachFromThread(); } + private: Flag** handle_; }; @@ -101,6 +103,11 @@ class WeakReferenceOwner { void Invalidate(); + // Indicates that this object will be used on another thread from now on. + void DetachFromThread() { + if (flag_) flag_->DetachFromThread(); + } + private: mutable WeakReference::Flag* flag_; }; @@ -192,6 +199,11 @@ class SupportsWeakPtr { return WeakPtr<T>(weak_reference_owner_.GetRef(), static_cast<T*>(this)); } + // Indicates that this object will be used on another thread from now on. + void DetachFromThread() { + weak_reference_owner_.DetachFromThread(); + } + private: internal::WeakReferenceOwner weak_reference_owner_; DISALLOW_COPY_AND_ASSIGN(SupportsWeakPtr); |