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

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: 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 | « no previous file | base/task_runner_util_unittest.cc » ('j') | base/task_runner_util_unittest.cc » ('J')
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..caeeddc66b3668548f6299b4dd201df76ad2b990 100644
--- a/base/task_runner_util.h
+++ b/base/task_runner_util.h
@@ -32,19 +32,19 @@ Closure ReturnAsParam(const Callback<ReturnType(void)>& func,
}
// Helper class for TaskRunner::PostTaskAndReplyWithResult.
-template <typename ReturnType>
+template <typename ReturnType, typename ResultType>
Jeffrey Yasskin 2012/11/05 22:13:22 Could you give these template arguments the same n
awong 2012/11/19 05:57:09 Done.
void ReplyAdapter(const Callback<void(ReturnType)>& callback,
- ReturnType* result) {
+ ResultType* result) {
DCHECK(result);
if(!callback.is_null())
callback.Run(CallbackForward(*result));
}
// Helper class for TaskRunner::PostTaskAndReplyWithResult.
-template <typename ReturnType, typename OwnedType>
+template <typename ReturnType, typename ResultType>
Jeffrey Yasskin 2012/11/05 22:13:22 Ditto here.
awong 2012/11/19 05:57:09 Done.
awong 2012/11/19 05:57:09 Done.
Closure ReplyHelper(const Callback<void(ReturnType)>& callback,
- OwnedType result) {
- return Bind(&ReplyAdapter<ReturnType>, callback, result);
+ ResultType* result) {
+ return Bind(&ReplyAdapter<ReturnType, ResultType>, callback, Owned(result));
}
} // namespace internal
@@ -63,17 +63,17 @@ 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) {
Jeffrey Yasskin 2012/11/05 22:13:22 Could you double-check that users get a sensible e
awong 2012/11/19 05:57:09 Define sensible :) It looks good enough to me. Th
Jeffrey Yasskin 2012/11/19 10:33:46 LGTM
+ TaskReturnType* result = new TaskReturnType;
return task_runner->PostTaskAndReply(
from_here,
- internal::ReturnAsParam<ReturnType>(task, result),
- internal::ReplyHelper(reply, Owned(result)));
+ internal::ReturnAsParam<TaskReturnType>(task, result),
+ internal::ReplyHelper(reply, result));
}
} // namespace base
« no previous file with comments | « no previous file | base/task_runner_util_unittest.cc » ('j') | base/task_runner_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698