[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | |||||
[email protected] | fb44196 | 2013-05-08 05:35:24 | [diff] [blame] | 5 | #ifndef BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_ |
6 | #define BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_ | ||||
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 7 | |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 8 | namespace base { |
9 | |||||
tzik | b9dae93 | 2017-02-10 03:57:30 | [diff] [blame] | 10 | class SequencedTaskRunner; |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 11 | |
12 | // Template helpers which use function indirection to erase T from the | ||||
13 | // function signature while still remembering it so we can call the | ||||
14 | // correct destructor/release function. | ||||
15 | // | ||||
16 | // We use this trick so we don't need to include bind.h in a header | ||||
17 | // file like sequenced_task_runner.h. We also wrap the helpers in a | ||||
18 | // templated class to make it easier for users of DeleteSoon to | ||||
19 | // declare the helper as a friend. | ||||
20 | template <class T> | ||||
21 | class DeleteHelper { | ||||
22 | private: | ||||
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 23 | static void DoDelete(const void* object) { |
tzik | b9dae93 | 2017-02-10 03:57:30 | [diff] [blame] | 24 | delete static_cast<const T*>(object); |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 25 | } |
26 | |||||
tzik | b9dae93 | 2017-02-10 03:57:30 | [diff] [blame] | 27 | friend class SequencedTaskRunner; |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 28 | }; |
29 | |||||
30 | template <class T> | ||||
31 | class ReleaseHelper { | ||||
32 | private: | ||||
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 33 | static void DoRelease(const void* object) { |
tzik | b9dae93 | 2017-02-10 03:57:30 | [diff] [blame] | 34 | static_cast<const T*>(object)->Release(); |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 35 | } |
36 | |||||
tzik | b9dae93 | 2017-02-10 03:57:30 | [diff] [blame] | 37 | friend class SequencedTaskRunner; |
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 38 | }; |
39 | |||||
[email protected] | 6b28d94 | 2012-02-15 01:43:19 | [diff] [blame] | 40 | } // namespace base |
41 | |||||
[email protected] | fb44196 | 2013-05-08 05:35:24 | [diff] [blame] | 42 | #endif // BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_ |