#include "libcef_dll/cpptoc/task_runner_cpptoc.h"
#include "libcef_dll/ctocpp/task_ctocpp.h"
#include "libcef_dll/shutdown_checker.h"
CEF_EXPORT cef_task_runner_t* cef_task_runner_get_for_current_thread() {
shutdown_checker::AssertNotShutdown();
CefRefPtr<CefTaskRunner> _retval = CefTaskRunner::GetForCurrentThread();
return CefTaskRunnerCppToC::Wrap(_retval);
}
CEF_EXPORT cef_task_runner_t* cef_task_runner_get_for_thread(
cef_thread_id_t threadId) {
shutdown_checker::AssertNotShutdown();
CefRefPtr<CefTaskRunner> _retval = CefTaskRunner::GetForThread(threadId);
return CefTaskRunnerCppToC::Wrap(_retval);
}
namespace {
int CEF_CALLBACK task_runner_is_same(struct _cef_task_runner_t* self,
struct _cef_task_runner_t* that) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
DCHECK(that);
if (!that)
return 0;
bool _retval =
CefTaskRunnerCppToC::Get(self)->IsSame(CefTaskRunnerCppToC::Unwrap(that));
return _retval;
}
int CEF_CALLBACK
task_runner_belongs_to_current_thread(struct _cef_task_runner_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
bool _retval = CefTaskRunnerCppToC::Get(self)->BelongsToCurrentThread();
return _retval;
}
int CEF_CALLBACK task_runner_belongs_to_thread(struct _cef_task_runner_t* self,
cef_thread_id_t threadId) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
bool _retval = CefTaskRunnerCppToC::Get(self)->BelongsToThread(threadId);
return _retval;
}
int CEF_CALLBACK task_runner_post_task(struct _cef_task_runner_t* self,
cef_task_t* task) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
DCHECK(task);
if (!task)
return 0;
bool _retval =
CefTaskRunnerCppToC::Get(self)->PostTask(CefTaskCToCpp::Wrap(task));
return _retval;
}
int CEF_CALLBACK task_runner_post_delayed_task(struct _cef_task_runner_t* self,
cef_task_t* task,
int64 delay_ms) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
DCHECK(task);
if (!task)
return 0;
bool _retval = CefTaskRunnerCppToC::Get(self)->PostDelayedTask(
CefTaskCToCpp::Wrap(task), delay_ms);
return _retval;
}
}
CefTaskRunnerCppToC::CefTaskRunnerCppToC() {
GetStruct()->is_same = task_runner_is_same;
GetStruct()->belongs_to_current_thread =
task_runner_belongs_to_current_thread;
GetStruct()->belongs_to_thread = task_runner_belongs_to_thread;
GetStruct()->post_task = task_runner_post_task;
GetStruct()->post_delayed_task = task_runner_post_delayed_task;
}
CefTaskRunnerCppToC::~CefTaskRunnerCppToC() {
shutdown_checker::AssertNotShutdown();
}
template <>
CefRefPtr<CefTaskRunner>
CefCppToCRefCounted<CefTaskRunnerCppToC, CefTaskRunner, cef_task_runner_t>::
UnwrapDerived(CefWrapperType type, cef_task_runner_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return nullptr;
}
template <>
CefWrapperType CefCppToCRefCounted<CefTaskRunnerCppToC,
CefTaskRunner,
cef_task_runner_t>::kWrapperType =
WT_TASK_RUNNER;