blob: 18ec0e26f5d6dfb979a1a095f32b7f66491dd0d1 [file] [log] [blame]
[email protected]6b28d942012-02-15 01:43:191// 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]fb441962013-05-08 05:35:245#ifndef BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_
6#define BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_
[email protected]6b28d942012-02-15 01:43:197
[email protected]6b28d942012-02-15 01:43:198namespace base {
9
tzikb9dae932017-02-10 03:57:3010class SequencedTaskRunner;
[email protected]6b28d942012-02-15 01:43:1911
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.
20template <class T>
21class DeleteHelper {
22 private:
[email protected]6b28d942012-02-15 01:43:1923 static void DoDelete(const void* object) {
tzikb9dae932017-02-10 03:57:3024 delete static_cast<const T*>(object);
[email protected]6b28d942012-02-15 01:43:1925 }
26
tzikb9dae932017-02-10 03:57:3027 friend class SequencedTaskRunner;
[email protected]6b28d942012-02-15 01:43:1928};
29
30template <class T>
31class ReleaseHelper {
32 private:
[email protected]6b28d942012-02-15 01:43:1933 static void DoRelease(const void* object) {
tzikb9dae932017-02-10 03:57:3034 static_cast<const T*>(object)->Release();
[email protected]6b28d942012-02-15 01:43:1935 }
36
tzikb9dae932017-02-10 03:57:3037 friend class SequencedTaskRunner;
[email protected]6b28d942012-02-15 01:43:1938};
39
[email protected]6b28d942012-02-15 01:43:1940} // namespace base
41
[email protected]fb441962013-05-08 05:35:2442#endif // BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_