OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BASE_CANCELABLE_CALLBACK_H_ | |
6 #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
| |
7 #pragma once | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/bind_helpers.h" | |
11 #include "base/callback.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/memory/singleton.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 | |
16 namespace base { | |
17 | |
18 // Wrapper used to cancel a callback. | |
19 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
| |
20 public: | |
21 // |callback| must not be null. | |
22 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.
| |
23 | |
24 // Cancels the stored callback. | |
25 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
| |
26 | |
27 // Returns the wrapped callback. | |
28 const base::Closure& callback() const; | |
29 | |
30 private: | |
31 // Closure that runs the stored callback. | |
32 void RunCallback(); | |
33 | |
34 // Used to ensure RunCallback() is not run when this object is destroyed. | |
35 base::WeakPtrFactory<CancelableCallback> weak_factory_; | |
36 | |
37 // The wrapper closure. | |
38 base::Closure forwarder_; | |
39 | |
40 // The stored closure that may be cancelled. | |
41 base::Closure callback_; | |
42 | |
43 DISALLOW_COPY_AND_ASSIGN(CancelableCallback); | |
44 }; | |
45 | |
46 } // namespace base | |
47 | |
48 #endif // BASE_CANCELABLE_CALLBACK_H_ | |
OLD | NEW |