sequenced_task_source.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2018 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_TASK_SEQUENCE_MANAGER_SEQUENCED_TASK_SOURCE_H_
  5. #define BASE_TASK_SEQUENCE_MANAGER_SEQUENCED_TASK_SOURCE_H_
  6. #include "base/optional.h"
  7. #include "base/pending_task.h"
  8. #include "base/task/sequence_manager/lazy_now.h"
  9. #include "base/task/sequence_manager/tasks.h"
  10. namespace base {
  11. namespace sequence_manager {
  12. namespace internal {
  13. // Interface to pass tasks to ThreadController.
  14. class SequencedTaskSource {
  15. public:
  16. enum class SelectTaskOption { kDefault, kSkipDelayedTask };
  17. virtual ~SequencedTaskSource() = default;
  18. // Returns the next task to run from this source or nullptr if
  19. // there're no more tasks ready to run. If a task is returned,
  20. // DidRunTask() must be invoked before the next call to SelectNextTask().
  21. // |option| allows control on which kind of tasks can be selected.
  22. virtual Task* SelectNextTask(
  23. SelectTaskOption option = SelectTaskOption::kDefault) = 0;
  24. // Notifies this source that the task previously obtained
  25. // from SelectNextTask() has been completed.
  26. virtual void DidRunTask() = 0;
  27. // Returns the delay till the next task or TimeDelta::Max()
  28. // if there are no tasks left. |option| allows control on which kind of tasks
  29. // can be selected.
  30. virtual TimeDelta DelayTillNextTask(
  31. LazyNow* lazy_now,
  32. SelectTaskOption option = SelectTaskOption::kDefault) const = 0;
  33. // Return true if there are any pending tasks in the task source which require
  34. // high resolution timing.
  35. virtual bool HasPendingHighResolutionTasks() = 0;
  36. // Called when we have run out of immediate work. If more immediate work
  37. // becomes available as a result of any processing done by this callback,
  38. // return true to schedule a future DoWork.
  39. virtual bool OnSystemIdle() = 0;
  40. };
  41. } // namespace internal
  42. } // namespace sequence_manager
  43. } // namespace base
  44. #endif // BASE_TASK_SEQUENCE_MANAGER_SEQUENCED_TASK_SOURCE_H_