Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 // CancelableCallback is a wrapper around base::Callback that allows | 5 // CancelableCallback is a wrapper around base::Callback that allows |
| 6 // cancellation of a callback. CancelableCallback takes a reference on the | 6 // cancellation of a callback. CancelableCallback takes a reference on the |
| 7 // wrapped callback until this object is destroyed or Reset()/Cancel() are | 7 // wrapped callback until this object is destroyed or Reset()/Cancel() are |
| 8 // called. | 8 // called. |
| 9 // | 9 // |
| 10 // NOTE: | 10 // NOTES: |
| 11 // | 11 // |
| 12 // Calling CancelableCallback::Cancel() brings the object back to its natural, | 12 // Calling CancelableCallback::Cancel() brings the object back to its natural, |
| 13 // default-constructed state, i.e., CancelableCallback::callback() will return | 13 // default-constructed state, i.e., CancelableCallback::callback() will return |
| 14 // a null callback. | 14 // a null callback. |
| 15 // | 15 // |
| 16 // It is NOT allowed to call CancelableCallback::Cancel() or | |
| 17 // CancelableCallback::Reset() from the wrapped callback. | |
| 18 // | |
| 16 // THREAD-SAFETY: | 19 // THREAD-SAFETY: |
| 17 // | 20 // |
| 18 // CancelableCallback objects must be created on, posted to, cancelled on, and | 21 // CancelableCallback objects must be posted to, cancelled on, reset on, and |
| 19 // destroyed on the same thread. | 22 // destroyed on the same thread. |
| 20 // | 23 // |
| 24 // CancelableCallback objects are allowed to be constructed on a different | |
|
emaxx
2017/03/01 03:37:54
Hmm, thinking more on this, this added comment is
| |
| 25 // thread than on which they will be used later. | |
| 26 // | |
| 21 // | 27 // |
| 22 // EXAMPLE USAGE: | 28 // EXAMPLE USAGE: |
| 23 // | 29 // |
| 24 // In the following example, the test is verifying that RunIntensiveTest() | 30 // In the following example, the test is verifying that RunIntensiveTest() |
| 25 // Quit()s the message loop within 4 seconds. The cancelable callback is posted | 31 // Quit()s the message loop within 4 seconds. The cancelable callback is posted |
| 26 // to the message loop, the intensive test runs, the message loop is run, | 32 // to the message loop, the intensive test runs, the message loop is run, |
| 27 // then the callback is cancelled. | 33 // then the callback is cancelled. |
| 28 // | 34 // |
| 29 // RunLoop run_loop; | 35 // RunLoop run_loop; |
| 30 // | 36 // |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 base::WeakPtrFactory<CancelableCallback<void(A...)>> weak_factory_; | 133 base::WeakPtrFactory<CancelableCallback<void(A...)>> weak_factory_; |
| 128 | 134 |
| 129 DISALLOW_COPY_AND_ASSIGN(CancelableCallback); | 135 DISALLOW_COPY_AND_ASSIGN(CancelableCallback); |
| 130 }; | 136 }; |
| 131 | 137 |
| 132 typedef CancelableCallback<void(void)> CancelableClosure; | 138 typedef CancelableCallback<void(void)> CancelableClosure; |
| 133 | 139 |
| 134 } // namespace base | 140 } // namespace base |
| 135 | 141 |
| 136 #endif // BASE_CANCELABLE_CALLBACK_H_ | 142 #endif // BASE_CANCELABLE_CALLBACK_H_ |
| OLD | NEW |