Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2913)

Unified Diff: base/callback_internal.h

Issue 8914022: Revert 114494 - Remove BindStateHolder and have Bind() return a Callback<> object directly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/callback.h.pump ('k') | base/callback_internal.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/callback_internal.h
===================================================================
--- base/callback_internal.h (revision 114494)
+++ base/callback_internal.h (working copy)
@@ -29,6 +29,29 @@
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 {
@@ -49,11 +72,8 @@
// Returns true if this callback equals |other|. |other| may be null.
bool Equals(const CallbackBase& other) const;
- // 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);
+ CallbackBase(InvokeFuncStorage polymorphic_invoke,
+ scoped_refptr<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
« no previous file with comments | « base/callback.h.pump ('k') | base/callback_internal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698