sequenced_task_runner_handle.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_THREADING_SEQUENCED_TASK_RUNNER_HANDLE_H_
  5. #define BASE_THREADING_SEQUENCED_TASK_RUNNER_HANDLE_H_
  6. #include "base/base_export.h"
  7. #include "base/memory/scoped_refptr.h"
  8. #include "base/task/sequenced_task_runner.h"
  9. namespace base {
  10. class ThreadTaskRunnerHandle;
  11. class BASE_EXPORT SequencedTaskRunnerHandle {
  12. public:
  13. // Returns a SequencedTaskRunner which guarantees that posted tasks will only
  14. // run after the current task is finished and will satisfy a SequenceChecker.
  15. // It should only be called if IsSet() returns true (see the comment there for
  16. // the requirements).
  17. [[nodiscard]] static const scoped_refptr<SequencedTaskRunner>& Get();
  18. // Returns true if one of the following conditions is fulfilled:
  19. // a) A SequencedTaskRunner has been assigned to the current thread by
  20. // instantiating a SequencedTaskRunnerHandle.
  21. // b) The current thread has a ThreadTaskRunnerHandle (which includes any
  22. // thread that has a MessageLoop associated with it).
  23. [[nodiscard]] static bool IsSet();
  24. // Binds |task_runner| to the current thread.
  25. explicit SequencedTaskRunnerHandle(
  26. scoped_refptr<SequencedTaskRunner> task_runner);
  27. SequencedTaskRunnerHandle(const SequencedTaskRunnerHandle&) = delete;
  28. SequencedTaskRunnerHandle& operator=(const SequencedTaskRunnerHandle&) =
  29. delete;
  30. ~SequencedTaskRunnerHandle();
  31. private:
  32. friend class ThreadTaskRunnerHandleOverride;
  33. scoped_refptr<SequencedTaskRunner> task_runner_;
  34. };
  35. } // namespace base
  36. #endif // BASE_THREADING_SEQUENCED_TASK_RUNNER_HANDLE_H_