Index: base/callback_internal.h |
diff --git a/base/callback_internal.h b/base/callback_internal.h |
index 8a5c4378bc1ccbfb5303727ecfd129dc49a42903..fefd7a2b2010ed118ef278cb54a60e1eee132190 100644 |
--- a/base/callback_internal.h |
+++ b/base/callback_internal.h |
@@ -10,15 +10,19 @@ |
#include <stddef.h> |
+#include "base/atomic_ref_count.h" |
#include "base/base_export.h" |
+#include "base/macros.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/template_util.h" |
template <typename T> |
class ScopedVector; |
namespace base { |
namespace internal { |
+class CallbackBase; |
// BindStateBase is used to provide an opaque handle that the Callback |
// class can use to represent a function object with bound arguments. It |
@@ -26,10 +30,30 @@ namespace internal { |
// DoInvoke function to perform the function execution. This allows |
// us to shield the Callback class from the types of the bound argument via |
// "type erasure." |
-class BindStateBase : public RefCountedThreadSafe<BindStateBase> { |
+// At the base level, the only task is to add reference counting data. Don't use |
+// RefCountedThreadSafe since it requires the destructor to be a virtual method. |
+// Creating a vtable for every BindState template instantiation results in a lot |
+// of bloat. Its only task is to call the destructor which can be done with a |
+// function pointer. |
+class BindStateBase { |
protected: |
- friend class RefCountedThreadSafe<BindStateBase>; |
- virtual ~BindStateBase() {} |
+ explicit BindStateBase(void (*destructor)(BindStateBase*)) |
+ : ref_count_(0), destructor_(destructor) {} |
+ ~BindStateBase() = default; |
+ |
+ private: |
+ friend class scoped_refptr<BindStateBase>; |
+ friend class CallbackBase; |
+ |
+ void AddRef(); |
+ void Release(); |
+ |
+ AtomicRefCount ref_count_; |
+ |
+ // Pointer to a function that will properly destroy |this|. |
+ void (*destructor_)(BindStateBase*); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BindStateBase); |
}; |
// Holds the Callback methods that don't require specialization to reduce |