2013-01-03 18:24:24 +01:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
2012-04-03 03:34:16 +02:00
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_RENDERER_THREAD_UTIL_H_
|
|
|
|
#define CEF_LIBCEF_RENDERER_THREAD_UTIL_H_
|
|
|
|
#pragma once
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "libcef/common/task_runner_manager.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include "base/location.h"
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "content/public/renderer/render_thread.h"
|
|
|
|
|
|
|
|
#define CEF_CURRENTLY_ON_RT() (!!content::RenderThread::Get())
|
|
|
|
|
|
|
|
#define CEF_REQUIRE_RT() DCHECK(CEF_CURRENTLY_ON_RT())
|
|
|
|
|
2023-05-08 17:07:57 +02:00
|
|
|
#define CEF_REQUIRE_RT_RETURN(var) \
|
|
|
|
if (!CEF_CURRENTLY_ON_RT()) { \
|
|
|
|
DCHECK(false) << "called on invalid thread"; \
|
|
|
|
return var; \
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-05-08 17:07:57 +02:00
|
|
|
#define CEF_REQUIRE_RT_RETURN_VOID() \
|
|
|
|
if (!CEF_CURRENTLY_ON_RT()) { \
|
|
|
|
DCHECK(false) << "called on invalid thread"; \
|
|
|
|
return; \
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
#define CEF_RENDER_TASK_RUNNER() \
|
|
|
|
(CefTaskRunnerManager::Get()->GetRenderTaskRunner())
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
#define CEF_POST_TASK_RT(task) \
|
|
|
|
CEF_RENDER_TASK_RUNNER()->PostTask(FROM_HERE, task)
|
2021-10-19 00:17:16 +02:00
|
|
|
#define CEF_POST_DELAYED_TASK_RT(task, delay_ms) \
|
|
|
|
CEF_RENDER_TASK_RUNNER()->PostDelayedTask(FROM_HERE, task, \
|
|
|
|
base::Milliseconds(delay_ms))
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Use this template in conjuction with RefCountedThreadSafe when you want to
|
|
|
|
// ensure that an object is deleted on the render thread.
|
|
|
|
struct CefDeleteOnRenderThread {
|
2017-05-17 11:29:28 +02:00
|
|
|
template <typename T>
|
2012-04-03 03:34:16 +02:00
|
|
|
static void Destruct(const T* x) {
|
|
|
|
if (CEF_CURRENTLY_ON_RT()) {
|
|
|
|
delete x;
|
|
|
|
} else {
|
2020-06-28 20:29:44 +02:00
|
|
|
if (!CEF_RENDER_TASK_RUNNER()->DeleteSoon(FROM_HERE, x)) {
|
2012-04-03 03:34:16 +02:00
|
|
|
#if defined(UNIT_TEST)
|
|
|
|
// Only logged under unit testing because leaks at shutdown
|
|
|
|
// are acceptable under normal circumstances.
|
|
|
|
LOG(ERROR) << "DeleteSoon failed on thread " << thread;
|
|
|
|
#endif // UNIT_TEST
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_RENDERER_THREAD_UTIL_H_
|