summaryrefslogtreecommitdiffstats
path: root/base/message_loop_helpers.h
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-30 06:46:30 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-30 06:46:30 +0000
commitc29985edade9519981211f183a3278ec62aa0469 (patch)
treef6cf6c8b58740fda179c70dc42569d0bac538a27 /base/message_loop_helpers.h
parentbe9764157d577464924341079b558ce5eb98dd42 (diff)
downloadchromium_src-c29985edade9519981211f183a3278ec62aa0469.zip
chromium_src-c29985edade9519981211f183a3278ec62aa0469.tar.gz
chromium_src-c29985edade9519981211f183a3278ec62aa0469.tar.bz2
Convert various ReleaseSoon methods to use base::Bind()
BUG=none TEST=none TBR=brettw,atwilson Review URL: http://codereview.chromium.org/9022034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116030 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop_helpers.h')
-rw-r--r--base/message_loop_helpers.h61
1 files changed, 46 insertions, 15 deletions
diff --git a/base/message_loop_helpers.h b/base/message_loop_helpers.h
index 151128c..9aeaad7 100644
--- a/base/message_loop_helpers.h
+++ b/base/message_loop_helpers.h
@@ -16,17 +16,18 @@ namespace base {
namespace subtle {
template <class T, class R> class DeleteHelperInternal;
+template <class T, class R> class ReleaseHelperInternal;
}
-// This is a template helper which uses a function indirection to erase T from
-// the function signature while still remembering it so we can call the correct
-// destructor. We use this trick so we don't need to include bind.h in a
-// header file. We also embed the function in a class to make it easier for
-// users of DeleteSoon to declare the helper as a friend.
+// Template helpers which use a function indirection to erase T from the
+// function signature while still remembering it so we can call the correct
+// destructor/release function.
+// We use this trick so we don't need to include bind.h in a header file like
+// message_loop.h. We also wrap the helpers in a templated class to make it
+// easier for users of DeleteSoon to declare the helper as a friend.
template <class T>
class DeleteHelper {
private:
- // TODO(dcheng): Move the return type back to a function template parameter.
template <class T2, class R> friend class subtle::DeleteHelperInternal;
static void DoDelete(const void* object) {
@@ -36,19 +37,32 @@ class DeleteHelper {
DISALLOW_COPY_AND_ASSIGN(DeleteHelper);
};
+template <class T>
+class ReleaseHelper {
+ private:
+ template <class T2, class R> friend class subtle::ReleaseHelperInternal;
+
+ static void DoRelease(const void* object) {
+ reinterpret_cast<const T*>(object)->Release();
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(ReleaseHelper);
+};
+
namespace subtle {
-// An internal MessageLoop-like class helper for DeleteHelper. We don't want to
-// expose DoDelete directly since the void* argument makes it possible to pass
-// an object of the wrong type to delete. Instead, we force callers to go
-// through DeleteHelperInternal for type safety. MessageLoop-like classes which
-// expose a DeleteSoon method should friend this class and implement a
-// DeleteSoonInternal method with the following signature:
+// An internal MessageLoop-like class helper for DeleteHelper and ReleaseHelper.
+// We don't want to expose the Do*() functions directly directly since the void*
+// argument makes it possible to pass/ an object of the wrong type to delete.
+// Instead, we force callers to go through these internal helpers for type
+// safety. MessageLoop-like classes which expose DeleteSoon or ReleaseSoon
+// methods should friend the appropriate helper and implement a corresponding
+// *Internal method with the following signature:
// bool(const tracked_objects::Location&,
-// void(*deleter)(const void*),
+// void(*function)(const void*),
// void* object)
-// An implementation of DeleteSoonInternal should simply create a base::Closure
-// from (deleter, object) and return the result of posting the task.
+// An implementation of this function should simply create a base::Closure
+// from (function, object) and return the result of posting the task.
template <class T, class ReturnType>
class DeleteHelperInternal {
public:
@@ -66,6 +80,23 @@ class DeleteHelperInternal {
DISALLOW_COPY_AND_ASSIGN(DeleteHelperInternal);
};
+template <class T, class ReturnType>
+class ReleaseHelperInternal {
+ public:
+ template <class MessageLoopType>
+ static ReturnType ReleaseOnMessageLoop(
+ MessageLoopType* message_loop,
+ const tracked_objects::Location& from_here,
+ const T* object) {
+ return message_loop->ReleaseSoonInternal(from_here,
+ &ReleaseHelper<T>::DoRelease,
+ object);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ReleaseHelperInternal);
+};
+
} // namespace subtle
} // namespace base