OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/task_scheduler/scheduler_single_thread_task_runner_manager.h" | 5 #include "base/task_scheduler/scheduler_single_thread_task_runner_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 SchedulerSingleThreadTaskRunnerManager* const outer, | 246 SchedulerSingleThreadTaskRunnerManager* const outer, |
247 const TaskTraits& traits, | 247 const TaskTraits& traits, |
248 SchedulerWorker* worker) | 248 SchedulerWorker* worker) |
249 : outer_(outer), traits_(traits), worker_(worker) { | 249 : outer_(outer), traits_(traits), worker_(worker) { |
250 DCHECK(outer_); | 250 DCHECK(outer_); |
251 DCHECK(worker_); | 251 DCHECK(worker_); |
252 } | 252 } |
253 | 253 |
254 // SingleThreadTaskRunner: | 254 // SingleThreadTaskRunner: |
255 bool PostDelayedTask(const tracked_objects::Location& from_here, | 255 bool PostDelayedTask(const tracked_objects::Location& from_here, |
256 const Closure& closure, | 256 Closure closure, |
257 TimeDelta delay) override { | 257 TimeDelta delay) override { |
258 auto task = MakeUnique<Task>(from_here, closure, traits_, delay); | 258 auto task = MakeUnique<Task>(from_here, std::move(closure), traits_, delay); |
259 task->single_thread_task_runner_ref = this; | 259 task->single_thread_task_runner_ref = this; |
260 | 260 |
261 if (!outer_->task_tracker_->WillPostTask(task.get())) | 261 if (!outer_->task_tracker_->WillPostTask(task.get())) |
262 return false; | 262 return false; |
263 | 263 |
264 if (task->delayed_run_time.is_null()) { | 264 if (task->delayed_run_time.is_null()) { |
265 PostTaskNow(std::move(task)); | 265 PostTaskNow(std::move(task)); |
266 } else { | 266 } else { |
267 outer_->delayed_task_manager_->AddDelayedTask( | 267 outer_->delayed_task_manager_->AddDelayedTask( |
268 std::move(task), Bind(&SchedulerSingleThreadTaskRunner::PostTaskNow, | 268 std::move(task), Bind(&SchedulerSingleThreadTaskRunner::PostTaskNow, |
269 Unretained(this))); | 269 Unretained(this))); |
270 } | 270 } |
271 return true; | 271 return true; |
272 } | 272 } |
273 | 273 |
274 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 274 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
275 const Closure& closure, | 275 Closure closure, |
276 TimeDelta delay) override { | 276 TimeDelta delay) override { |
277 // Tasks are never nested within the task scheduler. | 277 // Tasks are never nested within the task scheduler. |
278 return PostDelayedTask(from_here, closure, delay); | 278 return PostDelayedTask(from_here, std::move(closure), delay); |
279 } | 279 } |
280 | 280 |
281 bool RunsTasksOnCurrentThread() const override { | 281 bool RunsTasksOnCurrentThread() const override { |
282 return GetDelegate()->RunsTasksOnCurrentThread(); | 282 return GetDelegate()->RunsTasksOnCurrentThread(); |
283 } | 283 } |
284 | 284 |
285 private: | 285 private: |
286 ~SchedulerSingleThreadTaskRunner() override { | 286 ~SchedulerSingleThreadTaskRunner() override { |
287 outer_->UnregisterSchedulerWorker(worker_); | 287 outer_->UnregisterSchedulerWorker(worker_); |
288 } | 288 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 }); | 444 }); |
445 DCHECK(worker_iter != workers_.end()); | 445 DCHECK(worker_iter != workers_.end()); |
446 worker_to_destroy = std::move(*worker_iter); | 446 worker_to_destroy = std::move(*worker_iter); |
447 workers_.erase(worker_iter); | 447 workers_.erase(worker_iter); |
448 } | 448 } |
449 worker_to_destroy->Cleanup(); | 449 worker_to_destroy->Cleanup(); |
450 } | 450 } |
451 | 451 |
452 } // namespace internal | 452 } // namespace internal |
453 } // namespace base | 453 } // namespace base |
OLD | NEW |