Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: base/cancelable_callback.h

Issue 8673008: base::Bind: Implement CancelableCallback to replace CancelableTaske. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test build fix. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_
7 #pragma once
8
csilv 2011/11/23 19:37:30 Consider adding some overview documentation here a
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"
csilv 2011/11/23 19:37:30 i dont think bind.h, bind_helpers.h, compiler_spec
James Hawkins 2011/11/23 22:12:52 Done.
14 #include "base/memory/weak_ptr.h"
15
16 namespace base {
17
18 // Wrapper used to cancel a callback.
19 class CancelableCallback {
csilv 2011/11/23 19:37:30 i think you may need to add BASE_EXPORT (along wit
James Hawkins 2011/11/23 22:12:52 Done.
20 public:
21 CancelableCallback();
22
23 // |callback| must not be null.
csilv 2011/11/23 19:37:30 Would it be better to say "must not be a null call
James Hawkins 2011/11/23 22:12:52 "|callback| must not be a null callback" sounds we
24 explicit CancelableCallback(const base::Closure& callback);
25
26 ~CancelableCallback();
27
28 // Cancels the stored callback.
29 void Cancel();
30
31 // Sets |callback| as the closure that may be cancelled. |callback| may not
32 // be null.
awong 2011/11/23 19:58:23 Should state what happens to outstanding callbacks
James Hawkins 2011/11/23 22:12:52 Done.
33 void Reset(const base::Closure& callback);
34
35 // Returns the wrapped callback.
awong 2011/11/23 19:58:23 Returns a callback that can disabled by calling Ca
James Hawkins 2011/11/23 22:12:52 Done.
36 const base::Closure& callback() const;
37
38 // Returns true if the wrapped callback is null.
39 bool is_null() const;
40
41 private:
42 // Closure that runs the stored callback.
43 void RunCallback();
44
45 // Helper method to bind |forwarder_| using a weak pointer from
46 // |weak_factory_|.
47 void BindForwarder();
48
49 // Used to ensure RunCallback() is not run when this object is destroyed.
50 base::WeakPtrFactory<CancelableCallback> weak_factory_;
51
52 // The wrapper closure.
53 base::Closure forwarder_;
54
55 // The stored closure that may be cancelled.
56 base::Closure callback_;
57
58 DISALLOW_COPY_AND_ASSIGN(CancelableCallback);
59 };
60
61 } // namespace base
62
63 #endif // BASE_CANCELABLE_CALLBACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698