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 // It also defines a set of simple functions and utilities that people want | 9 // It also defines a set of simple functions and utilities that people want |
10 // when using Callback<> and Bind(). | 10 // when using Callback<> and Bind(). |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 template <typename T> | 418 template <typename T> |
419 T* Unwrap(const OwnedWrapper<T>& o) { | 419 T* Unwrap(const OwnedWrapper<T>& o) { |
420 return o.get(); | 420 return o.get(); |
421 } | 421 } |
422 | 422 |
423 template <typename T> | 423 template <typename T> |
424 T Unwrap(PassedWrapper<T>& o) { | 424 T Unwrap(PassedWrapper<T>& o) { |
425 return o.Take(); | 425 return o.Take(); |
426 } | 426 } |
427 | 427 |
428 // Utility for handling different refcounting semantics in the Bind() | |
429 // function. | |
430 template <bool is_method, typename... T> | |
431 struct MaybeScopedRefPtr; | |
432 | |
433 template <bool is_method> | |
434 struct MaybeScopedRefPtr<is_method> { | |
435 MaybeScopedRefPtr() {} | |
436 }; | |
437 | |
438 template <typename T, typename... Rest> | |
439 struct MaybeScopedRefPtr<false, T, Rest...> { | |
440 MaybeScopedRefPtr(const T&, const Rest&...) {} | |
441 }; | |
442 | |
443 template <typename T, size_t n, typename... Rest> | |
444 struct MaybeScopedRefPtr<false, T[n], Rest...> { | |
445 MaybeScopedRefPtr(const T*, const Rest&...) {} | |
446 }; | |
447 | |
448 template <typename T, typename... Rest> | |
449 struct MaybeScopedRefPtr<true, T, Rest...> { | |
450 MaybeScopedRefPtr(const T& o, const Rest&...) {} | |
451 }; | |
452 | |
453 template <typename T, typename... Rest> | |
454 struct MaybeScopedRefPtr<true, T*, Rest...> { | |
455 MaybeScopedRefPtr(T* o, const Rest&...) : ref_(o) {} | |
456 scoped_refptr<T> ref_; | |
457 }; | |
458 | |
459 // No need to additionally AddRef() and Release() since we are storing a | |
460 // scoped_refptr<> inside the storage object already. | |
461 template <typename T, typename... Rest> | |
462 struct MaybeScopedRefPtr<true, scoped_refptr<T>, Rest...> { | |
463 MaybeScopedRefPtr(const scoped_refptr<T>&, const Rest&...) {} | |
464 }; | |
465 | |
466 template <typename T, typename... Rest> | |
467 struct MaybeScopedRefPtr<true, const T*, Rest...> { | |
468 MaybeScopedRefPtr(const T* o, const Rest&...) : ref_(o) {} | |
469 scoped_refptr<const T> ref_; | |
470 }; | |
471 | |
472 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a | 428 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a |
473 // method. It is used internally by Bind() to select the correct | 429 // method. It is used internally by Bind() to select the correct |
474 // InvokeHelper that will no-op itself in the event the WeakPtr<> for | 430 // InvokeHelper that will no-op itself in the event the WeakPtr<> for |
475 // the target object is invalidated. | 431 // the target object is invalidated. |
476 // | 432 // |
477 // The first argument should be the type of the object that will be received by | 433 // The first argument should be the type of the object that will be received by |
478 // the method. | 434 // the method. |
479 template <bool IsMethod, typename... Args> | 435 template <bool IsMethod, typename... Args> |
480 struct IsWeakMethod : public false_type {}; | 436 struct IsWeakMethod : public false_type {}; |
481 | 437 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 BASE_EXPORT void DoNothing(); | 590 BASE_EXPORT void DoNothing(); |
635 | 591 |
636 template<typename T> | 592 template<typename T> |
637 void DeletePointer(T* obj) { | 593 void DeletePointer(T* obj) { |
638 delete obj; | 594 delete obj; |
639 } | 595 } |
640 | 596 |
641 } // namespace base | 597 } // namespace base |
642 | 598 |
643 #endif // BASE_BIND_HELPERS_H_ | 599 #endif // BASE_BIND_HELPERS_H_ |
OLD | NEW |