Add a WeakPtr<T> class.

This allows a class to hand out weak pointers to itself that will be nulled out
automatically when the class instance is destroyed.

I have provided two ways for a class to implement weak pointers.  It can either
subclass SupportsWeakPtr (like subclassing RefCounted) or it can be composed of
WeakPtrFactory (like having a ScopedRunnableMethodFactory member).

Eventually, I'd like to make it possible to pass a WeakPtr<T> as the first
parameter to NewRunnableMethod.  This will make ScopedRunnableMethodFactory
obsolete and should help cleanup some code.

One feature that makes the implementation here a bit more complicated is that
it is possible to pass a WeakPtr<U> to a method that takes a WeakPtr<T>
provided U "is a" T.  This proved useful in RenderView, which can then give
out weak references to both itself as well as to an interface it implements.
This informed the design of WeakPtr, causing it to have a T* ptr_ member
instead of stashing that pointer within the ref counted WeakReference object.

R=brettw
BUG=none
TEST=weak_ptr_unittest.cc

Review URL: http://codereview.chromium.org/183026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25087 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 3125d6467fc6d03e81776fca4228e92dd107e93a
3 files changed
tree: 0c7b061ae3c7670f0b548274d8c7100926f5d37e
  1. base/
  2. build/
  3. ipc/
  4. testing/