Chromium Code Reviews| Index: base/cancelable_callback.h |
| diff --git a/base/cancelable_callback.h b/base/cancelable_callback.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f0cbce7d25b9db8860c50f4bcc288767b0fc5ac6 |
| --- /dev/null |
| +++ b/base/cancelable_callback.h |
| @@ -0,0 +1,48 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_CANCELABLE_CALLBACK_H_ |
| +#define BASE_CANCELABLE_CALLBACK_H_ |
|
groby-ooo-7-16
2011/11/23 02:14:12
Can we get a comment explaining usage, same as for
James Hawkins
2011/11/23 03:59:08
I could not find a succinct example to write for u
awong
2011/11/23 19:58:23
I think we should start with a syntax example show
|
| +#pragma once |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/callback.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/singleton.h" |
| +#include "base/memory/weak_ptr.h" |
| + |
| +namespace base { |
| + |
| +// Wrapper used to cancel a callback. |
| +class CancelableCallback { |
|
awong
2011/11/23 02:30:21
Part of me wants to make this subsume content/brow
James Hawkins
2011/11/23 03:59:08
I'm not sure, but looking at CancelableRequest, it
awong
2011/11/23 19:58:23
Happy to have most of the work in another CL, but
James Hawkins
2011/11/23 22:12:52
Hmm, not really. I think they're very similar as i
|
| + public: |
| + // |callback| must not be null. |
| + CancelableCallback(const base::Closure callback); |
|
groby-ooo-7-16
2011/11/23 02:14:12
We probably need an Assign() or Reset() method - e
binji
2011/11/23 02:21:44
const base::Closure& callback?
awong
2011/11/23 02:30:21
explicit and const&
James Hawkins
2011/11/23 03:59:08
Done.
James Hawkins
2011/11/23 03:59:08
Done.
James Hawkins
2011/11/23 03:59:08
Done.
|
| + |
| + // Cancels the stored callback. |
| + void Cancel(); |
|
awong
2011/11/23 02:30:21
What happens if this class is canceled multiple ti
James Hawkins
2011/11/23 03:59:08
Foo is never run in the above code. I added a uni
awong
2011/11/23 19:58:23
Sorry, I wasn't clear on the sequencing. Assume y
James Hawkins
2011/11/23 22:12:52
Can you comment what needs to be changed in the un
|
| + |
| + // Returns the wrapped callback. |
| + const base::Closure& callback() const; |
| + |
| + private: |
| + // Closure that runs the stored callback. |
| + void RunCallback(); |
| + |
| + // Used to ensure RunCallback() is not run when this object is destroyed. |
| + base::WeakPtrFactory<CancelableCallback> weak_factory_; |
| + |
| + // The wrapper closure. |
| + base::Closure forwarder_; |
| + |
| + // The stored closure that may be cancelled. |
| + base::Closure callback_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CancelableCallback); |
| +}; |
| + |
| +} // namespace base |
| + |
| +#endif // BASE_CANCELABLE_CALLBACK_H_ |