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

Unified Diff: base/task_runner_util.h

Issue 2842493004: Add OnceCallback support to PostTaskAndReplyWithResult (Closed)
Patch Set: s/can not/cannot/ 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
« no previous file with comments | « no previous file | components/drive/chromeos/change_list_loader.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 9196bf17a16f88e9992b48259ea0e22b8e0b51f8..e046f4537c2cb1a31b7aee8b86163e93cedbb77d 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 cannot use template deduction and object conversion at once on the
+// overload resolution.
+// TODO(crbug.com/714018): 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, OnceCallback<TaskReturnType()>(std::move(task)),
+ OnceCallback<void(ReplyArgType)>(std::move(reply)));
}
} // namespace base
« no previous file with comments | « no previous file | components/drive/chromeos/change_list_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698