aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Bochkarev <artem.bochkarev@jetbrains.com>2023-04-27 17:47:50 +0700
committerArtem Bochkarev <artem.bochkarev@jetbrains.com>2023-04-28 15:44:00 +0700
commitdab0f1bcc5ba8d6b39784b593250bc4c93ef8d64 (patch)
tree76f1bc60c7692985f66221e8eb171ba6884ec498
parent36c5c2afe226d04a356df4d082043a2738bd6554 (diff)
downloadjcef-dab0f1bcc5ba8d6b39784b593250bc4c93ef8d64.tar.gz
JBR-5530 shutdown CefApp on bg thread
-rw-r--r--java/org/cef/CefApp.java27
-rw-r--r--native/context.cpp9
-rw-r--r--native/util_mac.mm2
3 files changed, 13 insertions, 25 deletions
diff --git a/java/org/cef/CefApp.java b/java/org/cef/CefApp.java
index 45c89d6..b4d6361 100644
--- a/java/org/cef/CefApp.java
+++ b/java/org/cef/CefApp.java
@@ -354,7 +354,7 @@ public class CefApp extends CefAppHandlerAdapter {
// (3) Shutdown sequence. Close all clients and continue.
setState(CefAppState.SHUTTING_DOWN);
if (clients_.isEmpty()) {
- shutdown();
+ scheduleNativeShutdown();
} else {
// shutdown() will be called from clientWasDisposed() when the last
// client is gone.
@@ -446,7 +446,7 @@ public class CefApp extends CefAppHandlerAdapter {
CefLog.Debug("CefApp: client was disposed: %s [clients count %d]", client, clients_.size());
if (clients_.isEmpty() && getState().compareTo(CefAppState.SHUTTING_DOWN) >= 0) {
// Shutdown native system.
- shutdown();
+ scheduleNativeShutdown();
}
}
@@ -549,26 +549,19 @@ public class CefApp extends CefAppHandlerAdapter {
/**
* Shut down the context.
*/
- private final void shutdown() {
- // [tav] in order to "unwind" invokeLater(()-> CefApp.dispose()) explicitly.
+ private void scheduleNativeShutdown() {
+ new Thread(()-> {
+ // Can execute on any thread
+ CefLog.Info("shutdown CEF on " + Thread.currentThread());
- // Execute on the AWT event dispatching thread. Always call asynchronously
- // so the call stack has a chance to unwind.
- Runnable _shutdown = () -> {
- synchronized (CefApp.this) {
- CefLog.Info("shutdown on " + Thread.currentThread());
-
- // Shutdown native CEF.
- N_Shutdown();
+ // Shutdown native CEF.
+ N_Shutdown();
+ synchronized (this) {
setState(CefAppState.TERMINATED);
CefApp.self = null;
}
- };
- if (EventQueue.isDispatchThread())
- _shutdown.run();
- else
- SwingUtilities.invokeLater(_shutdown);
+ }, "CEF-shutdown-thread").start();
}
/**
diff --git a/native/context.cpp b/native/context.cpp
index ef25bdb..046791d 100644
--- a/native/context.cpp
+++ b/native/context.cpp
@@ -286,8 +286,6 @@ void Context::DoMessageLoopWork() {
}
void Context::Shutdown() {
- DCHECK(thread_checker_.CalledOnValidThread());
-
static bool shutdownWasCalled = false;
if (shutdownWasCalled) return;
shutdownWasCalled = true;
@@ -299,12 +297,9 @@ void Context::Shutdown() {
#if defined(OS_MAC)
util_mac::CefShutdownOnMainThread();
#else
- // Pump CefDoMessageLoopWork a few times before shutting down.
- if (external_message_pump_) {
- for (int i = 0; i < 10; ++i)
- CefDoMessageLoopWork();
- }
+ // NOTE: external_message_pump_ == false in Windows and Linux (see Context::Initialize)
+ // So don't pump CefDoMessageLoopWork (a few times before shutting down) here.
temp_window_.reset(nullptr);
CefShutdown();
diff --git a/native/util_mac.mm b/native/util_mac.mm
index 2d8265c..fe383da 100644
--- a/native/util_mac.mm
+++ b/native/util_mac.mm
@@ -521,7 +521,7 @@ void CefShutdownOnMainThread() {
// Block until done.
[[CefHandler class] performSelectorOnMainThread:@selector(shutdown)
withObject:nil
- waitUntilDone:YES];
+ waitUntilDone:NO];
}
void CefDoMessageLoopWorkOnMainThread() {