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

Unified Diff: base/task_runner_util.h

Issue 2842493004: Add OnceCallback support to PostTaskAndReplyWithResult (Closed)
Patch Set: . Created 3 years, 8 months 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
Index: base/task_runner_util.h
diff --git a/base/task_runner_util.h b/base/task_runner_util.h
index 9196bf17a16f88e9992b48259ea0e22b8e0b51f8..a89adc6937a78f81a1710c36afd8020e54c9e95c 100644
--- a/base/task_runner_util.h
+++ b/base/task_runner_util.h
@@ -28,22 +28,38 @@ namespace base {
// PostTaskAndReplyWithResult(
// target_thread_.task_runner(),
// FROM_HERE,
-// Bind(&DoWorkAndReturn),
-// Bind(&Callback));
+// BindOnce(&DoWorkAndReturn),
+// BindOnce(&Callback));
template <typename TaskReturnType, typename ReplyArgType>
bool PostTaskAndReplyWithResult(TaskRunner* task_runner,
const tracked_objects::Location& from_here,
- Callback<TaskReturnType()> task,
- Callback<void(ReplyArgType)> reply) {
+ OnceCallback<TaskReturnType()> task,
+ OnceCallback<void(ReplyArgType)> reply) {
DCHECK(task);
DCHECK(reply);
TaskReturnType* result = new TaskReturnType();
return task_runner->PostTaskAndReply(
from_here,
- base::BindOnce(&internal::ReturnAsParamAdapter<TaskReturnType>,
- std::move(task), result),
- base::BindOnce(&internal::ReplyAdapter<TaskReturnType, ReplyArgType>,
- std::move(reply), base::Owned(result)));
+ BindOnce(&internal::ReturnAsParamAdapter<TaskReturnType>, std::move(task),
+ result),
+ BindOnce(&internal::ReplyAdapter<TaskReturnType, ReplyArgType>,
+ std::move(reply), Owned(result)));
+}
+
+// Callback version of PostTaskAndReplyWithResult above.
+// Though RepeatingCallback is convertible to OnceCallback, we need this since
+// we can not use template deduction and object conversion at once on the
+// overload resolution.
+// TODO(tzik): Update all callers of the Callback version to use OnceCallback.
+template <typename TaskReturnType, typename ReplyArgType>
+bool PostTaskAndReplyWithResult(TaskRunner* task_runner,
+ const tracked_objects::Location& from_here,
+ Callback<TaskReturnType()> task,
+ Callback<void(ReplyArgType)> reply) {
+ return PostTaskAndReplyWithResult(
+ task_runner, from_here,
+ static_cast<OnceCallback<TaskReturnType()>>(std::move(task)),
+ static_cast<OnceCallback<void(ReplyArgType)>>(std::move(reply)));
}
} // namespace base
« no previous file with comments | « no previous file | components/drive/chromeos/change_list_loader.cc » ('j') | content/public/browser/browser_thread.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698