| 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(), bass::Passed(), | 9 // The public functions are base::Unretained(), base::Owned(), bass::Passed(), |
| 10 // base::ConstRef(), and base::IgnoreResult(). | 10 // base::ConstRef(), and base::IgnoreResult(). |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // Passed() is particularly useful with PostTask() when you are transferring | 123 // Passed() is particularly useful with PostTask() when you are transferring |
| 124 // ownership of an argument into a task, but don't necessarily know if the | 124 // ownership of an argument into a task, but don't necessarily know if the |
| 125 // task will always be executed. This can happen if the task is cancellable | 125 // task will always be executed. This can happen if the task is cancellable |
| 126 // or if it is posted to a MessageLoopProxy. | 126 // or if it is posted to a MessageLoopProxy. |
| 127 | 127 |
| 128 #ifndef BASE_BIND_HELPERS_H_ | 128 #ifndef BASE_BIND_HELPERS_H_ |
| 129 #define BASE_BIND_HELPERS_H_ | 129 #define BASE_BIND_HELPERS_H_ |
| 130 #pragma once | 130 #pragma once |
| 131 | 131 |
| 132 #include "base/basictypes.h" | 132 #include "base/basictypes.h" |
| 133 #include "base/bind.h" | |
| 134 #include "base/callback.h" | 133 #include "base/callback.h" |
| 135 #include "base/memory/weak_ptr.h" | 134 #include "base/memory/weak_ptr.h" |
| 136 #include "base/template_util.h" | 135 #include "base/template_util.h" |
| 137 | 136 |
| 138 namespace base { | 137 namespace base { |
| 139 namespace internal { | 138 namespace internal { |
| 140 | 139 |
| 141 // Use the Substitution Failure Is Not An Error (SFINAE) trick to inspect T | 140 // Use the Substitution Failure Is Not An Error (SFINAE) trick to inspect T |
| 142 // for the existence of AddRef() and Release() functions of the correct | 141 // for the existence of AddRef() and Release() functions of the correct |
| 143 // signature. | 142 // signature. |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 static void AddRef(const scoped_refptr<T>& o) {} | 454 static void AddRef(const scoped_refptr<T>& o) {} |
| 456 static void Release(const scoped_refptr<T>& o) {} | 455 static void Release(const scoped_refptr<T>& o) {} |
| 457 }; | 456 }; |
| 458 | 457 |
| 459 template <typename T> | 458 template <typename T> |
| 460 struct MaybeRefcount<true, const T*> { | 459 struct MaybeRefcount<true, const T*> { |
| 461 static void AddRef(const T* o) { o->AddRef(); } | 460 static void AddRef(const T* o) { o->AddRef(); } |
| 462 static void Release(const T* o) { o->Release(); } | 461 static void Release(const T* o) { o->Release(); } |
| 463 }; | 462 }; |
| 464 | 463 |
| 465 template <typename R> | |
| 466 void VoidReturnAdapter(Callback<R(void)> callback) { | |
| 467 callback.Run(); | |
| 468 } | |
| 469 | |
| 470 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a | 464 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a |
| 471 // method. It is used internally by Bind() to select the correct | 465 // method. It is used internally by Bind() to select the correct |
| 472 // InvokeHelper that will no-op itself in the event the WeakPtr<> for | 466 // InvokeHelper that will no-op itself in the event the WeakPtr<> for |
| 473 // the target object is invalidated. | 467 // the target object is invalidated. |
| 474 // | 468 // |
| 475 // P1 should be the type of the object that will be received of the method. | 469 // P1 should be the type of the object that will be received of the method. |
| 476 template <bool IsMethod, typename P1> | 470 template <bool IsMethod, typename P1> |
| 477 struct IsWeakMethod : public false_type {}; | 471 struct IsWeakMethod : public false_type {}; |
| 478 | 472 |
| 479 template <typename T> | 473 template <typename T> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 505 // to write Passed(scoper.Pass()). | 499 // to write Passed(scoper.Pass()). |
| 506 template <typename T> | 500 template <typename T> |
| 507 static inline internal::PassedWrapper<T> Passed(T scoper) { | 501 static inline internal::PassedWrapper<T> Passed(T scoper) { |
| 508 return internal::PassedWrapper<T>(scoper.Pass()); | 502 return internal::PassedWrapper<T>(scoper.Pass()); |
| 509 } | 503 } |
| 510 template <typename T> | 504 template <typename T> |
| 511 static inline internal::PassedWrapper<T> Passed(T* scoper) { | 505 static inline internal::PassedWrapper<T> Passed(T* scoper) { |
| 512 return internal::PassedWrapper<T>(scoper->Pass()); | 506 return internal::PassedWrapper<T>(scoper->Pass()); |
| 513 } | 507 } |
| 514 | 508 |
| 515 // -- DEPRECATED -- Use IgnoreResult instead. | |
| 516 template <typename R> | |
| 517 static inline Closure IgnoreReturn(Callback<R(void)> callback) { | |
| 518 return Bind(&internal::VoidReturnAdapter<R>, callback); | |
| 519 } | |
| 520 | |
| 521 template <typename T> | 509 template <typename T> |
| 522 static inline internal::IgnoreResultHelper<T> IgnoreResult(T data) { | 510 static inline internal::IgnoreResultHelper<T> IgnoreResult(T data) { |
| 523 return internal::IgnoreResultHelper<T>(data); | 511 return internal::IgnoreResultHelper<T>(data); |
| 524 } | 512 } |
| 525 | 513 |
| 526 template <typename T> | 514 template <typename T> |
| 527 static inline internal::IgnoreResultHelper<Callback<T> > | 515 static inline internal::IgnoreResultHelper<Callback<T> > |
| 528 IgnoreResult(const Callback<T>& data) { | 516 IgnoreResult(const Callback<T>& data) { |
| 529 return internal::IgnoreResultHelper<Callback<T> >(data); | 517 return internal::IgnoreResultHelper<Callback<T> >(data); |
| 530 } | 518 } |
| 531 | 519 |
| 532 } // namespace base | 520 } // namespace base |
| 533 | 521 |
| 534 #endif // BASE_BIND_HELPERS_H_ | 522 #endif // BASE_BIND_HELPERS_H_ |
| OLD | NEW |