sequenced_task_runner_helpers.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #ifndef BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_
  5. #define BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_
  6. namespace base {
  7. class SequencedTaskRunner;
  8. // Template helpers which use function indirection to erase T from the
  9. // function signature while still remembering it so we can call the
  10. // correct destructor/release function.
  11. //
  12. // We use this trick so we don't need to include bind.h in a header
  13. // file like sequenced_task_runner.h. We also wrap the helpers in a
  14. // templated class to make it easier for users of DeleteSoon to
  15. // declare the helper as a friend.
  16. template <class T>
  17. class DeleteHelper {
  18. private:
  19. static void DoDelete(const void* object) {
  20. delete static_cast<const T*>(object);
  21. }
  22. friend class SequencedTaskRunner;
  23. };
  24. template <class T>
  25. class ReleaseHelper {
  26. private:
  27. static void DoRelease(const void* object) {
  28. static_cast<const T*>(object)->Release();
  29. }
  30. friend class SequencedTaskRunner;
  31. };
  32. } // namespace base
  33. #endif // BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_