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

Side by Side Diff: base/threading/sequenced_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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/threading/sequenced_worker_pool.h" 5 #include "base/threading/sequenced_worker_pool.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <set> 12 #include <set>
13 #include <unordered_map> 13 #include <unordered_map>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/atomic_sequence_num.h" 17 #include "base/atomic_sequence_num.h"
18 #include "base/callback.h" 18 #include "base/callback.h"
19 #include "base/callback_helpers.h"
19 #include "base/compiler_specific.h" 20 #include "base/compiler_specific.h"
20 #include "base/critical_closure.h" 21 #include "base/critical_closure.h"
21 #include "base/debug/dump_without_crashing.h" 22 #include "base/debug/dump_without_crashing.h"
22 #include "base/lazy_instance.h" 23 #include "base/lazy_instance.h"
23 #include "base/logging.h" 24 #include "base/logging.h"
24 #include "base/macros.h" 25 #include "base/macros.h"
25 #include "base/memory/ptr_util.h" 26 #include "base/memory/ptr_util.h"
26 #include "base/stl_util.h" 27 #include "base/stl_util.h"
27 #include "base/strings/stringprintf.h" 28 #include "base/strings/stringprintf.h"
28 #include "base/synchronization/condition_variable.h" 29 #include "base/synchronization/condition_variable.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // 134 //
134 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner). 135 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner).
135 class SequencedWorkerPoolTaskRunner : public TaskRunner { 136 class SequencedWorkerPoolTaskRunner : public TaskRunner {
136 public: 137 public:
137 SequencedWorkerPoolTaskRunner( 138 SequencedWorkerPoolTaskRunner(
138 scoped_refptr<SequencedWorkerPool> pool, 139 scoped_refptr<SequencedWorkerPool> pool,
139 SequencedWorkerPool::WorkerShutdown shutdown_behavior); 140 SequencedWorkerPool::WorkerShutdown shutdown_behavior);
140 141
141 // TaskRunner implementation 142 // TaskRunner implementation
142 bool PostDelayedTask(const tracked_objects::Location& from_here, 143 bool PostDelayedTask(const tracked_objects::Location& from_here,
143 const Closure& task, 144 Closure task,
144 TimeDelta delay) override; 145 TimeDelta delay) override;
145 bool RunsTasksOnCurrentThread() const override; 146 bool RunsTasksOnCurrentThread() const override;
146 147
147 private: 148 private:
148 ~SequencedWorkerPoolTaskRunner() override; 149 ~SequencedWorkerPoolTaskRunner() override;
149 150
150 const scoped_refptr<SequencedWorkerPool> pool_; 151 const scoped_refptr<SequencedWorkerPool> pool_;
151 152
152 const SequencedWorkerPool::WorkerShutdown shutdown_behavior_; 153 const SequencedWorkerPool::WorkerShutdown shutdown_behavior_;
153 154
154 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolTaskRunner); 155 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolTaskRunner);
155 }; 156 };
156 157
157 SequencedWorkerPoolTaskRunner::SequencedWorkerPoolTaskRunner( 158 SequencedWorkerPoolTaskRunner::SequencedWorkerPoolTaskRunner(
158 scoped_refptr<SequencedWorkerPool> pool, 159 scoped_refptr<SequencedWorkerPool> pool,
159 SequencedWorkerPool::WorkerShutdown shutdown_behavior) 160 SequencedWorkerPool::WorkerShutdown shutdown_behavior)
160 : pool_(std::move(pool)), shutdown_behavior_(shutdown_behavior) {} 161 : pool_(std::move(pool)), shutdown_behavior_(shutdown_behavior) {}
161 162
162 SequencedWorkerPoolTaskRunner::~SequencedWorkerPoolTaskRunner() { 163 SequencedWorkerPoolTaskRunner::~SequencedWorkerPoolTaskRunner() {
163 } 164 }
164 165
165 bool SequencedWorkerPoolTaskRunner::PostDelayedTask( 166 bool SequencedWorkerPoolTaskRunner::PostDelayedTask(
166 const tracked_objects::Location& from_here, 167 const tracked_objects::Location& from_here,
167 const Closure& task, 168 Closure task,
168 TimeDelta delay) { 169 TimeDelta delay) {
169 if (delay.is_zero()) { 170 if (delay.is_zero()) {
170 return pool_->PostWorkerTaskWithShutdownBehavior( 171 return pool_->PostWorkerTaskWithShutdownBehavior(from_here, std::move(task),
171 from_here, task, shutdown_behavior_); 172 shutdown_behavior_);
172 } 173 }
173 return pool_->PostDelayedWorkerTask(from_here, task, delay); 174 return pool_->PostDelayedWorkerTask(from_here, std::move(task), delay);
174 } 175 }
175 176
176 bool SequencedWorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { 177 bool SequencedWorkerPoolTaskRunner::RunsTasksOnCurrentThread() const {
177 return pool_->RunsTasksOnCurrentThread(); 178 return pool_->RunsTasksOnCurrentThread();
178 } 179 }
179 180
180 } // namespace 181 } // namespace
181 182
182 // SequencedWorkerPool::PoolSequencedTaskRunner ------------------------------ 183 // SequencedWorkerPool::PoolSequencedTaskRunner ------------------------------
183 // A SequencedTaskRunner which posts tasks to a SequencedWorkerPool with a 184 // A SequencedTaskRunner which posts tasks to a SequencedWorkerPool with a
184 // fixed sequence token. 185 // fixed sequence token.
185 // 186 //
186 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner). 187 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner).
187 class SequencedWorkerPool::PoolSequencedTaskRunner 188 class SequencedWorkerPool::PoolSequencedTaskRunner
188 : public SequencedTaskRunner { 189 : public SequencedTaskRunner {
189 public: 190 public:
190 PoolSequencedTaskRunner( 191 PoolSequencedTaskRunner(
191 scoped_refptr<SequencedWorkerPool> pool, 192 scoped_refptr<SequencedWorkerPool> pool,
192 SequencedWorkerPool::SequenceToken token, 193 SequencedWorkerPool::SequenceToken token,
193 SequencedWorkerPool::WorkerShutdown shutdown_behavior); 194 SequencedWorkerPool::WorkerShutdown shutdown_behavior);
194 195
195 // TaskRunner implementation 196 // TaskRunner implementation
196 bool PostDelayedTask(const tracked_objects::Location& from_here, 197 bool PostDelayedTask(const tracked_objects::Location& from_here,
197 const Closure& task, 198 Closure task,
198 TimeDelta delay) override; 199 TimeDelta delay) override;
199 bool RunsTasksOnCurrentThread() const override; 200 bool RunsTasksOnCurrentThread() const override;
200 201
201 // SequencedTaskRunner implementation 202 // SequencedTaskRunner implementation
202 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 203 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
203 const Closure& task, 204 Closure task,
204 TimeDelta delay) override; 205 TimeDelta delay) override;
205 206
206 private: 207 private:
207 ~PoolSequencedTaskRunner() override; 208 ~PoolSequencedTaskRunner() override;
208 209
209 const scoped_refptr<SequencedWorkerPool> pool_; 210 const scoped_refptr<SequencedWorkerPool> pool_;
210 211
211 const SequencedWorkerPool::SequenceToken token_; 212 const SequencedWorkerPool::SequenceToken token_;
212 213
213 const SequencedWorkerPool::WorkerShutdown shutdown_behavior_; 214 const SequencedWorkerPool::WorkerShutdown shutdown_behavior_;
214 215
215 DISALLOW_COPY_AND_ASSIGN(PoolSequencedTaskRunner); 216 DISALLOW_COPY_AND_ASSIGN(PoolSequencedTaskRunner);
216 }; 217 };
217 218
218 SequencedWorkerPool::PoolSequencedTaskRunner:: 219 SequencedWorkerPool::PoolSequencedTaskRunner::
219 PoolSequencedTaskRunner( 220 PoolSequencedTaskRunner(
220 scoped_refptr<SequencedWorkerPool> pool, 221 scoped_refptr<SequencedWorkerPool> pool,
221 SequencedWorkerPool::SequenceToken token, 222 SequencedWorkerPool::SequenceToken token,
222 SequencedWorkerPool::WorkerShutdown shutdown_behavior) 223 SequencedWorkerPool::WorkerShutdown shutdown_behavior)
223 : pool_(std::move(pool)), 224 : pool_(std::move(pool)),
224 token_(token), 225 token_(token),
225 shutdown_behavior_(shutdown_behavior) {} 226 shutdown_behavior_(shutdown_behavior) {}
226 227
227 SequencedWorkerPool::PoolSequencedTaskRunner:: 228 SequencedWorkerPool::PoolSequencedTaskRunner::
228 ~PoolSequencedTaskRunner() = default; 229 ~PoolSequencedTaskRunner() = default;
229 230
230 bool SequencedWorkerPool::PoolSequencedTaskRunner:: 231 bool SequencedWorkerPool::PoolSequencedTaskRunner::PostDelayedTask(
231 PostDelayedTask(const tracked_objects::Location& from_here, 232 const tracked_objects::Location& from_here,
232 const Closure& task, 233 Closure task,
233 TimeDelta delay) { 234 TimeDelta delay) {
234 if (delay.is_zero()) { 235 if (delay.is_zero()) {
235 return pool_->PostSequencedWorkerTaskWithShutdownBehavior( 236 return pool_->PostSequencedWorkerTaskWithShutdownBehavior(
236 token_, from_here, task, shutdown_behavior_); 237 token_, from_here, std::move(task), shutdown_behavior_);
237 } 238 }
238 return pool_->PostDelayedSequencedWorkerTask(token_, from_here, task, delay); 239 return pool_->PostDelayedSequencedWorkerTask(token_, from_here,
240 std::move(task), delay);
239 } 241 }
240 242
241 bool SequencedWorkerPool::PoolSequencedTaskRunner:: 243 bool SequencedWorkerPool::PoolSequencedTaskRunner::
242 RunsTasksOnCurrentThread() const { 244 RunsTasksOnCurrentThread() const {
243 return pool_->IsRunningSequenceOnCurrentThread(token_); 245 return pool_->IsRunningSequenceOnCurrentThread(token_);
244 } 246 }
245 247
246 bool SequencedWorkerPool::PoolSequencedTaskRunner:: 248 bool SequencedWorkerPool::PoolSequencedTaskRunner::PostNonNestableDelayedTask(
247 PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 249 const tracked_objects::Location& from_here,
248 const Closure& task, 250 Closure task,
249 TimeDelta delay) { 251 TimeDelta delay) {
250 // There's no way to run nested tasks, so simply forward to 252 // There's no way to run nested tasks, so simply forward to
251 // PostDelayedTask. 253 // PostDelayedTask.
252 return PostDelayedTask(from_here, task, delay); 254 return PostDelayedTask(from_here, std::move(task), delay);
253 } 255 }
254 256
255 // Worker --------------------------------------------------------------------- 257 // Worker ---------------------------------------------------------------------
256 258
257 class SequencedWorkerPool::Worker : public SimpleThread { 259 class SequencedWorkerPool::Worker : public SimpleThread {
258 public: 260 public:
259 // Hold a (cyclic) ref to |worker_pool|, since we want to keep it 261 // Hold a (cyclic) ref to |worker_pool|, since we want to keep it
260 // around as long as we are running. 262 // around as long as we are running.
261 Worker(scoped_refptr<SequencedWorkerPool> worker_pool, 263 Worker(scoped_refptr<SequencedWorkerPool> worker_pool,
262 int thread_number, 264 int thread_number,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 343
342 SequenceToken GetNamedSequenceToken(const std::string& name); 344 SequenceToken GetNamedSequenceToken(const std::string& name);
343 345
344 // This function accepts a name and an ID. If the name is null, the 346 // This function accepts a name and an ID. If the name is null, the
345 // token ID is used. This allows us to implement the optional name lookup 347 // token ID is used. This allows us to implement the optional name lookup
346 // from a single function without having to enter the lock a separate time. 348 // from a single function without having to enter the lock a separate time.
347 bool PostTask(const std::string* optional_token_name, 349 bool PostTask(const std::string* optional_token_name,
348 SequenceToken sequence_token, 350 SequenceToken sequence_token,
349 WorkerShutdown shutdown_behavior, 351 WorkerShutdown shutdown_behavior,
350 const tracked_objects::Location& from_here, 352 const tracked_objects::Location& from_here,
351 const Closure& task, 353 Closure task,
352 TimeDelta delay); 354 TimeDelta delay);
353 355
354 bool RunsTasksOnCurrentThread() const; 356 bool RunsTasksOnCurrentThread() const;
355 357
356 bool IsRunningSequenceOnCurrentThread(SequenceToken sequence_token) const; 358 bool IsRunningSequenceOnCurrentThread(SequenceToken sequence_token) const;
357 359
358 void CleanupForTesting(); 360 void CleanupForTesting();
359 361
360 void SignalHasWorkForTesting(); 362 void SignalHasWorkForTesting();
361 363
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 SequencedWorkerPool::Inner::GetNamedSequenceToken(const std::string& name) { 687 SequencedWorkerPool::Inner::GetNamedSequenceToken(const std::string& name) {
686 AutoLock lock(lock_); 688 AutoLock lock(lock_);
687 return SequenceToken(LockedGetNamedTokenID(name)); 689 return SequenceToken(LockedGetNamedTokenID(name));
688 } 690 }
689 691
690 bool SequencedWorkerPool::Inner::PostTask( 692 bool SequencedWorkerPool::Inner::PostTask(
691 const std::string* optional_token_name, 693 const std::string* optional_token_name,
692 SequenceToken sequence_token, 694 SequenceToken sequence_token,
693 WorkerShutdown shutdown_behavior, 695 WorkerShutdown shutdown_behavior,
694 const tracked_objects::Location& from_here, 696 const tracked_objects::Location& from_here,
695 const Closure& task, 697 Closure task,
696 TimeDelta delay) { 698 TimeDelta delay) {
697 // TODO(fdoray): Uncomment this DCHECK. It is initially commented to avoid a 699 // TODO(fdoray): Uncomment this DCHECK. It is initially commented to avoid a
698 // revert of the CL that adds debug::DumpWithoutCrashing() if it fails on the 700 // revert of the CL that adds debug::DumpWithoutCrashing() if it fails on the
699 // waterfall. https://crbug.com/622400 701 // waterfall. https://crbug.com/622400
700 // DCHECK_NE(AllPoolsState::POST_TASK_DISABLED, g_all_pools_state); 702 // DCHECK_NE(AllPoolsState::POST_TASK_DISABLED, g_all_pools_state);
701 if (g_all_pools_state == AllPoolsState::POST_TASK_DISABLED) 703 if (g_all_pools_state == AllPoolsState::POST_TASK_DISABLED)
702 debug::DumpWithoutCrashing(); 704 debug::DumpWithoutCrashing();
703 705
704 DCHECK(delay.is_zero() || shutdown_behavior == SKIP_ON_SHUTDOWN); 706 DCHECK(delay.is_zero() || shutdown_behavior == SKIP_ON_SHUTDOWN);
705 SequencedTask sequenced(from_here); 707 SequencedTask sequenced(from_here);
706 sequenced.sequence_token_id = sequence_token.id_; 708 sequenced.sequence_token_id = sequence_token.id_;
707 sequenced.shutdown_behavior = shutdown_behavior; 709 sequenced.shutdown_behavior = shutdown_behavior;
708 sequenced.posted_from = from_here; 710 sequenced.posted_from = from_here;
709 sequenced.task = 711 sequenced.task = shutdown_behavior == BLOCK_SHUTDOWN
710 shutdown_behavior == BLOCK_SHUTDOWN ? 712 ? base::MakeCriticalClosure(std::move(task))
711 base::MakeCriticalClosure(task) : task; 713 : std::move(task);
712 sequenced.time_to_run = TimeTicks::Now() + delay; 714 sequenced.time_to_run = TimeTicks::Now() + delay;
713 715
714 int create_thread_id = 0; 716 int create_thread_id = 0;
715 { 717 {
716 AutoLock lock(lock_); 718 AutoLock lock(lock_);
717 719
718 if (shutdown_called_) { 720 if (shutdown_called_) {
719 // Don't allow a new task to be posted if it doesn't block shutdown. 721 // Don't allow a new task to be posted if it doesn't block shutdown.
720 if (shutdown_behavior != BLOCK_SHUTDOWN) 722 if (shutdown_behavior != BLOCK_SHUTDOWN)
721 return false; 723 return false;
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 1013
1012 // Complete thread creation outside the lock if necessary. 1014 // Complete thread creation outside the lock if necessary.
1013 if (new_thread_id) 1015 if (new_thread_id)
1014 FinishStartingAdditionalThread(new_thread_id); 1016 FinishStartingAdditionalThread(new_thread_id);
1015 1017
1016 this_worker->set_running_task_info( 1018 this_worker->set_running_task_info(
1017 SequenceToken(task.sequence_token_id), task.shutdown_behavior); 1019 SequenceToken(task.sequence_token_id), task.shutdown_behavior);
1018 1020
1019 tracked_objects::TaskStopwatch stopwatch; 1021 tracked_objects::TaskStopwatch stopwatch;
1020 stopwatch.Start(); 1022 stopwatch.Start();
1021 task.task.Run(); 1023 std::move(task.task).Run();
1022 stopwatch.Stop(); 1024 stopwatch.Stop();
1023 1025
1024 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking( 1026 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(
1025 task, stopwatch); 1027 task, stopwatch);
1026 1028
1027 // Make sure our task is erased outside the lock for the 1029 // Make sure our task is erased outside the lock for the
1028 // same reason we do this with delete_these_oustide_lock. 1030 // same reason we do this with delete_these_oustide_lock.
1029 // Also, do it before calling reset_running_task_info() so 1031 // Also, do it before calling reset_running_task_info() so
1030 // that sequence-checking from within the task's destructor 1032 // that sequence-checking from within the task's destructor
1031 // still works. 1033 // still works.
1032 task.task = Closure(); 1034 DCHECK(!task.task);
1033 1035
1034 this_worker->reset_running_task_info(); 1036 this_worker->reset_running_task_info();
1035 } 1037 }
1036 DidRunWorkerTask(task); // Must be done inside the lock. 1038 DidRunWorkerTask(task); // Must be done inside the lock.
1037 } else if (cleanup_state_ == CLEANUP_RUNNING) { 1039 } else if (cleanup_state_ == CLEANUP_RUNNING) {
1038 switch (status) { 1040 switch (status) {
1039 case GET_WORK_WAIT: { 1041 case GET_WORK_WAIT: {
1040 AutoUnlock unlock(lock_); 1042 AutoUnlock unlock(lock_);
1041 DeleteWithoutLock(&delete_these_outside_lock, this_worker); 1043 DeleteWithoutLock(&delete_these_outside_lock, this_worker);
1042 } 1044 }
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 } 1527 }
1526 1528
1527 scoped_refptr<TaskRunner> 1529 scoped_refptr<TaskRunner>
1528 SequencedWorkerPool::GetTaskRunnerWithShutdownBehavior( 1530 SequencedWorkerPool::GetTaskRunnerWithShutdownBehavior(
1529 WorkerShutdown shutdown_behavior) { 1531 WorkerShutdown shutdown_behavior) {
1530 return new SequencedWorkerPoolTaskRunner(this, shutdown_behavior); 1532 return new SequencedWorkerPoolTaskRunner(this, shutdown_behavior);
1531 } 1533 }
1532 1534
1533 bool SequencedWorkerPool::PostWorkerTask( 1535 bool SequencedWorkerPool::PostWorkerTask(
1534 const tracked_objects::Location& from_here, 1536 const tracked_objects::Location& from_here,
1535 const Closure& task) { 1537 Closure task) {
1536 return inner_->PostTask(NULL, SequenceToken(), BLOCK_SHUTDOWN, 1538 return inner_->PostTask(NULL, SequenceToken(), BLOCK_SHUTDOWN, from_here,
1537 from_here, task, TimeDelta()); 1539 std::move(task), TimeDelta());
1538 } 1540 }
1539 1541
1540 bool SequencedWorkerPool::PostDelayedWorkerTask( 1542 bool SequencedWorkerPool::PostDelayedWorkerTask(
1541 const tracked_objects::Location& from_here, 1543 const tracked_objects::Location& from_here,
1542 const Closure& task, 1544 Closure task,
1543 TimeDelta delay) { 1545 TimeDelta delay) {
1544 WorkerShutdown shutdown_behavior = 1546 WorkerShutdown shutdown_behavior =
1545 delay.is_zero() ? BLOCK_SHUTDOWN : SKIP_ON_SHUTDOWN; 1547 delay.is_zero() ? BLOCK_SHUTDOWN : SKIP_ON_SHUTDOWN;
1546 return inner_->PostTask(NULL, SequenceToken(), shutdown_behavior, 1548 return inner_->PostTask(NULL, SequenceToken(), shutdown_behavior, from_here,
1547 from_here, task, delay); 1549 std::move(task), delay);
1548 } 1550 }
1549 1551
1550 bool SequencedWorkerPool::PostWorkerTaskWithShutdownBehavior( 1552 bool SequencedWorkerPool::PostWorkerTaskWithShutdownBehavior(
1551 const tracked_objects::Location& from_here, 1553 const tracked_objects::Location& from_here,
1552 const Closure& task, 1554 Closure task,
1553 WorkerShutdown shutdown_behavior) { 1555 WorkerShutdown shutdown_behavior) {
1554 return inner_->PostTask(NULL, SequenceToken(), shutdown_behavior, 1556 return inner_->PostTask(NULL, SequenceToken(), shutdown_behavior, from_here,
1555 from_here, task, TimeDelta()); 1557 std::move(task), TimeDelta());
1556 } 1558 }
1557 1559
1558 bool SequencedWorkerPool::PostSequencedWorkerTask( 1560 bool SequencedWorkerPool::PostSequencedWorkerTask(
1559 SequenceToken sequence_token, 1561 SequenceToken sequence_token,
1560 const tracked_objects::Location& from_here, 1562 const tracked_objects::Location& from_here,
1561 const Closure& task) { 1563 Closure task) {
1562 return inner_->PostTask(NULL, sequence_token, BLOCK_SHUTDOWN, 1564 return inner_->PostTask(NULL, sequence_token, BLOCK_SHUTDOWN, from_here,
1563 from_here, task, TimeDelta()); 1565 std::move(task), TimeDelta());
1564 } 1566 }
1565 1567
1566 bool SequencedWorkerPool::PostDelayedSequencedWorkerTask( 1568 bool SequencedWorkerPool::PostDelayedSequencedWorkerTask(
1567 SequenceToken sequence_token, 1569 SequenceToken sequence_token,
1568 const tracked_objects::Location& from_here, 1570 const tracked_objects::Location& from_here,
1569 const Closure& task, 1571 Closure task,
1570 TimeDelta delay) { 1572 TimeDelta delay) {
1571 WorkerShutdown shutdown_behavior = 1573 WorkerShutdown shutdown_behavior =
1572 delay.is_zero() ? BLOCK_SHUTDOWN : SKIP_ON_SHUTDOWN; 1574 delay.is_zero() ? BLOCK_SHUTDOWN : SKIP_ON_SHUTDOWN;
1573 return inner_->PostTask(NULL, sequence_token, shutdown_behavior, 1575 return inner_->PostTask(NULL, sequence_token, shutdown_behavior, from_here,
1574 from_here, task, delay); 1576 std::move(task), delay);
1575 } 1577 }
1576 1578
1577 bool SequencedWorkerPool::PostNamedSequencedWorkerTask( 1579 bool SequencedWorkerPool::PostNamedSequencedWorkerTask(
1578 const std::string& token_name, 1580 const std::string& token_name,
1579 const tracked_objects::Location& from_here, 1581 const tracked_objects::Location& from_here,
1580 const Closure& task) { 1582 Closure task) {
1581 DCHECK(!token_name.empty()); 1583 DCHECK(!token_name.empty());
1582 return inner_->PostTask(&token_name, SequenceToken(), BLOCK_SHUTDOWN, 1584 return inner_->PostTask(&token_name, SequenceToken(), BLOCK_SHUTDOWN,
1583 from_here, task, TimeDelta()); 1585 from_here, std::move(task), TimeDelta());
1584 } 1586 }
1585 1587
1586 bool SequencedWorkerPool::PostSequencedWorkerTaskWithShutdownBehavior( 1588 bool SequencedWorkerPool::PostSequencedWorkerTaskWithShutdownBehavior(
1587 SequenceToken sequence_token, 1589 SequenceToken sequence_token,
1588 const tracked_objects::Location& from_here, 1590 const tracked_objects::Location& from_here,
1589 const Closure& task, 1591 Closure task,
1590 WorkerShutdown shutdown_behavior) { 1592 WorkerShutdown shutdown_behavior) {
1591 return inner_->PostTask(NULL, sequence_token, shutdown_behavior, 1593 return inner_->PostTask(NULL, sequence_token, shutdown_behavior, from_here,
1592 from_here, task, TimeDelta()); 1594 std::move(task), TimeDelta());
1593 } 1595 }
1594 1596
1595 bool SequencedWorkerPool::PostDelayedTask( 1597 bool SequencedWorkerPool::PostDelayedTask(
1596 const tracked_objects::Location& from_here, 1598 const tracked_objects::Location& from_here,
1597 const Closure& task, 1599 Closure task,
1598 TimeDelta delay) { 1600 TimeDelta delay) {
1599 return PostDelayedWorkerTask(from_here, task, delay); 1601 return PostDelayedWorkerTask(from_here, std::move(task), delay);
1600 } 1602 }
1601 1603
1602 bool SequencedWorkerPool::RunsTasksOnCurrentThread() const { 1604 bool SequencedWorkerPool::RunsTasksOnCurrentThread() const {
1603 return inner_->RunsTasksOnCurrentThread(); 1605 return inner_->RunsTasksOnCurrentThread();
1604 } 1606 }
1605 1607
1606 void SequencedWorkerPool::FlushForTesting() { 1608 void SequencedWorkerPool::FlushForTesting() {
1607 DCHECK(!RunsTasksOnCurrentThread()); 1609 DCHECK(!RunsTasksOnCurrentThread());
1608 base::ThreadRestrictions::ScopedAllowWait allow_wait; 1610 base::ThreadRestrictions::ScopedAllowWait allow_wait;
1609 if (g_all_pools_state == AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER) { 1611 if (g_all_pools_state == AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER) {
(...skipping 16 matching lines...) Expand all
1626 bool SequencedWorkerPool::IsShutdownInProgress() { 1628 bool SequencedWorkerPool::IsShutdownInProgress() {
1627 return inner_->IsShutdownInProgress(); 1629 return inner_->IsShutdownInProgress();
1628 } 1630 }
1629 1631
1630 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( 1632 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread(
1631 SequenceToken sequence_token) const { 1633 SequenceToken sequence_token) const {
1632 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); 1634 return inner_->IsRunningSequenceOnCurrentThread(sequence_token);
1633 } 1635 }
1634 1636
1635 } // namespace base 1637 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698