bridge_task_runner.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2015 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_BRIDGE_TASK_RUNNER_H_
  5. #define ATOM_BROWSER_BRIDGE_TASK_RUNNER_H_
  6. #include <tuple>
  7. #include <vector>
  8. #include "base/location.h"
  9. #include "base/single_thread_task_runner.h"
  10. #include "base/tuple.h"
  11. namespace atom {
  12. // Post all tasks to the current message loop's task runner if available,
  13. // otherwise delay the work until message loop is ready.
  14. class BridgeTaskRunner : public base::SingleThreadTaskRunner {
  15. public:
  16. BridgeTaskRunner();
  17. // Called when message loop is ready.
  18. void MessageLoopIsReady();
  19. // base::SingleThreadTaskRunner:
  20. bool PostDelayedTask(const base::Location& from_here,
  21. base::OnceClosure task,
  22. base::TimeDelta delay) override;
  23. bool RunsTasksInCurrentSequence() const override;
  24. bool PostNonNestableDelayedTask(const base::Location& from_here,
  25. base::OnceClosure task,
  26. base::TimeDelta delay) override;
  27. private:
  28. using TaskPair =
  29. std::tuple<base::Location, base::OnceClosure, base::TimeDelta>;
  30. ~BridgeTaskRunner() override;
  31. std::vector<TaskPair> tasks_;
  32. std::vector<TaskPair> non_nestable_tasks_;
  33. DISALLOW_COPY_AND_ASSIGN(BridgeTaskRunner);
  34. };
  35. } // namespace atom
  36. #endif // ATOM_BROWSER_BRIDGE_TASK_RUNNER_H_