| Index: base/cancelable_callback.h
|
| diff --git a/base/cancelable_callback.h b/base/cancelable_callback.h
|
| index 159100f71bfd890ffb17848c92aee0bb68ba9b01..91eb046153c9cc5412e9339dd19a1c181d7337bf 100644
|
| --- a/base/cancelable_callback.h
|
| +++ b/base/cancelable_callback.h
|
| @@ -55,13 +55,13 @@ namespace base {
|
| template <typename Sig>
|
| class CancelableCallback;
|
|
|
| -template <>
|
| -class CancelableCallback<void(void)> {
|
| +template <typename... A>
|
| +class CancelableCallback<void(A...)> {
|
| public:
|
| CancelableCallback() : weak_factory_(this) {}
|
|
|
| // |callback| must not be null.
|
| - explicit CancelableCallback(const base::Callback<void(void)>& callback)
|
| + explicit CancelableCallback(const base::Callback<void(A...)>& callback)
|
| : weak_factory_(this),
|
| callback_(callback) {
|
| DCHECK(!callback.is_null());
|
| @@ -84,7 +84,7 @@ class CancelableCallback<void(void)> {
|
|
|
| // Sets |callback| as the closure that may be cancelled. |callback| may not
|
| // be null. Outstanding and any previously wrapped callbacks are cancelled.
|
| - void Reset(const base::Callback<void(void)>& callback) {
|
| + void Reset(const base::Callback<void(A...)>& callback) {
|
| DCHECK(!callback.is_null());
|
|
|
| // Outstanding tasks (e.g., posted to a message loop) must not be called.
|
| @@ -97,173 +97,36 @@ class CancelableCallback<void(void)> {
|
| }
|
|
|
| // Returns a callback that can be disabled by calling Cancel().
|
| - const base::Callback<void(void)>& callback() const {
|
| + const base::Callback<void(A...)>& callback() const {
|
| return forwarder_;
|
| }
|
|
|
| private:
|
| - void Forward() {
|
| - callback_.Run();
|
| + void Forward(A... args) const {
|
| + callback_.Run(args...);
|
| }
|
|
|
| // Helper method to bind |forwarder_| using a weak pointer from
|
| // |weak_factory_|.
|
| void InitializeForwarder() {
|
| - forwarder_ = base::Bind(&CancelableCallback<void(void)>::Forward,
|
| + forwarder_ = base::Bind(&CancelableCallback<void(A...)>::Forward,
|
| weak_factory_.GetWeakPtr());
|
| }
|
|
|
| // Used to ensure Forward() is not run when this object is destroyed.
|
| - base::WeakPtrFactory<CancelableCallback<void(void)> > weak_factory_;
|
| + // TODO(ckehoe): This should be the last class member.
|
| + // Move it there when crbug.com/433583 is fixed.
|
| + base::WeakPtrFactory<CancelableCallback<void(A...)> > weak_factory_;
|
|
|
| // The wrapper closure.
|
| - base::Callback<void(void)> forwarder_;
|
| + base::Callback<void(A...)> forwarder_;
|
|
|
| // The stored closure that may be cancelled.
|
| - base::Callback<void(void)> callback_;
|
| + base::Callback<void(A...)> callback_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(CancelableCallback);
|
| };
|
|
|
| -template <typename A1>
|
| -class CancelableCallback<void(A1)> {
|
| - public:
|
| - CancelableCallback() : weak_factory_(this) {}
|
| -
|
| - // |callback| must not be null.
|
| - explicit CancelableCallback(const base::Callback<void(A1)>& callback)
|
| - : weak_factory_(this),
|
| - callback_(callback) {
|
| - DCHECK(!callback.is_null());
|
| - InitializeForwarder();
|
| - }
|
| -
|
| - ~CancelableCallback() {}
|
| -
|
| - // Cancels and drops the reference to the wrapped callback.
|
| - void Cancel() {
|
| - weak_factory_.InvalidateWeakPtrs();
|
| - forwarder_.Reset();
|
| - callback_.Reset();
|
| - }
|
| -
|
| - // Returns true if the wrapped callback has been cancelled.
|
| - bool IsCancelled() const {
|
| - return callback_.is_null();
|
| - }
|
| -
|
| - // Sets |callback| as the closure that may be cancelled. |callback| may not
|
| - // be null. Outstanding and any previously wrapped callbacks are cancelled.
|
| - void Reset(const base::Callback<void(A1)>& callback) {
|
| - DCHECK(!callback.is_null());
|
| -
|
| - // Outstanding tasks (e.g., posted to a message loop) must not be called.
|
| - Cancel();
|
| -
|
| - // |forwarder_| is no longer valid after Cancel(), so re-bind.
|
| - InitializeForwarder();
|
| -
|
| - callback_ = callback;
|
| - }
|
| -
|
| - // Returns a callback that can be disabled by calling Cancel().
|
| - const base::Callback<void(A1)>& callback() const {
|
| - return forwarder_;
|
| - }
|
| -
|
| - private:
|
| - void Forward(A1 a1) const {
|
| - callback_.Run(a1);
|
| - }
|
| -
|
| - // Helper method to bind |forwarder_| using a weak pointer from
|
| - // |weak_factory_|.
|
| - void InitializeForwarder() {
|
| - forwarder_ = base::Bind(&CancelableCallback<void(A1)>::Forward,
|
| - weak_factory_.GetWeakPtr());
|
| - }
|
| -
|
| - // Used to ensure Forward() is not run when this object is destroyed.
|
| - base::WeakPtrFactory<CancelableCallback<void(A1)> > weak_factory_;
|
| -
|
| - // The wrapper closure.
|
| - base::Callback<void(A1)> forwarder_;
|
| -
|
| - // The stored closure that may be cancelled.
|
| - base::Callback<void(A1)> callback_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(CancelableCallback);
|
| -};
|
| -
|
| -template <typename A1, typename A2>
|
| -class CancelableCallback<void(A1, A2)> {
|
| - public:
|
| - CancelableCallback() : weak_factory_(this) {}
|
| -
|
| - // |callback| must not be null.
|
| - explicit CancelableCallback(const base::Callback<void(A1, A2)>& callback)
|
| - : weak_factory_(this),
|
| - callback_(callback) {
|
| - DCHECK(!callback.is_null());
|
| - InitializeForwarder();
|
| - }
|
| -
|
| - ~CancelableCallback() {}
|
| -
|
| - // Cancels and drops the reference to the wrapped callback.
|
| - void Cancel() {
|
| - weak_factory_.InvalidateWeakPtrs();
|
| - forwarder_.Reset();
|
| - callback_.Reset();
|
| - }
|
| -
|
| - // Returns true if the wrapped callback has been cancelled.
|
| - bool IsCancelled() const {
|
| - return callback_.is_null();
|
| - }
|
| -
|
| - // Sets |callback| as the closure that may be cancelled. |callback| may not
|
| - // be null. Outstanding and any previously wrapped callbacks are cancelled.
|
| - void Reset(const base::Callback<void(A1, A2)>& callback) {
|
| - DCHECK(!callback.is_null());
|
| -
|
| - // Outstanding tasks (e.g., posted to a message loop) must not be called.
|
| - Cancel();
|
| -
|
| - // |forwarder_| is no longer valid after Cancel(), so re-bind.
|
| - InitializeForwarder();
|
| -
|
| - callback_ = callback;
|
| - }
|
| -
|
| - // Returns a callback that can be disabled by calling Cancel().
|
| - const base::Callback<void(A1, A2)>& callback() const {
|
| - return forwarder_;
|
| - }
|
| -
|
| - private:
|
| - void Forward(A1 a1, A2 a2) const {
|
| - callback_.Run(a1, a2);
|
| - }
|
| -
|
| - // Helper method to bind |forwarder_| using a weak pointer from
|
| - // |weak_factory_|.
|
| - void InitializeForwarder() {
|
| - forwarder_ = base::Bind(&CancelableCallback<void(A1, A2)>::Forward,
|
| - weak_factory_.GetWeakPtr());
|
| - }
|
| -
|
| - // The wrapper closure.
|
| - base::Callback<void(A1, A2)> forwarder_;
|
| -
|
| - // The stored closure that may be cancelled.
|
| - base::Callback<void(A1, A2)> callback_;
|
| -
|
| - // Used to ensure Forward() is not run when this object is destroyed.
|
| - base::WeakPtrFactory<CancelableCallback<void(A1, A2)> > weak_factory_;
|
| - DISALLOW_COPY_AND_ASSIGN(CancelableCallback);
|
| -};
|
| -
|
| typedef CancelableCallback<void(void)> CancelableClosure;
|
|
|
| } // namespace base
|
|
|