OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains utility functions and classes that help the | 5 // This file contains utility functions and classes that help the |
6 // implementation, and management of the Callback objects. | 6 // implementation, and management of the Callback objects. |
7 | 7 |
8 #ifndef BASE_CALLBACK_HELPERS_H_ | 8 #ifndef BASE_CALLBACK_INTERNAL_H_ |
9 #define BASE_CALLBACK_HELPERS_H_ | 9 #define BASE_CALLBACK_INTERNAL_H_ |
10 #pragma once | 10 #pragma once |
11 | 11 |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 // InvokerStorageBase is used to provide an opaque handle that the Callback | 17 // InvokerStorageBase is used to provide an opaque handle that the Callback |
18 // class can use to represent a function object with bound arguments. It | 18 // class can use to represent a function object with bound arguments. It |
19 // behaves as an existential type that is used by a corresponding | 19 // behaves as an existential type that is used by a corresponding |
(...skipping 22 matching lines...) Expand all Loading... | |
42 } | 42 } |
43 | 43 |
44 mutable scoped_refptr<InvokerStorageBase> invoker_storage_; | 44 mutable scoped_refptr<InvokerStorageBase> invoker_storage_; |
45 }; | 45 }; |
46 | 46 |
47 template <typename T> | 47 template <typename T> |
48 InvokerStorageHolder<T> MakeInvokerStorageHolder(T* o) { | 48 InvokerStorageHolder<T> MakeInvokerStorageHolder(T* o) { |
49 return InvokerStorageHolder<T>(o); | 49 return InvokerStorageHolder<T>(o); |
50 } | 50 } |
51 | 51 |
52 // Holds the Callback methods that don't require specialization to reduce | |
53 // template bloat. | |
54 class CallbackBase { | |
55 public: | |
56 // Returns true if Callback is null (doesn't refer to anything). | |
57 bool is_null() const; | |
58 | |
59 // Returns the Callback into an uninitalized state. | |
60 void Reset(); | |
61 | |
62 bool Equals(const CallbackBase& other) const; | |
63 | |
64 protected: | |
65 // In C++, it is safe to cast function pointers to function pointers of | |
66 // another type. It is not okay to use void*. We create a InvokeFuncStorage | |
67 // that that can store our function pointer, and then cast it back to | |
68 // the original type on usage. | |
69 typedef void(*InvokeFuncStorage)(void); | |
70 | |
71 CallbackBase(InvokeFuncStorage polymorphic_invoke, | |
72 scoped_refptr<InvokerStorageBase>* invoker_storage); | |
Elliot Glaysher
2011/02/18 20:39:11
Drive by: add a destructor. The autogenerated one
awong
2011/02/18 21:27:24
Done. Added comment summarizing our IM discussion
| |
73 | |
74 scoped_refptr<InvokerStorageBase> invoker_storage_; | |
75 InvokeFuncStorage polymorphic_invoke_; | |
76 }; | |
77 | |
52 } // namespace internal | 78 } // namespace internal |
53 } // namespace base | 79 } // namespace base |
54 | 80 |
55 #endif // BASE_CALLBACK_HELPERS_H_ | 81 #endif // BASE_CALLBACK_INTERNAL_H_ |
OLD | NEW |