xref: /aosp_15_r20/external/cronet/base/task/thread_pool/pooled_parallel_task_runner.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/task/thread_pool/pooled_parallel_task_runner.h"
6 #include "base/task/thread_pool/pooled_task_runner_delegate.h"
7 
8 #include "base/task/thread_pool/sequence.h"
9 
10 namespace base {
11 namespace internal {
12 
PooledParallelTaskRunner(const TaskTraits & traits,PooledTaskRunnerDelegate * pooled_task_runner_delegate)13 PooledParallelTaskRunner::PooledParallelTaskRunner(
14     const TaskTraits& traits,
15     PooledTaskRunnerDelegate* pooled_task_runner_delegate)
16     : traits_(traits),
17       pooled_task_runner_delegate_(pooled_task_runner_delegate) {}
18 
19 PooledParallelTaskRunner::~PooledParallelTaskRunner() = default;
20 
PostDelayedTask(const Location & from_here,OnceClosure closure,TimeDelta delay)21 bool PooledParallelTaskRunner::PostDelayedTask(const Location& from_here,
22                                                OnceClosure closure,
23                                                TimeDelta delay) {
24   if (!PooledTaskRunnerDelegate::MatchesCurrentDelegate(
25           pooled_task_runner_delegate_)) {
26     return false;
27   }
28 
29   // Post the task as part of a one-off single-task Sequence.
30   scoped_refptr<Sequence> sequence = MakeRefCounted<Sequence>(
31       traits_, nullptr, TaskSourceExecutionMode::kParallel);
32 
33   return pooled_task_runner_delegate_->PostTaskWithSequence(
34       Task(from_here, std::move(closure), TimeTicks::Now(), delay),
35       std::move(sequence));
36 }
37 
38 }  // namespace internal
39 }  // namespace base
40