[email protected] | 2d71566 | 2011-11-28 22:00:29 | [diff] [blame] | 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_CALLBACK_FORWARD_H_ |
| 6 | #define BASE_CALLBACK_FORWARD_H_ |
[email protected] | 2d71566 | 2011-11-28 22:00:29 | [diff] [blame] | 7 | |
| 8 | namespace base { |
tzik | 77d41139 | 2016-03-09 09:47:03 | [diff] [blame] | 9 | namespace internal { |
[email protected] | 2d71566 | 2011-11-28 22:00:29 | [diff] [blame] | 10 | |
tzik | 77d41139 | 2016-03-09 09:47:03 | [diff] [blame] | 11 | // CopyMode is used to control the copyablity of a Callback. |
| 12 | // MoveOnly indicates the Callback is not copyable but movable, and Copyable |
| 13 | // indicates it is copyable and movable. |
| 14 | enum class CopyMode { |
tzik | 27d1e31 | 2016-09-13 05:28:59 | [diff] [blame] | 15 | MoveOnly, |
| 16 | Copyable, |
| 17 | }; |
| 18 | |
| 19 | enum class RepeatMode { |
| 20 | Once, |
| 21 | Repeating, |
tzik | 77d41139 | 2016-03-09 09:47:03 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | } // namespace internal |
| 25 | |
| 26 | template <typename Signature, |
tzik | 27d1e31 | 2016-09-13 05:28:59 | [diff] [blame] | 27 | internal::CopyMode copy_mode = internal::CopyMode::Copyable, |
| 28 | internal::RepeatMode repeat_mode = internal::RepeatMode::Repeating> |
[email protected] | 2d71566 | 2011-11-28 22:00:29 | [diff] [blame] | 29 | class Callback; |
| 30 | |
tzik | 3bc7779b | 2015-12-19 09:18:46 | [diff] [blame] | 31 | // Syntactic sugar to make Callback<void()> easier to declare since it |
tzik | ce3ecf8 | 2015-12-15 06:41:49 | [diff] [blame] | 32 | // will be used in a lot of APIs with delayed execution. |
tzik | 3bc7779b | 2015-12-19 09:18:46 | [diff] [blame] | 33 | using Closure = Callback<void()>; |
[email protected] | 2d71566 | 2011-11-28 22:00:29 | [diff] [blame] | 34 | |
tzik | 27d1e31 | 2016-09-13 05:28:59 | [diff] [blame] | 35 | template <typename Signature> |
| 36 | using OnceCallback = Callback<Signature, |
| 37 | internal::CopyMode::MoveOnly, |
| 38 | internal::RepeatMode::Once>; |
| 39 | template <typename Signature> |
| 40 | using RepeatingCallback = Callback<Signature, |
| 41 | internal::CopyMode::Copyable, |
| 42 | internal::RepeatMode::Repeating>; |
| 43 | using OnceClosure = OnceCallback<void()>; |
| 44 | using RepeatingClosure = RepeatingCallback<void()>; |
| 45 | |
[email protected] | 2d71566 | 2011-11-28 22:00:29 | [diff] [blame] | 46 | } // namespace base |
| 47 | |
danakj | 0a44860 | 2015-03-10 00:31:16 | [diff] [blame] | 48 | #endif // BASE_CALLBACK_FORWARD_H_ |