diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 00:10:04 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 00:10:04 +0000 |
commit | e24f876c537646cab5a9e8492658f570ccd7da4a (patch) | |
tree | 85aa283d18c10b47f1e3acbafce3283661407477 /base/callback_internal.h | |
parent | b538d7ea0b2484074dea680d60f7f68750d1d1e3 (diff) | |
download | chromium_src-e24f876c537646cab5a9e8492658f570ccd7da4a.zip chromium_src-e24f876c537646cab5a9e8492658f570ccd7da4a.tar.gz chromium_src-e24f876c537646cab5a9e8492658f570ccd7da4a.tar.bz2 |
Retry 114494 - Remove BindStateHolder and have Bind() return a Callback<> object directly."
This removes some complexity and also fixes a bug where if you call Bind() with the result of Bind(), the resulting Callback would only be valid during the first call. Ouch.
Also makes the static type checking a bit more strict when assigning into a Callback<>.
BUG=none
TEST=new unittests
Review URL: http://codereview.chromium.org/8915024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115045 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/callback_internal.h')
-rw-r--r-- | base/callback_internal.h | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/base/callback_internal.h b/base/callback_internal.h index 81c87c0..4bb8aa9 100644 --- a/base/callback_internal.h +++ b/base/callback_internal.h @@ -29,29 +29,6 @@ class BindStateBase : public RefCountedThreadSafe<BindStateBase> { virtual ~BindStateBase() {} }; -// This structure exists purely to pass the returned |bind_state_| from -// Bind() to Callback while avoiding an extra AddRef/Release() pair. -// -// To do this, the constructor of Callback<> must take a const-ref. The -// reference must be to a const object otherwise the compiler will emit a -// warning about taking a reference to a temporary. -// -// Unfortunately, this means that the internal |bind_state_| field must -// be made mutable. -template <typename T> -struct BindStateHolder { - explicit BindStateHolder(T* bind_state) - : bind_state_(bind_state) { - } - - mutable scoped_refptr<BindStateBase> bind_state_; -}; - -template <typename T> -BindStateHolder<T> MakeBindStateHolder(T* o) { - return BindStateHolder<T>(o); -} - // Holds the Callback methods that don't require specialization to reduce // template bloat. class BASE_EXPORT CallbackBase { @@ -72,8 +49,11 @@ class BASE_EXPORT CallbackBase { // Returns true if this callback equals |other|. |other| may be null. bool Equals(const CallbackBase& other) const; - CallbackBase(InvokeFuncStorage polymorphic_invoke, - scoped_refptr<BindStateBase>* bind_state); + // Allow initializing of |bind_state_| via the constructor to avoid default + // initialization of the scoped_refptr. We do not also initialize + // |polymorphic_invoke_| here because doing a normal assignment in the + // derived Callback templates makes for much nicer compiler errors. + explicit CallbackBase(BindStateBase* bind_state); // Force the destructor to be instantiated inside this translation unit so // that our subclasses will not get inlined versions. Avoids more template |