Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Unified Diff: base/task_runner_util.h

Issue 11369061: Disassociate argument type from return type in PostTaskAndReplyWithResult template. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't rely on PTARWR allowing a null reply. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_util_proxy.cc ('k') | base/task_runner_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_runner_util.h
diff --git a/base/task_runner_util.h b/base/task_runner_util.h
index d1b9f62fcd6b25abf788324e118979421c738e03..a2efa56225160dbd4e4123aacdbf57c6e06267c0 100644
--- a/base/task_runner_util.h
+++ b/base/task_runner_util.h
@@ -15,36 +15,19 @@ namespace base {
namespace internal {
-// Helper class for TaskRunner::PostTaskAndReplyWithResult.
+// Adapts a function that produces a result via a return value to
+// one that returns via an output parameter.
template <typename ReturnType>
void ReturnAsParamAdapter(const Callback<ReturnType(void)>& func,
ReturnType* result) {
- if (!func.is_null())
- *result = func.Run();
+ *result = func.Run();
}
-// Helper class for TaskRunner::PostTaskAndReplyWithResult.
-template <typename ReturnType>
-Closure ReturnAsParam(const Callback<ReturnType(void)>& func,
- ReturnType* result) {
- DCHECK(result);
- return Bind(&ReturnAsParamAdapter<ReturnType>, func, result);
-}
-
-// Helper class for TaskRunner::PostTaskAndReplyWithResult.
-template <typename ReturnType>
-void ReplyAdapter(const Callback<void(ReturnType)>& callback,
- ReturnType* result) {
- DCHECK(result);
- if(!callback.is_null())
- callback.Run(CallbackForward(*result));
-}
-
-// Helper class for TaskRunner::PostTaskAndReplyWithResult.
-template <typename ReturnType, typename OwnedType>
-Closure ReplyHelper(const Callback<void(ReturnType)>& callback,
- OwnedType result) {
- return Bind(&ReplyAdapter<ReturnType>, callback, result);
+// Adapts a T* result to a calblack that expects a T.
Jeffrey Yasskin 2012/11/19 10:33:46 sp: calblack
awong 2012/11/26 21:57:27 Done.
+template <typename TaskReturnType, typename ReplyArgType>
+void ReplyAdapter(const Callback<void(ReplyArgType)>& callback,
+ TaskReturnType* result) {
+ callback.Run(CallbackForward(*result));
}
} // namespace internal
@@ -63,17 +46,20 @@ Closure ReplyHelper(const Callback<void(ReturnType)>& callback,
// FROM_HERE,
// Bind(&DoWorkAndReturn),
// Bind(&Callback));
-template <typename ReturnType>
+template <typename TaskReturnType, typename ReplyArgType>
bool PostTaskAndReplyWithResult(
TaskRunner* task_runner,
const tracked_objects::Location& from_here,
- const Callback<ReturnType(void)>& task,
- const Callback<void(ReturnType)>& reply) {
- ReturnType* result = new ReturnType;
+ const Callback<TaskReturnType(void)>& task,
+ const Callback<void(ReplyArgType)>& reply) {
+ DCHECK(!reply.is_null());
+ TaskReturnType* result = new TaskReturnType();
return task_runner->PostTaskAndReply(
from_here,
- internal::ReturnAsParam<ReturnType>(task, result),
- internal::ReplyHelper(reply, Owned(result)));
+ base::Bind(&internal::ReturnAsParamAdapter<TaskReturnType>, task,
+ result),
+ base::Bind(&internal::ReplyAdapter<TaskReturnType, ReplyArgType>, reply,
+ base::Owned(result)));
}
} // namespace base
« no previous file with comments | « base/file_util_proxy.cc ('k') | base/task_runner_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698