Index: base/task_runner_util.h |
diff --git a/base/task_runner_util.h b/base/task_runner_util.h |
index d1b9f62fcd6b25abf788324e118979421c738e03..b3fc8a89fda04f895a5a87561a94af1517985b5b 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 callblack that expects a T. |
+template <typename TaskReturnType, typename ReplyArgType> |
+void ReplyAdapter(const Callback<void(ReplyArgType)>& callback, |
+ TaskReturnType* result) { |
+ callback.Run(CallbackForward(*result)); |
} |
} // namespace internal |
@@ -63,17 +46,24 @@ 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) { |
+ if (reply.is_null()) { |
darin (slow to review)
2012/11/27 21:26:17
What is the use case for a null reply? Isn't this
awong
2012/11/27 21:30:36
This was behavior that was added during the origin
darin (slow to review)
2012/11/27 21:35:30
Oh, I see. Why not just preserve the null check i
awong
2012/11/27 21:40:13
Not quite sure I understand. You still have to in
|
+ // Don't waste a proxy object if |reply| does not do anything. |
+ return task_runner->PostTask(from_here, |
+ base::Bind(base::IgnoreResult(task))); |
+ } |
+ 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 |