Callback API Change: Reimplement Bind(); support IgnoreResult, full currying, and use less types.

The main API change IgnoreResult() and fully currying.  See unittest for what the new API looks like.  The rest of the changes are done to support that.

Previously, IgnoreReturn could not be used with WeakPtr<> Bind()s as it was applied after the fact to the Callback object.  Now, IgnoreResult() wraps the function like Unretained().

As an incidental benefit, the new implementation gave us fully currying for free.

Also, the new implementation scales better when supporting higher arities of functions.  The new type growth is:

  (n^2 + 20n) / 2

as opposed to

  (3n^2 + 17n) / 2

where n == arity.

For n = 6 and n=10, the new implementation has 81 and 155 templates respectively.

The old implementation had 105 and 235 templates respectively.

BUG=35233,98919,98542
TEST=existing unittests

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110975 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/callback_internal.h b/base/callback_internal.h
index 4f0736f0..81c87c0 100644
--- a/base/callback_internal.h
+++ b/base/callback_internal.h
@@ -17,39 +17,39 @@
 namespace base {
 namespace internal {
 
-// InvokerStorageBase is used to provide an opaque handle that the Callback
+// BindStateBase is used to provide an opaque handle that the Callback
 // class can use to represent a function object with bound arguments.  It
 // behaves as an existential type that is used by a corresponding
 // 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 InvokerStorageBase : public RefCountedThreadSafe<InvokerStorageBase> {
+class BindStateBase : public RefCountedThreadSafe<BindStateBase> {
  protected:
-  friend class RefCountedThreadSafe<InvokerStorageBase>;
-  virtual ~InvokerStorageBase() {}
+  friend class RefCountedThreadSafe<BindStateBase>;
+  virtual ~BindStateBase() {}
 };
 
-// This structure exists purely to pass the returned |invoker_storage_| from
+// 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 |invoker_storage_| field must
+// Unfortunately, this means that the internal |bind_state_| field must
 // be made mutable.
 template <typename T>
-struct InvokerStorageHolder {
-  explicit InvokerStorageHolder(T* invoker_storage)
-      : invoker_storage_(invoker_storage) {
+struct BindStateHolder {
+  explicit BindStateHolder(T* bind_state)
+      : bind_state_(bind_state) {
   }
 
-  mutable scoped_refptr<InvokerStorageBase> invoker_storage_;
+  mutable scoped_refptr<BindStateBase> bind_state_;
 };
 
 template <typename T>
-InvokerStorageHolder<T> MakeInvokerStorageHolder(T* o) {
-  return InvokerStorageHolder<T>(o);
+BindStateHolder<T> MakeBindStateHolder(T* o) {
+  return BindStateHolder<T>(o);
 }
 
 // Holds the Callback methods that don't require specialization to reduce
@@ -73,14 +73,14 @@
   bool Equals(const CallbackBase& other) const;
 
   CallbackBase(InvokeFuncStorage polymorphic_invoke,
-               scoped_refptr<InvokerStorageBase>* invoker_storage);
+               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
   // bloat.
   ~CallbackBase();
 
-  scoped_refptr<InvokerStorageBase> invoker_storage_;
+  scoped_refptr<BindStateBase> bind_state_;
   InvokeFuncStorage polymorphic_invoke_;
 };
 
@@ -96,7 +96,7 @@
 // array type in the initializer list which C++ does not allow.  This will
 // break passing of C-string literals.
 template <typename T>
-struct ParamTraits {
+struct CallbackParamTraits {
   typedef const T& ForwardType;
   typedef T StorageType;
 };
@@ -107,7 +107,7 @@
 //
 // The ForwardType should only be used for unbound arguments.
 template <typename T>
-struct ParamTraits<T&> {
+struct CallbackParamTraits<T&> {
   typedef T& ForwardType;
   typedef T StorageType;
 };
@@ -118,14 +118,14 @@
 // T[n]" does not seem to match correctly, so we are stuck with this
 // restriction.
 template <typename T, size_t n>
-struct ParamTraits<T[n]> {
+struct CallbackParamTraits<T[n]> {
   typedef const T* ForwardType;
   typedef const T* StorageType;
 };
 
-// See comment for ParamTraits<T[n]>.
+// See comment for CallbackParamTraits<T[n]>.
 template <typename T>
-struct ParamTraits<T[]> {
+struct CallbackParamTraits<T[]> {
   typedef const T* ForwardType;
   typedef const T* StorageType;
 };