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/compiler_specific.h"
  8. #include "base/macros.h"
  9. #include "base/memory/scoped_refptr.h"
  10. #include "base/sequenced_task_runner.h"
  11. namespace base {
  12. class ThreadTaskRunnerHandle;
  13. class BASE_EXPORT SequencedTaskRunnerHandle {
  14. public:
  15. // Returns a SequencedTaskRunner which guarantees that posted tasks will only
  16. // run after the current task is finished and will satisfy a SequenceChecker.
  17. // It should only be called if IsSet() returns true (see the comment there for
  18. // the requirements).
  19. static const scoped_refptr<SequencedTaskRunner>& Get() WARN_UNUSED_RESULT;
  20. // Returns true if one of the following conditions is fulfilled:
  21. // a) A SequencedTaskRunner has been assigned to the current thread by
  22. // instantiating a SequencedTaskRunnerHandle.
  23. // b) The current thread has a ThreadTaskRunnerHandle (which includes any
  24. // thread that has a MessageLoop associated with it).
  25. static bool IsSet() WARN_UNUSED_RESULT;
  26. // Binds |task_runner| to the current thread.
  27. explicit SequencedTaskRunnerHandle(
  28. scoped_refptr<SequencedTaskRunner> task_runner);
  29. ~SequencedTaskRunnerHandle();
  30. private:
  31. // Friend needed for ThreadTaskRunnerHandle::OverrideForTesting().
  32. friend class ThreadTaskRunnerHandle;
  33. scoped_refptr<SequencedTaskRunner> task_runner_;
  34. DISALLOW_COPY_AND_ASSIGN(SequencedTaskRunnerHandle);
  35. };
  36. } // namespace base
  37. #endif // BASE_THREADING_SEQUENCED_TASK_RUNNER_HANDLE_H_