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::Owned(), | 9 // The public functions are base::Unretained(), base::Owned(), |
10 // base::ConstRef(), and base::IgnoreReturn(). | 10 // base::ConstRef(), and base::IgnoreReturn(). |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 270 |
271 template <typename T> | 271 template <typename T> |
272 const T& Unwrap(ConstRefWrapper<T> const_ref) { | 272 const T& Unwrap(ConstRefWrapper<T> const_ref) { |
273 return const_ref.get(); | 273 return const_ref.get(); |
274 } | 274 } |
275 | 275 |
276 template <typename T> | 276 template <typename T> |
277 T* Unwrap(const scoped_refptr<T>& o) { return o.get(); } | 277 T* Unwrap(const scoped_refptr<T>& o) { return o.get(); } |
278 | 278 |
279 template <typename T> | 279 template <typename T> |
| 280 PassScopedPtr<T> Unwrap(subtle::PassScopedPtrAnchor<T>& o) { |
| 281 return PassScopedPtr<T>(&o); |
| 282 } |
| 283 |
| 284 template <typename T> |
280 const WeakPtr<T>& Unwrap(const WeakPtr<T>& o) { return o; } | 285 const WeakPtr<T>& Unwrap(const WeakPtr<T>& o) { return o; } |
281 | 286 |
282 template <typename T> | 287 template <typename T> |
283 T* Unwrap(const OwnedWrapper<T>& o) { | 288 T* Unwrap(const OwnedWrapper<T>& o) { |
284 return o.get(); | 289 return o.get(); |
285 } | 290 } |
286 | 291 |
287 // Utility for handling different refcounting semantics in the Bind() | 292 // Utility for handling different refcounting semantics in the Bind() |
288 // function. | 293 // function. |
289 template <typename IsMethod, typename T> | 294 template <typename IsMethod, typename T> |
290 struct MaybeRefcount; | 295 struct MaybeRefcount; |
291 | 296 |
292 template <typename T> | 297 template <typename T> |
293 struct MaybeRefcount<base::false_type, T> { | 298 struct MaybeRefcount<base::false_type, T> { |
294 static void AddRef(const T&) {} | 299 static void AddRef(const T&) {} |
295 static void Release(const T&) {} | 300 static void Release(const T&) {} |
296 }; | 301 }; |
297 | 302 |
298 template <typename T, size_t n> | 303 template <typename T, size_t n> |
299 struct MaybeRefcount<base::false_type, T[n]> { | 304 struct MaybeRefcount<base::false_type, T[n]> { |
300 static void AddRef(const T*) {} | 305 static void AddRef(const T*) {} |
301 static void Release(const T*) {} | 306 static void Release(const T*) {} |
302 }; | 307 }; |
303 | 308 |
304 template <typename T> | 309 template <typename T> |
| 310 struct MaybeRefcount<base::false_type, subtle::TransientPassScopedPtr<T> > { |
| 311 static void AddRef(const subtle::PassScopedPtrAnchor<T>&) {} |
| 312 static void Release(const subtle::PassScopedPtrAnchor<T>&) {} |
| 313 }; |
| 314 |
| 315 template <typename T> |
305 struct MaybeRefcount<base::true_type, T*> { | 316 struct MaybeRefcount<base::true_type, T*> { |
306 static void AddRef(T* o) { o->AddRef(); } | 317 static void AddRef(T* o) { o->AddRef(); } |
307 static void Release(T* o) { o->Release(); } | 318 static void Release(T* o) { o->Release(); } |
308 }; | 319 }; |
309 | 320 |
310 template <typename T> | 321 template <typename T> |
311 struct MaybeRefcount<base::true_type, UnretainedWrapper<T> > { | 322 struct MaybeRefcount<base::true_type, UnretainedWrapper<T> > { |
312 static void AddRef(const UnretainedWrapper<T>&) {} | 323 static void AddRef(const UnretainedWrapper<T>&) {} |
313 static void Release(const UnretainedWrapper<T>&) {} | 324 static void Release(const UnretainedWrapper<T>&) {} |
314 }; | 325 }; |
(...skipping 12 matching lines...) Expand all Loading... |
327 static void Release(const scoped_refptr<T>& o) {} | 338 static void Release(const scoped_refptr<T>& o) {} |
328 }; | 339 }; |
329 | 340 |
330 template <typename T> | 341 template <typename T> |
331 struct MaybeRefcount<base::true_type, const T*> { | 342 struct MaybeRefcount<base::true_type, const T*> { |
332 static void AddRef(const T* o) { o->AddRef(); } | 343 static void AddRef(const T* o) { o->AddRef(); } |
333 static void Release(const T* o) { o->Release(); } | 344 static void Release(const T* o) { o->Release(); } |
334 }; | 345 }; |
335 | 346 |
336 template <typename T> | 347 template <typename T> |
| 348 struct MaybeRefcount<base::true_type, subtle::TransientPassScopedPtr<T> > { |
| 349 static void AddRef(const subtle::PassScopedPtrAnchor<T>&) {} |
| 350 static void Release(const subtle::PassScopedPtrAnchor<T>&) {} |
| 351 }; |
| 352 |
| 353 template <typename T> |
337 struct MaybeRefcount<base::true_type, WeakPtr<T> > { | 354 struct MaybeRefcount<base::true_type, WeakPtr<T> > { |
338 static void AddRef(const WeakPtr<T>&) {} | 355 static void AddRef(const WeakPtr<T>&) {} |
339 static void Release(const WeakPtr<T>&) {} | 356 static void Release(const WeakPtr<T>&) {} |
340 }; | 357 }; |
341 | 358 |
342 template <typename R> | 359 template <typename R> |
343 void VoidReturnAdapter(Callback<R(void)> callback) { | 360 void VoidReturnAdapter(Callback<R(void)> callback) { |
344 callback.Run(); | 361 callback.Run(); |
345 } | 362 } |
346 | 363 |
(...skipping 15 matching lines...) Expand all Loading... |
362 } | 379 } |
363 | 380 |
364 template <typename R> | 381 template <typename R> |
365 Closure IgnoreReturn(Callback<R(void)> callback) { | 382 Closure IgnoreReturn(Callback<R(void)> callback) { |
366 return Bind(&internal::VoidReturnAdapter<R>, callback); | 383 return Bind(&internal::VoidReturnAdapter<R>, callback); |
367 } | 384 } |
368 | 385 |
369 } // namespace base | 386 } // namespace base |
370 | 387 |
371 #endif // BASE_BIND_HELPERS_H_ | 388 #endif // BASE_BIND_HELPERS_H_ |
OLD | NEW |