| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_INTERNAL_H_ | 8 #ifndef BASE_CALLBACK_INTERNAL_H_ |
| 9 #define BASE_CALLBACK_INTERNAL_H_ | 9 #define BASE_CALLBACK_INTERNAL_H_ |
| 10 | 10 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // | 123 // |
| 124 // For these types, the ForwardType must not be a const reference, or a | 124 // For these types, the ForwardType must not be a const reference, or a |
| 125 // reference. A const reference is inappropriate, and would break const | 125 // reference. A const reference is inappropriate, and would break const |
| 126 // correctness, because we are implementing a destructive move. A non-const | 126 // correctness, because we are implementing a destructive move. A non-const |
| 127 // reference cannot be used with temporaries which means the result of a | 127 // reference cannot be used with temporaries which means the result of a |
| 128 // function or a cast would not be usable with Callback<> or Bind(). | 128 // function or a cast would not be usable with Callback<> or Bind(). |
| 129 // | 129 // |
| 130 // TODO(ajwong): We might be able to use SFINAE to search for the existence of | 130 // TODO(ajwong): We might be able to use SFINAE to search for the existence of |
| 131 // a Pass() function in the type and avoid the whitelist in CallbackParamTraits | 131 // a Pass() function in the type and avoid the whitelist in CallbackParamTraits |
| 132 // and CallbackForward. | 132 // and CallbackForward. |
| 133 template <typename T> | 133 template <typename T, typename D> |
| 134 struct CallbackParamTraits<scoped_ptr<T> > { | 134 struct CallbackParamTraits<scoped_ptr<T, D> > { |
| 135 typedef scoped_ptr<T> ForwardType; | 135 typedef scoped_ptr<T, D> ForwardType; |
| 136 typedef scoped_ptr<T> StorageType; | 136 typedef scoped_ptr<T, D> StorageType; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 template <typename T> | 139 template <typename T> |
| 140 struct CallbackParamTraits<scoped_array<T> > { | 140 struct CallbackParamTraits<scoped_array<T> > { |
| 141 typedef scoped_array<T> ForwardType; | 141 typedef scoped_array<T> ForwardType; |
| 142 typedef scoped_array<T> StorageType; | 142 typedef scoped_array<T> StorageType; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 template <typename T, typename R> | 145 template <typename T, typename R> |
| 146 struct CallbackParamTraits<scoped_ptr_malloc<T, R> > { | 146 struct CallbackParamTraits<scoped_ptr_malloc<T, R> > { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 166 // is impossible to implement a general std::forward with C++11 due to a lack | 166 // is impossible to implement a general std::forward with C++11 due to a lack |
| 167 // of rvalue references. | 167 // of rvalue references. |
| 168 // | 168 // |
| 169 // In addition to Callback/Bind, this is used by PostTaskAndReplyWithResult to | 169 // In addition to Callback/Bind, this is used by PostTaskAndReplyWithResult to |
| 170 // simulate std::forward() and forward the result of one Callback as a | 170 // simulate std::forward() and forward the result of one Callback as a |
| 171 // parameter to another callback. This is to support Callbacks that return | 171 // parameter to another callback. This is to support Callbacks that return |
| 172 // the movable-but-not-copyable types whitelisted above. | 172 // the movable-but-not-copyable types whitelisted above. |
| 173 template <typename T> | 173 template <typename T> |
| 174 T& CallbackForward(T& t) { return t; } | 174 T& CallbackForward(T& t) { return t; } |
| 175 | 175 |
| 176 template <typename T> | 176 template <typename T, typename D> |
| 177 scoped_ptr<T> CallbackForward(scoped_ptr<T>& p) { return p.Pass(); } | 177 scoped_ptr<T, D> CallbackForward(scoped_ptr<T, D>& p) { return p.Pass(); } |
| 178 | 178 |
| 179 template <typename T> | 179 template <typename T> |
| 180 scoped_array<T> CallbackForward(scoped_array<T>& p) { return p.Pass(); } | 180 scoped_array<T> CallbackForward(scoped_array<T>& p) { return p.Pass(); } |
| 181 | 181 |
| 182 template <typename T, typename R> | 182 template <typename T, typename R> |
| 183 scoped_ptr_malloc<T, R> CallbackForward(scoped_ptr_malloc<T, R>& p) { | 183 scoped_ptr_malloc<T, R> CallbackForward(scoped_ptr_malloc<T, R>& p) { |
| 184 return p.Pass(); | 184 return p.Pass(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 template <typename T> | 187 template <typename T> |
| 188 ScopedVector<T> CallbackForward(ScopedVector<T>& p) { return p.Pass(); } | 188 ScopedVector<T> CallbackForward(ScopedVector<T>& p) { return p.Pass(); } |
| 189 | 189 |
| 190 } // namespace internal | 190 } // namespace internal |
| 191 } // namespace base | 191 } // namespace base |
| 192 | 192 |
| 193 #endif // BASE_CALLBACK_INTERNAL_H_ | 193 #endif // BASE_CALLBACK_INTERNAL_H_ |
| OLD | NEW |