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 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
16 #include "base/synchronization/atomic_flag.h" | 17 #include "base/synchronization/atomic_flag.h" |
17 #include "base/task_scheduler/delayed_task_manager.h" | 18 #include "base/task_scheduler/delayed_task_manager.h" |
18 #include "base/task_scheduler/scheduler_worker.h" | 19 #include "base/task_scheduler/scheduler_worker.h" |
19 #include "base/task_scheduler/sequence.h" | 20 #include "base/task_scheduler/sequence.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 SchedulerSingleThreadTaskRunnerManager* const outer, | 141 SchedulerSingleThreadTaskRunnerManager* const outer, |
141 const TaskTraits& traits, | 142 const TaskTraits& traits, |
142 SchedulerWorker* worker) | 143 SchedulerWorker* worker) |
143 : outer_(outer), traits_(traits), worker_(worker) { | 144 : outer_(outer), traits_(traits), worker_(worker) { |
144 DCHECK(outer_); | 145 DCHECK(outer_); |
145 DCHECK(worker_); | 146 DCHECK(worker_); |
146 } | 147 } |
147 | 148 |
148 // SingleThreadTaskRunner: | 149 // SingleThreadTaskRunner: |
149 bool PostDelayedTask(const tracked_objects::Location& from_here, | 150 bool PostDelayedTask(const tracked_objects::Location& from_here, |
150 const Closure& closure, | 151 Closure closure, |
151 TimeDelta delay) override { | 152 TimeDelta delay) override { |
152 auto task = MakeUnique<Task>(from_here, closure, traits_, delay); | 153 auto task = MakeUnique<Task>(from_here, std::move(closure), traits_, delay); |
153 task->single_thread_task_runner_ref = this; | 154 task->single_thread_task_runner_ref = this; |
154 | 155 |
155 if (!outer_->task_tracker_->WillPostTask(task.get())) | 156 if (!outer_->task_tracker_->WillPostTask(task.get())) |
156 return false; | 157 return false; |
157 | 158 |
158 if (task->delayed_run_time.is_null()) { | 159 if (task->delayed_run_time.is_null()) { |
159 PostTaskNow(std::move(task)); | 160 PostTaskNow(std::move(task)); |
160 } else { | 161 } else { |
161 outer_->delayed_task_manager_->AddDelayedTask( | 162 outer_->delayed_task_manager_->AddDelayedTask( |
162 std::move(task), Bind(&SchedulerSingleThreadTaskRunner::PostTaskNow, | 163 std::move(task), Bind(&SchedulerSingleThreadTaskRunner::PostTaskNow, |
163 Unretained(this))); | 164 Unretained(this))); |
164 } | 165 } |
165 return true; | 166 return true; |
166 } | 167 } |
167 | 168 |
168 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 169 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
169 const Closure& closure, | 170 Closure closure, |
170 base::TimeDelta delay) override { | 171 base::TimeDelta delay) override { |
171 // Tasks are never nested within the task scheduler. | 172 // Tasks are never nested within the task scheduler. |
172 return PostDelayedTask(from_here, closure, delay); | 173 return PostDelayedTask(from_here, std::move(closure), delay); |
173 } | 174 } |
174 | 175 |
175 bool RunsTasksOnCurrentThread() const override { | 176 bool RunsTasksOnCurrentThread() const override { |
176 return GetDelegate()->RunsTasksOnCurrentThread(); | 177 return GetDelegate()->RunsTasksOnCurrentThread(); |
177 } | 178 } |
178 | 179 |
179 private: | 180 private: |
180 ~SchedulerSingleThreadTaskRunner() override { | 181 ~SchedulerSingleThreadTaskRunner() override { |
181 outer_->UnregisterSchedulerWorker(worker_); | 182 outer_->UnregisterSchedulerWorker(worker_); |
182 } | 183 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 }); | 300 }); |
300 DCHECK(worker_iter != workers_.end()); | 301 DCHECK(worker_iter != workers_.end()); |
301 worker_to_destroy = std::move(*worker_iter); | 302 worker_to_destroy = std::move(*worker_iter); |
302 workers_.erase(worker_iter); | 303 workers_.erase(worker_iter); |
303 } | 304 } |
304 worker_to_destroy->Cleanup(); | 305 worker_to_destroy->Cleanup(); |
305 } | 306 } |
306 | 307 |
307 } // namespace internal | 308 } // namespace internal |
308 } // namespace base | 309 } // namespace base |
OLD | NEW |