OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 COMPONENTS_SCHEDULER_BASE_CANCELABLE_CLOSURE_HOLDER_H_ | |
6 #define COMPONENTS_SCHEDULER_BASE_CANCELABLE_CLOSURE_HOLDER_H_ | |
7 | |
8 #include "base/cancelable_callback.h" | |
9 #include "base/macros.h" | |
10 | |
11 namespace scheduler { | |
12 | |
13 // A CancelableClosureHolder is a CancelableCallback which resets its wrapped | |
14 // callback with a cached closure whenever it is canceled. | |
15 class CancelableClosureHolder { | |
16 public: | |
17 CancelableClosureHolder(); | |
18 ~CancelableClosureHolder(); | |
19 | |
20 // Resets the closure to be wrapped by the cancelable callback. Cancels any | |
21 // outstanding callbacks. | |
22 void Reset(const base::Closure& callback); | |
23 | |
24 // Cancels any outstanding closures returned by callback(). | |
25 void Cancel(); | |
26 | |
27 // Returns a callback that will be disabled by calling Cancel(). Callback | |
28 // must have been set using Reset() before calling this function. | |
29 const base::Closure& callback() const; | |
30 | |
31 private: | |
32 base::Closure callback_; | |
33 base::CancelableClosure cancelable_callback_; | |
34 | |
35 DISALLOW_COPY_AND_ASSIGN(CancelableClosureHolder); | |
36 }; | |
37 | |
38 } // namespace scheduler | |
39 | |
40 #endif // COMPONENTS_SCHEDULER_BASE_CANCELABLE_CLOSURE_HOLDER_H_ | |
OLD | NEW |