blob: c2107f0afade1d6383967c5dfcbc4ca5db51805c [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2015 The Chromium Authors
bauerb8a408722015-10-30 09:05:312// 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_THREADING_SEQUENCED_TASK_RUNNER_HANDLE_H_
6#define BASE_THREADING_SEQUENCED_TASK_RUNNER_HANDLE_H_
7
Gabriel Charetteb62806f4a2019-01-29 21:08:418#include "base/base_export.h"
Gabriel Charetteb62806f4a2019-01-29 21:08:419#include "base/memory/scoped_refptr.h"
Patrick Monette643cdf62021-10-15 19:13:4210#include "base/task/sequenced_task_runner.h"
bauerb8a408722015-10-30 09:05:3111
12namespace base {
13
Gabriel Charetteb62806f4a2019-01-29 21:08:4114class ThreadTaskRunnerHandle;
15
bauerb8a408722015-10-30 09:05:3116class BASE_EXPORT SequencedTaskRunnerHandle {
17 public:
18 // Returns a SequencedTaskRunner which guarantees that posted tasks will only
19 // run after the current task is finished and will satisfy a SequenceChecker.
20 // It should only be called if IsSet() returns true (see the comment there for
21 // the requirements).
Daniel Cheng4455c9842022-01-13 23:26:3722 [[nodiscard]] static const scoped_refptr<SequencedTaskRunner>& Get();
bauerb8a408722015-10-30 09:05:3123
24 // Returns true if one of the following conditions is fulfilled:
gaba8e9e2c2016-05-02 21:17:4725 // a) A SequencedTaskRunner has been assigned to the current thread by
26 // instantiating a SequencedTaskRunnerHandle.
27 // b) The current thread has a ThreadTaskRunnerHandle (which includes any
Francois Doray4914ec142018-02-22 12:48:3828 // thread that has a MessageLoop associated with it).
Daniel Cheng4455c9842022-01-13 23:26:3729 [[nodiscard]] static bool IsSet();
bauerb8a408722015-10-30 09:05:3130
gaba8e9e2c2016-05-02 21:17:4731 // Binds |task_runner| to the current thread.
32 explicit SequencedTaskRunnerHandle(
33 scoped_refptr<SequencedTaskRunner> task_runner);
Peter Boström7319bbd2021-09-15 22:59:3834
35 SequencedTaskRunnerHandle(const SequencedTaskRunnerHandle&) = delete;
36 SequencedTaskRunnerHandle& operator=(const SequencedTaskRunnerHandle&) =
37 delete;
38
gaba8e9e2c2016-05-02 21:17:4739 ~SequencedTaskRunnerHandle();
40
bauerb8a408722015-10-30 09:05:3141 private:
Minoru Chikamune76ba6822021-01-12 10:39:5142 friend class ThreadTaskRunnerHandleOverride;
Gabriel Charetteb62806f4a2019-01-29 21:08:4143
gaba8e9e2c2016-05-02 21:17:4744 scoped_refptr<SequencedTaskRunner> task_runner_;
bauerb8a408722015-10-30 09:05:3145};
46
47} // namespace base
48
49#endif // BASE_THREADING_SEQUENCED_TASK_RUNNER_HANDLE_H_