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 // NOTE: |
(...skipping 10 matching lines...) Expand all Loading... |
21 // | 21 // |
22 // EXAMPLE USAGE: | 22 // EXAMPLE USAGE: |
23 // | 23 // |
24 // In the following example, the test is verifying that RunIntensiveTest() | 24 // In the following example, the test is verifying that RunIntensiveTest() |
25 // Quit()s the message loop within 4 seconds. The cancelable callback is posted | 25 // 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, | 26 // to the message loop, the intensive test runs, the message loop is run, |
27 // then the callback is cancelled. | 27 // then the callback is cancelled. |
28 // | 28 // |
29 // void TimeoutCallback(const std::string& timeout_message) { | 29 // void TimeoutCallback(const std::string& timeout_message) { |
30 // FAIL() << timeout_message; | 30 // FAIL() << timeout_message; |
31 // MessageLoop::current()->Quit(); | 31 // MessageLoop::current()->QuitWhenIdle(); |
32 // } | 32 // } |
33 // | 33 // |
34 // CancelableClosure timeout(base::Bind(&TimeoutCallback, "Test timed out.")); | 34 // CancelableClosure timeout(base::Bind(&TimeoutCallback, "Test timed out.")); |
35 // MessageLoop::current()->PostDelayedTask(FROM_HERE, timeout.callback(), | 35 // MessageLoop::current()->PostDelayedTask(FROM_HERE, timeout.callback(), |
36 // 4000) // 4 seconds to run. | 36 // 4000) // 4 seconds to run. |
37 // RunIntensiveTest(); | 37 // RunIntensiveTest(); |
38 // MessageLoop::current()->Run(); | 38 // MessageLoop::current()->Run(); |
39 // timeout.Cancel(); // Hopefully this is hit before the timeout callback runs. | 39 // timeout.Cancel(); // Hopefully this is hit before the timeout callback runs. |
40 // | 40 // |
41 | 41 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 base::Callback<void(A1)> callback_; | 193 base::Callback<void(A1)> callback_; |
194 | 194 |
195 DISALLOW_COPY_AND_ASSIGN(CancelableCallback); | 195 DISALLOW_COPY_AND_ASSIGN(CancelableCallback); |
196 }; | 196 }; |
197 | 197 |
198 typedef CancelableCallback<void(void)> CancelableClosure; | 198 typedef CancelableCallback<void(void)> CancelableClosure; |
199 | 199 |
200 } // namespace base | 200 } // namespace base |
201 | 201 |
202 #endif // BASE_CANCELABLE_CALLBACK_H_ | 202 #endif // BASE_CANCELABLE_CALLBACK_H_ |
OLD | NEW |