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

Unified Diff: chrome/browser/after_startup_task_utils.cc

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: s/base::ResetAndReturn/std::move/ Created 3 years, 9 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: chrome/browser/after_startup_task_utils.cc
diff --git a/chrome/browser/after_startup_task_utils.cc b/chrome/browser/after_startup_task_utils.cc
index c5c29e8b8cb599f7305a2df9b0a82abce8dd1e7c..24bf700bdf5a1800a09e8fed12203e36d1e332c2 100644
--- a/chrome/browser/after_startup_task_utils.cc
+++ b/chrome/browser/after_startup_task_utils.cc
@@ -7,6 +7,7 @@
#include <memory>
#include <utility>
+#include "base/callback_helpers.h"
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
@@ -34,13 +35,13 @@ namespace {
struct AfterStartupTask {
AfterStartupTask(const tracked_objects::Location& from_here,
const scoped_refptr<base::TaskRunner>& task_runner,
- const base::Closure& task)
- : from_here(from_here), task_runner(task_runner), task(task) {}
+ base::Closure task)
+ : from_here(from_here), task_runner(task_runner), task(std::move(task)) {}
~AfterStartupTask() {}
const tracked_objects::Location from_here;
const scoped_refptr<base::TaskRunner> task_runner;
- const base::Closure task;
+ base::Closure task;
};
// The flag may be read on any thread, but must only be set on the UI thread.
@@ -60,7 +61,7 @@ bool IsBrowserStartupComplete() {
void RunTask(std::unique_ptr<AfterStartupTask> queued_task) {
// We're careful to delete the caller's |task| on the target runner's thread.
DCHECK(queued_task->task_runner->RunsTasksOnCurrentThread());
- queued_task->task.Run();
+ std::move(queued_task->task).Run();
sky 2017/03/22 17:34:11 Similar comment about needing std::move here.
}
void ScheduleTask(std::unique_ptr<AfterStartupTask> queued_task) {
@@ -202,10 +203,11 @@ AfterStartupTaskUtils::Runner::~Runner() = default;
bool AfterStartupTaskUtils::Runner::PostDelayedTask(
const tracked_objects::Location& from_here,
- const base::Closure& task,
+ base::Closure task,
base::TimeDelta delay) {
DCHECK(delay.is_zero());
- AfterStartupTaskUtils::PostTask(from_here, destination_runner_, task);
+ AfterStartupTaskUtils::PostTask(from_here, destination_runner_,
+ std::move(task));
return true;
}
@@ -221,14 +223,14 @@ void AfterStartupTaskUtils::StartMonitoringStartup() {
void AfterStartupTaskUtils::PostTask(
const tracked_objects::Location& from_here,
const scoped_refptr<base::TaskRunner>& destination_runner,
- const base::Closure& task) {
+ base::Closure task) {
if (IsBrowserStartupComplete()) {
- destination_runner->PostTask(from_here, task);
+ destination_runner->PostTask(from_here, std::move(task));
return;
}
std::unique_ptr<AfterStartupTask> queued_task(
- new AfterStartupTask(from_here, destination_runner, task));
+ new AfterStartupTask(from_here, destination_runner, std::move(task)));
QueueTask(std::move(queued_task));
}

Powered by Google App Engine
This is Rietveld 408576698