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 defines a set of argument wrappers and related factory methods that | 5 // This defines a set of argument wrappers and related factory methods that |
6 // can be used specify the refcounting and reference semantics of arguments | 6 // can be used specify the refcounting and reference semantics of arguments |
7 // that are bound by the Bind() function in base/bind.h. | 7 // that are bound by the Bind() function in base/bind.h. |
8 // | 8 // |
9 // The public functions are base::Unretained(), base::ConstRef(), and | 9 // The public functions are base::Unretained(), base::ConstRef(), and |
10 // base::IgnoreReturn(). | 10 // base::IgnoreReturn(). |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 T Unwrap(T o) { return o; } | 220 T Unwrap(T o) { return o; } |
221 | 221 |
222 template <typename T> | 222 template <typename T> |
223 T* Unwrap(UnretainedWrapper<T> unretained) { return unretained.get(); } | 223 T* Unwrap(UnretainedWrapper<T> unretained) { return unretained.get(); } |
224 | 224 |
225 template <typename T> | 225 template <typename T> |
226 const T& Unwrap(ConstRefWrapper<T> const_ref) { | 226 const T& Unwrap(ConstRefWrapper<T> const_ref) { |
227 return const_ref.get(); | 227 return const_ref.get(); |
228 } | 228 } |
229 | 229 |
| 230 template <typename T> |
| 231 T* Unwrap(const scoped_refptr<T>& o) { return o.get(); } |
| 232 |
| 233 template <typename T> |
| 234 const WeakPtr<T>& Unwrap(const WeakPtr<T>& o) { return o; } |
230 | 235 |
231 // Utility for handling different refcounting semantics in the Bind() | 236 // Utility for handling different refcounting semantics in the Bind() |
232 // function. | 237 // function. |
233 template <typename IsMethod, typename T> | 238 template <typename IsMethod, typename T> |
234 struct MaybeRefcount; | 239 struct MaybeRefcount; |
235 | 240 |
236 template <typename T> | 241 template <typename T> |
237 struct MaybeRefcount<base::false_type, T> { | 242 struct MaybeRefcount<base::false_type, T> { |
238 static void AddRef(const T&) {} | 243 static void AddRef(const T&) {} |
239 static void Release(const T&) {} | 244 static void Release(const T&) {} |
(...skipping 10 matching lines...) Expand all Loading... |
250 static void AddRef(const UnretainedWrapper<T>&) {} | 255 static void AddRef(const UnretainedWrapper<T>&) {} |
251 static void Release(const UnretainedWrapper<T>&) {} | 256 static void Release(const UnretainedWrapper<T>&) {} |
252 }; | 257 }; |
253 | 258 |
254 template <typename T> | 259 template <typename T> |
255 struct MaybeRefcount<base::true_type, T*> { | 260 struct MaybeRefcount<base::true_type, T*> { |
256 static void AddRef(T* o) { o->AddRef(); } | 261 static void AddRef(T* o) { o->AddRef(); } |
257 static void Release(T* o) { o->Release(); } | 262 static void Release(T* o) { o->Release(); } |
258 }; | 263 }; |
259 | 264 |
| 265 // No need to additionally AddRef() and Release() since we are storing a |
| 266 // scoped_refptr<> inside the storage object already. |
| 267 template <typename T> |
| 268 struct MaybeRefcount<base::true_type, scoped_refptr<T> > { |
| 269 static void AddRef(const scoped_refptr<T>& o) {} |
| 270 static void Release(const scoped_refptr<T>& o) {} |
| 271 }; |
| 272 |
260 template <typename T> | 273 template <typename T> |
261 struct MaybeRefcount<base::true_type, const T*> { | 274 struct MaybeRefcount<base::true_type, const T*> { |
262 static void AddRef(const T* o) { o->AddRef(); } | 275 static void AddRef(const T* o) { o->AddRef(); } |
263 static void Release(const T* o) { o->Release(); } | 276 static void Release(const T* o) { o->Release(); } |
264 }; | 277 }; |
265 | 278 |
266 template <typename T> | 279 template <typename T> |
267 struct MaybeRefcount<base::true_type, WeakPtr<T> > { | 280 struct MaybeRefcount<base::true_type, WeakPtr<T> > { |
268 static void AddRef(const WeakPtr<T>&) {} | 281 static void AddRef(const WeakPtr<T>&) {} |
269 static void Release(const WeakPtr<T>&) {} | 282 static void Release(const WeakPtr<T>&) {} |
(...skipping 17 matching lines...) Expand all Loading... |
287 } | 300 } |
288 | 301 |
289 template <typename R> | 302 template <typename R> |
290 Closure IgnoreReturn(Callback<R(void)> callback) { | 303 Closure IgnoreReturn(Callback<R(void)> callback) { |
291 return Bind(&internal::VoidReturnAdapter<R>, callback); | 304 return Bind(&internal::VoidReturnAdapter<R>, callback); |
292 } | 305 } |
293 | 306 |
294 } // namespace base | 307 } // namespace base |
295 | 308 |
296 #endif // BASE_BIND_HELPERS_H_ | 309 #endif // BASE_BIND_HELPERS_H_ |
OLD | NEW |