bridge_task_runner.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/single_thread_task_runner.h"
  9. #include "base/tuple.h"
  10. namespace atom {
  11. // Post all tasks to the current message loop's task runner if available,
  12. // otherwise delay the work until message loop is ready.
  13. class BridgeTaskRunner : public base::SingleThreadTaskRunner {
  14. public:
  15. BridgeTaskRunner() {}
  16. ~BridgeTaskRunner() override {}
  17. // Called when message loop is ready.
  18. void MessageLoopIsReady();
  19. // base::SingleThreadTaskRunner:
  20. bool PostDelayedTask(const tracked_objects::Location& from_here,
  21. const base::Closure& task,
  22. base::TimeDelta delay) override;
  23. bool RunsTasksOnCurrentThread() const override;
  24. bool PostNonNestableDelayedTask(
  25. const tracked_objects::Location& from_here,
  26. const base::Closure& task,
  27. base::TimeDelta delay) override;
  28. private:
  29. using TaskPair = std::tuple<
  30. tracked_objects::Location, base::Closure, base::TimeDelta>;
  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_