diff options
author | sievers@chromium.org <sievers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-03 03:13:52 +0000 |
---|---|---|
committer | sievers@chromium.org <sievers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-03 03:13:52 +0000 |
commit | 7e53091fe9a48ae68c63e7bd43acb90d9bdd608c (patch) | |
tree | 0a7ffdb55262f7ec19d5af5a17d5bb044c429546 /base/memory | |
parent | b0e5a5e89b1279fe6868cb9eb0fdf7accbf410fd (diff) | |
download | chromium_src-7e53091fe9a48ae68c63e7bd43acb90d9bdd608c.zip chromium_src-7e53091fe9a48ae68c63e7bd43acb90d9bdd608c.tar.gz chromium_src-7e53091fe9a48ae68c63e7bd43acb90d9bdd608c.tar.bz2 |
Remove obsolete WeakPtr hack.
BUG=234964
Review URL: https://chromiumcodereview.appspot.com/20777008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215470 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/memory')
-rw-r--r-- | base/memory/weak_ptr.h | 17 | ||||
-rw-r--r-- | base/memory/weak_ptr_unittest.cc | 59 |
2 files changed, 37 insertions, 39 deletions
diff --git a/base/memory/weak_ptr.h b/base/memory/weak_ptr.h index b4120a1..1675889 100644 --- a/base/memory/weak_ptr.h +++ b/base/memory/weak_ptr.h @@ -90,9 +90,6 @@ class BASE_EXPORT WeakReference { void Invalidate(); bool IsValid() const; - // Remove this when crbug.com/234964 is addressed. - void DetachFromThreadHack() { sequence_checker_.DetachFromSequence(); } - private: friend class base::RefCountedThreadSafe<Flag>; @@ -125,12 +122,6 @@ class BASE_EXPORT WeakReferenceOwner { void Invalidate(); - // Remove this when crbug.com/234964 is addressed. - void DetachFromThreadHack() { - if (flag_.get()) - flag_->DetachFromThreadHack(); - } - private: mutable scoped_refptr<WeakReference::Flag> flag_; }; @@ -311,14 +302,6 @@ class SupportsWeakPtr : public internal::SupportsWeakPtrBase { return WeakPtr<T>(weak_reference_owner_.GetRef(), static_cast<T*>(this)); } - // Removes the binding, if any, from this object to a particular thread. - // This is used in WebGraphicsContext3DInProcessCommandBufferImpl to work- - // around access to cmmand buffer objects by more than one thread. - // Remove this when crbug.com/234964 is addressed. - void DetachFromThreadHack() { - weak_reference_owner_.DetachFromThreadHack(); - } - protected: ~SupportsWeakPtr() {} diff --git a/base/memory/weak_ptr_unittest.cc b/base/memory/weak_ptr_unittest.cc index be3b6db..e7e12a2 100644 --- a/base/memory/weak_ptr_unittest.cc +++ b/base/memory/weak_ptr_unittest.cc @@ -49,6 +49,10 @@ struct DerivedTarget : public Target {}; struct Arrow { WeakPtr<Target> target; }; +struct TargetWithFactory : public Target { + TargetWithFactory() : factory(this) {} + WeakPtrFactory<Target> factory; +}; // Helper class to create and destroy weak pointer copies // and delete objects on a background thread. @@ -336,43 +340,54 @@ TEST(WeakPtrTest, MoveOwnershipImplicitly) { background.DeleteArrow(arrow); } -TEST(WeakPtrTest, MoveOwnershipExplicitlyObjectNotReferenced) { - // Case 1: The target is not bound to any thread yet. So calling - // DetachFromThread() is a no-op. - Target target; - target.DetachFromThreadHack(); - - // Case 2: The target is bound to main thread but no WeakPtr is pointing to - // it. In this case, it will be re-bound to any thread trying to get a - // WeakPtr pointing to it. So detach function call is again no-op. - { - WeakPtr<Target> weak_ptr = target.AsWeakPtr(); - } - target.DetachFromThreadHack(); -} - -TEST(WeakPtrTest, MoveOwnershipExplicitly) { +TEST(WeakPtrTest, MoveOwnershipOfUnreferencedObject) { BackgroundThread background; background.Start(); Arrow* arrow; { Target target; - // Background thread creates WeakPtr(and implicitly owns the object). + // Background thread creates WeakPtr. background.CreateArrowFromTarget(&arrow, &target); + + // Bind to background thread. EXPECT_EQ(&target, background.DeRef(arrow)); - // Detach from background thread. - target.DetachFromThreadHack(); + // Release the only WeakPtr. + arrow->target.reset(); + + // Now we should be able to create a new reference from this thread. + arrow->target = target.AsWeakPtr(); // Re-bind to main thread. EXPECT_EQ(&target, arrow->target.get()); - // Main thread can now delete the target. + // And the main thread can now delete the target. } - // WeakPtr can be deleted on non-owner thread. - background.DeleteArrow(arrow); + delete arrow; +} + +TEST(WeakPtrTest, MoveOwnershipAfterInvalidate) { + BackgroundThread background; + background.Start(); + + Arrow arrow; + scoped_ptr<TargetWithFactory> target(new TargetWithFactory); + + // Bind to main thread. + arrow.target = target->factory.GetWeakPtr(); + EXPECT_EQ(target.get(), arrow.target.get()); + + target->factory.InvalidateWeakPtrs(); + EXPECT_EQ(NULL, arrow.target.get()); + + arrow.target = target->factory.GetWeakPtr(); + // Re-bind to background thread. + EXPECT_EQ(target.get(), background.DeRef(&arrow)); + + // And the background thread can now delete the target. + background.DeleteTarget(target.release()); } TEST(WeakPtrTest, MainThreadRefOutlivesBackgroundThreadRef) { |