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 5 #ifndef BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_ 6 #define BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_ 7 8 namespace base { 9 10 class SequencedTaskRunner; 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: DoDelete(const void * object)23 static void DoDelete(const void* object) { 24 delete static_cast<const T*>(object); 25 } 26 27 friend class SequencedTaskRunner; 28 }; 29 30 template <class T> 31 class ReleaseHelper { 32 private: DoRelease(const void * object)33 static void DoRelease(const void* object) { 34 static_cast<const T*>(object)->Release(); 35 } 36 37 friend class SequencedTaskRunner; 38 }; 39 40 } // namespace base 41 42 #endif // BASE_SEQUENCED_TASK_RUNNER_HELPERS_H_ 43