2014-07-15 00:18:51 +02:00
|
|
|
// Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2021-06-18 20:19:11 +02:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2017-05-19 11:06:00 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2014-07-15 00:18:51 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2021-06-18 20:19:11 +02:00
|
|
|
class CefOnceClosureTask : public CefTask {
|
|
|
|
public:
|
|
|
|
explicit CefOnceClosureTask(base::OnceClosure closure)
|
|
|
|
: closure_(std::move(closure)) {}
|
|
|
|
|
2021-12-06 22:59:14 +01:00
|
|
|
CefOnceClosureTask(const CefOnceClosureTask&) = delete;
|
|
|
|
CefOnceClosureTask& operator=(const CefOnceClosureTask&) = delete;
|
|
|
|
|
2021-06-18 20:19:11 +02:00
|
|
|
// CefTask method
|
|
|
|
void Execute() override { std::move(closure_).Run(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
base::OnceClosure closure_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefOnceClosureTask);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CefRepeatingClosureTask : public CefTask {
|
2014-07-15 00:18:51 +02:00
|
|
|
public:
|
2021-06-18 20:19:11 +02:00
|
|
|
explicit CefRepeatingClosureTask(const base::RepeatingClosure& closure)
|
|
|
|
: closure_(closure) {}
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2021-12-06 22:59:14 +01:00
|
|
|
CefRepeatingClosureTask(const CefRepeatingClosureTask&) = delete;
|
|
|
|
CefRepeatingClosureTask& operator=(const CefRepeatingClosureTask&) = delete;
|
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
// CefTask method
|
2021-06-18 20:19:11 +02:00
|
|
|
void Execute() override {
|
2014-07-15 00:18:51 +02:00
|
|
|
closure_.Run();
|
|
|
|
closure_.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-06-18 20:19:11 +02:00
|
|
|
base::RepeatingClosure closure_;
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2021-06-18 20:19:11 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(CefRepeatingClosureTask);
|
2014-07-15 00:18:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2021-06-18 20:19:11 +02:00
|
|
|
CefRefPtr<CefTask> CefCreateClosureTask(base::OnceClosure closure) {
|
|
|
|
return new CefOnceClosureTask(std::move(closure));
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefTask> CefCreateClosureTask(const base::RepeatingClosure& closure) {
|
|
|
|
return new CefRepeatingClosureTask(closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPostTask(CefThreadId threadId, base::OnceClosure closure) {
|
|
|
|
return CefPostTask(threadId, new CefOnceClosureTask(std::move(closure)));
|
2014-07-15 00:18:51 +02:00
|
|
|
}
|
|
|
|
|
2021-06-18 20:19:11 +02:00
|
|
|
bool CefPostTask(CefThreadId threadId, const base::RepeatingClosure& closure) {
|
|
|
|
return CefPostTask(threadId, new CefRepeatingClosureTask(closure));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPostDelayedTask(CefThreadId threadId,
|
|
|
|
base::OnceClosure closure,
|
2023-06-01 16:07:20 +02:00
|
|
|
int64_t delay_ms) {
|
2021-06-18 20:19:11 +02:00
|
|
|
return CefPostDelayedTask(
|
|
|
|
threadId, new CefOnceClosureTask(std::move(closure)), delay_ms);
|
2014-07-15 00:18:51 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool CefPostDelayedTask(CefThreadId threadId,
|
2021-06-18 20:19:11 +02:00
|
|
|
const base::RepeatingClosure& closure,
|
2023-06-01 16:07:20 +02:00
|
|
|
int64_t delay_ms) {
|
2021-06-18 20:19:11 +02:00
|
|
|
return CefPostDelayedTask(threadId, new CefRepeatingClosureTask(closure),
|
|
|
|
delay_ms);
|
2014-07-15 00:18:51 +02:00
|
|
|
}
|