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

Unified Diff: base/deferred_sequenced_task_runner.cc

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: erase Closure* 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
« no previous file with comments | « base/deferred_sequenced_task_runner.h ('k') | base/message_loop/incoming_task_queue.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/deferred_sequenced_task_runner.cc
diff --git a/base/deferred_sequenced_task_runner.cc b/base/deferred_sequenced_task_runner.cc
index 7d09ef838cf37bc67137fa3549c0d77b01a01088..3811bdaa82103d648b15910fbcd0a6db93a83517 100644
--- a/base/deferred_sequenced_task_runner.cc
+++ b/base/deferred_sequenced_task_runner.cc
@@ -4,6 +4,8 @@
#include "base/deferred_sequenced_task_runner.h"
+#include <utility>
+
#include "base/bind.h"
#include "base/logging.h"
@@ -13,12 +15,16 @@ DeferredSequencedTaskRunner::DeferredTask::DeferredTask()
: is_non_nestable(false) {
}
-DeferredSequencedTaskRunner::DeferredTask::DeferredTask(
- const DeferredTask& other) = default;
+DeferredSequencedTaskRunner::DeferredTask::DeferredTask(DeferredTask&& other) =
+ default;
DeferredSequencedTaskRunner::DeferredTask::~DeferredTask() {
}
+DeferredSequencedTaskRunner::DeferredTask&
+DeferredSequencedTaskRunner::DeferredTask::operator=(DeferredTask&& other) =
+ default;
+
DeferredSequencedTaskRunner::DeferredSequencedTaskRunner(
scoped_refptr<SequencedTaskRunner> target_task_runner)
: started_(false), target_task_runner_(std::move(target_task_runner)) {}
@@ -28,15 +34,17 @@ DeferredSequencedTaskRunner::~DeferredSequencedTaskRunner() {
bool DeferredSequencedTaskRunner::PostDelayedTask(
const tracked_objects::Location& from_here,
- const Closure& task,
+ Closure task,
TimeDelta delay) {
AutoLock lock(lock_);
if (started_) {
DCHECK(deferred_tasks_queue_.empty());
- return target_task_runner_->PostDelayedTask(from_here, task, delay);
+ return target_task_runner_->PostDelayedTask(from_here, std::move(task),
+ delay);
}
- QueueDeferredTask(from_here, task, delay, false /* is_non_nestable */);
+ QueueDeferredTask(from_here, std::move(task), delay,
+ false /* is_non_nestable */);
return true;
}
@@ -46,33 +54,32 @@ bool DeferredSequencedTaskRunner::RunsTasksOnCurrentThread() const {
bool DeferredSequencedTaskRunner::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
- const Closure& task,
+ Closure task,
TimeDelta delay) {
AutoLock lock(lock_);
if (started_) {
DCHECK(deferred_tasks_queue_.empty());
- return target_task_runner_->PostNonNestableDelayedTask(from_here,
- task,
- delay);
+ return target_task_runner_->PostNonNestableDelayedTask(
+ from_here, std::move(task), delay);
}
- QueueDeferredTask(from_here, task, delay, true /* is_non_nestable */);
+ QueueDeferredTask(from_here, std::move(task), delay,
+ true /* is_non_nestable */);
return true;
}
void DeferredSequencedTaskRunner::QueueDeferredTask(
const tracked_objects::Location& from_here,
- const Closure& task,
+ Closure task,
TimeDelta delay,
bool is_non_nestable) {
DeferredTask deferred_task;
deferred_task.posted_from = from_here;
- deferred_task.task = task;
+ deferred_task.task = std::move(task);
deferred_task.delay = delay;
deferred_task.is_non_nestable = is_non_nestable;
- deferred_tasks_queue_.push_back(deferred_task);
+ deferred_tasks_queue_.push_back(std::move(deferred_task));
}
-
void DeferredSequencedTaskRunner::Start() {
AutoLock lock(lock_);
DCHECK(!started_);
@@ -80,20 +87,14 @@ void DeferredSequencedTaskRunner::Start() {
for (std::vector<DeferredTask>::iterator i = deferred_tasks_queue_.begin();
i != deferred_tasks_queue_.end();
++i) {
- const DeferredTask& task = *i;
+ DeferredTask& task = *i;
if (task.is_non_nestable) {
- target_task_runner_->PostNonNestableDelayedTask(task.posted_from,
- task.task,
- task.delay);
+ target_task_runner_->PostNonNestableDelayedTask(
+ task.posted_from, std::move(task.task), task.delay);
} else {
target_task_runner_->PostDelayedTask(task.posted_from,
- task.task,
- task.delay);
+ std::move(task.task), task.delay);
}
- // Replace the i-th element in the |deferred_tasks_queue_| with an empty
- // |DelayedTask| to ensure that |task| is destroyed before the next task
- // is posted.
- *i = DeferredTask();
}
deferred_tasks_queue_.clear();
}
« no previous file with comments | « base/deferred_sequenced_task_runner.h ('k') | base/message_loop/incoming_task_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698