OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_CANCELABLE_CLOSURE_HOL
DER_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_CANCELABLE_CLOSURE_HOL
DER_H_ |
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_CANCELABLE_CLOSURE_HOL
DER_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_CANCELABLE_CLOSURE_HOL
DER_H_ |
7 | 7 |
8 #include "base/cancelable_callback.h" | 8 #include "base/cancelable_callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 namespace scheduler { | 12 namespace scheduler { |
13 | 13 |
14 // A CancelableClosureHolder is a CancelableCallback which resets its wrapped | 14 // A CancelableClosureHolder is a CancelableCallback which resets its wrapped |
15 // callback with a cached closure whenever it is canceled. | 15 // callback with a cached closure whenever it is canceled. |
| 16 // TODO(alexclarke): Remove this in favor of native cancellable tasks. |
16 class CancelableClosureHolder { | 17 class CancelableClosureHolder { |
17 public: | 18 public: |
18 CancelableClosureHolder(); | 19 CancelableClosureHolder(); |
19 ~CancelableClosureHolder(); | 20 ~CancelableClosureHolder(); |
20 | 21 |
21 // Resets the closure to be wrapped by the cancelable callback. Cancels any | 22 // Resets the closure to be wrapped by the cancelable callback. Cancels any |
22 // outstanding callbacks. | 23 // outstanding callbacks. |
23 void Reset(const base::Closure& callback); | 24 void Reset(const base::Closure& callback); |
24 | 25 |
25 // Cancels any outstanding closures returned by callback(). | 26 // Cancels any outstanding closures returned by callback(). |
26 void Cancel(); | 27 void Cancel(); |
27 | 28 |
28 // Returns a callback that will be disabled by calling Cancel(). Callback | 29 // Returns a callback that will be disabled by calling Cancel(). Callback |
29 // must have been set using Reset() before calling this function. | 30 // must have been set using Reset() before calling this function. |
30 const base::Closure& callback() const; | 31 const base::Closure& callback() const; |
31 | 32 |
32 private: | 33 private: |
33 base::Closure callback_; | 34 base::Closure callback_; |
34 base::CancelableClosure cancelable_callback_; | 35 base::CancelableClosure cancelable_callback_; |
35 | 36 |
36 DISALLOW_COPY_AND_ASSIGN(CancelableClosureHolder); | 37 DISALLOW_COPY_AND_ASSIGN(CancelableClosureHolder); |
37 }; | 38 }; |
38 | 39 |
39 } // namespace scheduler | 40 } // namespace scheduler |
40 } // namespace blink | 41 } // namespace blink |
41 | 42 |
42 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_CANCELABLE_CLOSURE_
HOLDER_H_ | 43 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_CANCELABLE_CLOSURE_
HOLDER_H_ |
OLD | NEW |