#include "libcef_dll/cpptoc/thread_cpptoc.h"
#include "libcef_dll/cpptoc/task_runner_cpptoc.h"
#include "libcef_dll/shutdown_checker.h"
CEF_EXPORT cef_thread_t* cef_thread_create(
const cef_string_t* display_name,
cef_thread_priority_t priority,
cef_message_loop_type_t message_loop_type,
int stoppable,
cef_com_init_mode_t com_init_mode) {
shutdown_checker::AssertNotShutdown();
CefRefPtr<CefThread> _retval = CefThread::CreateThread(
CefString(display_name), priority, message_loop_type,
stoppable ? true : false, com_init_mode);
return CefThreadCppToC::Wrap(_retval);
}
namespace {
cef_task_runner_t* CEF_CALLBACK
thread_get_task_runner(struct _cef_thread_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return NULL;
CefRefPtr<CefTaskRunner> _retval =
CefThreadCppToC::Get(self)->GetTaskRunner();
return CefTaskRunnerCppToC::Wrap(_retval);
}
cef_platform_thread_id_t CEF_CALLBACK
thread_get_platform_thread_id(struct _cef_thread_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return kInvalidPlatformThreadId;
cef_platform_thread_id_t _retval =
CefThreadCppToC::Get(self)->GetPlatformThreadId();
return _retval;
}
void CEF_CALLBACK thread_stop(struct _cef_thread_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
CefThreadCppToC::Get(self)->Stop();
}
int CEF_CALLBACK thread_is_running(struct _cef_thread_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
bool _retval = CefThreadCppToC::Get(self)->IsRunning();
return _retval;
}
}
CefThreadCppToC::CefThreadCppToC() {
GetStruct()->get_task_runner = thread_get_task_runner;
GetStruct()->get_platform_thread_id = thread_get_platform_thread_id;
GetStruct()->stop = thread_stop;
GetStruct()->is_running = thread_is_running;
}
CefThreadCppToC::~CefThreadCppToC() {
shutdown_checker::AssertNotShutdown();
}
template <>
CefRefPtr<CefThread>
CefCppToCRefCounted<CefThreadCppToC, CefThread, cef_thread_t>::UnwrapDerived(
CefWrapperType type,
cef_thread_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return nullptr;
}
template <>
CefWrapperType CefCppToCRefCounted<CefThreadCppToC, CefThread, cef_thread_t>::
kWrapperType = WT_THREAD;