Index: base/uber_callback_helpers.h |
diff --git a/base/uber_callback_helpers.h b/base/uber_callback_helpers.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a71bb0e13804628dafc614510d61f41aeb6c085a |
--- /dev/null |
+++ b/base/uber_callback_helpers.h |
@@ -0,0 +1,45 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// This file contains utility functions and classes that help the implemenation, |
+// and management of the Callback objects. |
+ |
+#ifndef BASE_UBER_CALLBACK_HELPERS_H_ |
+#define BASE_UBER_CALLBACK_HELPERS_H_ |
+#pragma once |
+ |
+#include "base/ref_counted.h" |
+ |
+namespace base { |
+namespace internal { |
+ |
+// InvokerStorageBase 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 |
+// PolymorphicInvoke 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> { |
+ protected: |
+ friend class RefCountedThreadSafe<InvokerStorageBase>; |
+ virtual ~InvokerStorageBase() {} |
+}; |
+ |
+template <typename T> |
+struct InvokerStorageHolder { |
+ explicit InvokerStorageHolder(T* invoker_storage) |
+ : invoker_storage_(invoker_storage) { |
+ } |
willchan no longer on Chromium
2011/02/07 23:25:15
Perhaps the destructor should DCHECK that invoker_
awong
2011/02/08 18:52:26
We could...but then we'd be adding a non-trivial d
|
+ mutable scoped_refptr<InvokerStorageBase> invoker_storage_; |
willchan no longer on Chromium
2011/02/06 10:26:50
Why is this mutable?
awong
2011/02/08 18:52:26
Added comment explaining.
|
+}; |
+ |
+template <typename T> |
+InvokerStorageHolder<T> MakeInvokerStorageHolder(T* o) { |
+ return InvokerStorageHolder<T>(o); |
+} |
+ |
+} // namespace internal |
+} // namespace base |
+ |
+#endif // BASE_UBER_CALLBACK_HELPERS_H_ |