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 #ifndef BASE_TASK_THREAD_POOL_POOLED_SEQUENCED_TASK_RUNNER_H_ 6 #define BASE_TASK_THREAD_POOL_POOLED_SEQUENCED_TASK_RUNNER_H_ 7 8 #include "base/base_export.h" 9 #include "base/functional/callback_forward.h" 10 #include "base/location.h" 11 #include "base/memory/raw_ptr.h" 12 #include "base/task/task_traits.h" 13 #include "base/task/thread_pool/pooled_task_runner_delegate.h" 14 #include "base/task/thread_pool/sequence.h" 15 #include "base/task/updateable_sequenced_task_runner.h" 16 #include "base/time/time.h" 17 18 namespace base { 19 namespace internal { 20 21 // A task runner that runs tasks in sequence. 22 class BASE_EXPORT PooledSequencedTaskRunner 23 : public UpdateableSequencedTaskRunner { 24 public: 25 // Constructs a PooledSequencedTaskRunner which can be used to post tasks. 26 PooledSequencedTaskRunner( 27 const TaskTraits& traits, 28 PooledTaskRunnerDelegate* pooled_task_runner_delegate); 29 PooledSequencedTaskRunner(const PooledSequencedTaskRunner&) = delete; 30 PooledSequencedTaskRunner& operator=(const PooledSequencedTaskRunner&) = 31 delete; 32 33 // UpdateableSequencedTaskRunner: 34 bool PostDelayedTask(const Location& from_here, 35 OnceClosure closure, 36 TimeDelta delay) override; 37 38 bool PostDelayedTaskAt(subtle::PostDelayedTaskPassKey, 39 const Location& from_here, 40 OnceClosure closure, 41 TimeTicks delayed_run_time, 42 subtle::DelayPolicy delay_policy) override; 43 44 bool PostNonNestableDelayedTask(const Location& from_here, 45 OnceClosure closure, 46 TimeDelta delay) override; 47 48 bool RunsTasksInCurrentSequence() const override; 49 50 void UpdatePriority(TaskPriority priority) override; 51 52 private: 53 ~PooledSequencedTaskRunner() override; 54 55 // Dangling usage guarded by MatchesCurrentDelegate() checks. 56 const raw_ptr<PooledTaskRunnerDelegate, DisableDanglingPtrDetection> 57 pooled_task_runner_delegate_; 58 59 // Sequence for all Tasks posted through this TaskRunner. 60 const scoped_refptr<Sequence> sequence_; 61 }; 62 63 } // namespace internal 64 } // namespace base 65 66 #endif // BASE_TASK_THREAD_POOL_POOLED_SEQUENCED_TASK_RUNNER_H_ 67