2015-09-02 07:52:17 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_BRIDGE_TASK_RUNNER_H_
|
|
|
|
#define ATOM_BROWSER_BRIDGE_TASK_RUNNER_H_
|
|
|
|
|
2016-09-06 08:24:37 +00:00
|
|
|
#include <tuple>
|
2015-10-22 07:54:27 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2017-12-18 02:35:17 +00:00
|
|
|
#include "base/location.h"
|
2015-09-02 07:52:17 +00:00
|
|
|
#include "base/single_thread_task_runner.h"
|
2015-10-22 07:54:27 +00:00
|
|
|
#include "base/tuple.h"
|
2015-09-02 07:52:17 +00:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
// Post all tasks to the current message loop's task runner if available,
|
2015-10-22 07:54:27 +00:00
|
|
|
// otherwise delay the work until message loop is ready.
|
2015-09-02 07:52:17 +00:00
|
|
|
class BridgeTaskRunner : public base::SingleThreadTaskRunner {
|
|
|
|
public:
|
2018-04-17 23:37:22 +00:00
|
|
|
BridgeTaskRunner();
|
2015-09-02 07:52:17 +00:00
|
|
|
|
2015-10-22 07:54:27 +00:00
|
|
|
// Called when message loop is ready.
|
2015-11-30 14:29:01 +00:00
|
|
|
void MessageLoopIsReady();
|
2015-10-22 07:54:27 +00:00
|
|
|
|
2015-09-02 07:52:17 +00:00
|
|
|
// base::SingleThreadTaskRunner:
|
2017-12-18 02:35:17 +00:00
|
|
|
bool PostDelayedTask(const base::Location& from_here,
|
2017-06-16 20:39:08 +00:00
|
|
|
base::OnceClosure task,
|
2015-09-02 07:52:17 +00:00
|
|
|
base::TimeDelta delay) override;
|
2017-08-07 21:14:35 +00:00
|
|
|
bool RunsTasksInCurrentSequence() const override;
|
2018-04-18 01:44:10 +00:00
|
|
|
bool PostNonNestableDelayedTask(const base::Location& from_here,
|
|
|
|
base::OnceClosure task,
|
|
|
|
base::TimeDelta delay) override;
|
2015-09-02 07:52:17 +00:00
|
|
|
|
|
|
|
private:
|
2018-04-18 01:44:10 +00:00
|
|
|
using TaskPair =
|
|
|
|
std::tuple<base::Location, base::OnceClosure, base::TimeDelta>;
|
2018-04-17 23:37:22 +00:00
|
|
|
~BridgeTaskRunner() override;
|
2018-04-17 23:23:40 +00:00
|
|
|
|
2015-11-30 14:29:01 +00:00
|
|
|
std::vector<TaskPair> tasks_;
|
|
|
|
std::vector<TaskPair> non_nestable_tasks_;
|
2015-10-22 07:54:27 +00:00
|
|
|
|
2015-09-02 07:52:17 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(BridgeTaskRunner);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_BRIDGE_TASK_RUNNER_H_
|