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

Unified Diff: content/renderer/categorized_worker_pool.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: content/renderer/categorized_worker_pool.cc
diff --git a/content/renderer/categorized_worker_pool.cc b/content/renderer/categorized_worker_pool.cc
index 8873ad196bab77bfbdd912d430a6d6ad73dc3258..7b46aae0ce820513726a06ea09dc13f0d7dcf933 100644
--- a/content/renderer/categorized_worker_pool.cc
+++ b/content/renderer/categorized_worker_pool.cc
@@ -8,6 +8,7 @@
#include <utility>
#include <vector>
+#include "base/callback_helpers.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"
#include "base/trace_event/trace_event.h"
@@ -53,15 +54,15 @@ class CategorizedWorkerPool::CategorizedWorkerPoolSequencedTaskRunner
// Overridden from base::TaskRunner:
bool PostDelayedTask(const tracked_objects::Location& from_here,
- const base::Closure& task,
+ base::Closure task,
base::TimeDelta delay) override {
- return PostNonNestableDelayedTask(from_here, task, delay);
+ return PostNonNestableDelayedTask(from_here, std::move(task), delay);
}
bool RunsTasksOnCurrentThread() const override { return true; }
// Overridden from base::SequencedTaskRunner:
bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
- const base::Closure& task,
+ base::Closure task,
base::TimeDelta delay) override {
base::AutoLock lock(lock_);
@@ -72,7 +73,7 @@ class CategorizedWorkerPool::CategorizedWorkerPoolSequencedTaskRunner
tasks_.erase(tasks_.begin(), tasks_.begin() + completed_tasks_.size());
- tasks_.push_back(make_scoped_refptr(new ClosureTask(task)));
+ tasks_.push_back(make_scoped_refptr(new ClosureTask(std::move(task))));
graph_.Reset();
for (const auto& graph_task : tasks_) {
int dependencies = 0;
@@ -186,7 +187,7 @@ void CategorizedWorkerPool::Shutdown() {
// Overridden from base::TaskRunner:
bool CategorizedWorkerPool::PostDelayedTask(
const tracked_objects::Location& from_here,
- const base::Closure& task,
+ base::Closure task,
base::TimeDelta delay) {
base::AutoLock lock(lock_);
@@ -202,7 +203,7 @@ bool CategorizedWorkerPool::PostDelayedTask(
});
tasks_.erase(end, tasks_.end());
- tasks_.push_back(make_scoped_refptr(new ClosureTask(task)));
+ tasks_.push_back(make_scoped_refptr(new ClosureTask(std::move(task))));
graph_.Reset();
for (const auto& graph_task : tasks_) {
// Delayed tasks are assigned FOREGROUND category, ensuring that they run as
@@ -414,13 +415,12 @@ void CategorizedWorkerPool::SignalHasReadyToRunTasksWithLockAcquired() {
}
}
-CategorizedWorkerPool::ClosureTask::ClosureTask(const base::Closure& closure)
- : closure_(closure) {}
+CategorizedWorkerPool::ClosureTask::ClosureTask(base::Closure closure)
+ : closure_(std::move(closure)) {}
// Overridden from cc::Task:
void CategorizedWorkerPool::ClosureTask::RunOnWorkerThread() {
- closure_.Run();
- closure_.Reset();
+ std::move(closure_).Run();
}
CategorizedWorkerPool::ClosureTask::~ClosureTask() {}

Powered by Google App Engine
This is Rietveld 408576698