2015-09-02 20:28:50 -06: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.
|
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#ifndef ELECTRON_SHELL_APP_UV_TASK_RUNNER_H_
|
|
|
|
#define ELECTRON_SHELL_APP_UV_TASK_RUNNER_H_
|
2015-09-02 20:28:50 -06:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
2023-05-11 14:07:39 -06:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2021-11-24 01:45:59 -07:00
|
|
|
#include "base/task/single_thread_task_runner.h"
|
2020-04-24 13:57:41 -06:00
|
|
|
#include "uv.h" // NOLINT(build/include_directory)
|
2015-09-02 20:28:50 -06:00
|
|
|
|
2021-07-01 18:51:37 -06:00
|
|
|
namespace base {
|
|
|
|
class Location;
|
2022-02-25 11:17:35 -07:00
|
|
|
class TimeDelta;
|
|
|
|
} // namespace base
|
2021-07-01 18:51:37 -06:00
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
namespace electron {
|
2015-09-02 20:28:50 -06:00
|
|
|
|
|
|
|
// TaskRunner implementation that posts tasks into libuv's default loop.
|
|
|
|
class UvTaskRunner : public base::SingleThreadTaskRunner {
|
|
|
|
public:
|
|
|
|
explicit UvTaskRunner(uv_loop_t* loop);
|
|
|
|
|
2021-11-03 05:41:45 -06:00
|
|
|
// disable copy
|
|
|
|
UvTaskRunner(const UvTaskRunner&) = delete;
|
|
|
|
UvTaskRunner& operator=(const UvTaskRunner&) = delete;
|
|
|
|
|
2015-09-02 20:28:50 -06:00
|
|
|
// base::SingleThreadTaskRunner:
|
2017-12-17 16:56:18 -07:00
|
|
|
bool PostDelayedTask(const base::Location& from_here,
|
2017-06-16 14:39:08 -06:00
|
|
|
base::OnceClosure task,
|
2015-09-02 20:28:50 -06:00
|
|
|
base::TimeDelta delay) override;
|
2017-08-07 15:14:35 -06:00
|
|
|
bool RunsTasksInCurrentSequence() const override;
|
2018-04-17 19:44:10 -06:00
|
|
|
bool PostNonNestableDelayedTask(const base::Location& from_here,
|
|
|
|
base::OnceClosure task,
|
|
|
|
base::TimeDelta delay) override;
|
2015-09-02 20:28:50 -06:00
|
|
|
|
|
|
|
private:
|
2018-04-17 17:23:40 -06:00
|
|
|
~UvTaskRunner() override;
|
2015-09-02 20:28:50 -06:00
|
|
|
static void OnTimeout(uv_timer_t* timer);
|
2015-10-21 06:46:16 -06:00
|
|
|
static void OnClose(uv_handle_t* handle);
|
2015-09-02 20:28:50 -06:00
|
|
|
|
2023-05-11 14:07:39 -06:00
|
|
|
raw_ptr<uv_loop_t> loop_;
|
2015-09-02 20:28:50 -06:00
|
|
|
|
2017-06-16 14:39:08 -06:00
|
|
|
std::map<uv_timer_t*, base::OnceClosure> tasks_;
|
2015-09-02 20:28:50 -06:00
|
|
|
};
|
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
} // namespace electron
|
2015-09-02 20:28:50 -06:00
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#endif // ELECTRON_SHELL_APP_UV_TASK_RUNNER_H_
|