Can you use a lousy timer (for testing) to perform a pooling on the opened/closed browsers ?
Saying your app is keeping count of opened browsers in a browsers_count variable, simply do InterlockedIncrement on browsers_count in client handler OnAfterCreated, InterlockedDecrement on browsers_count in OnBeforeClose, and when you want to do quit it will be something like in this crude Windows pseudocode
- Code: Select all
void ClientHandler::OnAfterCreated() {
...
InterlockedIncrement(&App::browsers_count);
}
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
...
InterlockedDecrement(&App::browsers_count);
}
void App::Quit() {
... instead of CefQuitMessageLoop
quit_timer_id = CreateTimer( ... ); // or a self-rearming CreateWaitableTimer if you don't process WM_TIMER
...
}
void App::WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
if (msg == WM_TIMER) {
if (wp == quit_timer_id) {
if (InterlockedCompareExchange(&App::browsers_count, 0, 0) == 0) {
// done, browsers_count decreased to 0
PostMessage(hwnd, USER_WM_CLOSE, 0, 0); // define a USER_WM_CLOSE = WM_USER + 100 or so
}
}
}
...
else if (msg == USER_WM_CLOSE) {
CefQuitMessageLoop();
return 0;
}
...
... DefWindowProc/CallWindowProc if subclass etc
}