Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: quit after Chromium is fully started #21488

Merged
merged 3 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions shell/browser/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@

namespace electron {

namespace {

// Call |quit| after Chromium is fully started.
//
// This is important for quitting immediately in the "ready" event, when
// certain initialization task may still be pending, and quitting at that time
// could end up with crash on exit.
void RunQuitClosure(base::OnceClosure quit) {
// Consume remaining tasks in message loop.
base::RunLoop().RunUntilIdle();
// On Linux/Windows the "ready" event is emitted in "PreMainMessageLoopRun",
// make sure we quit after message loop has run for once.
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(quit));
nornagon marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace

Browser::LoginItemSettings::LoginItemSettings() = default;
Browser::LoginItemSettings::~LoginItemSettings() = default;
Browser::LoginItemSettings::LoginItemSettings(const LoginItemSettings& other) =
Expand Down Expand Up @@ -94,7 +111,7 @@ void Browser::Shutdown() {
observer.OnQuit();

if (quit_main_message_loop_) {
std::move(quit_main_message_loop_).Run();
RunQuitClosure(std::move(quit_main_message_loop_));
} else {
// There is no message loop available so we are in early stage, wait until
// the quit_main_message_loop_ is available.
Expand Down Expand Up @@ -189,7 +206,7 @@ void Browser::PreMainMessageLoopRun() {

void Browser::SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) {
if (is_shutdown_)
std::move(quit_closure).Run();
RunQuitClosure(std::move(quit_closure));
else
quit_main_message_loop_ = std::move(quit_closure);
}
Expand Down
2 changes: 1 addition & 1 deletion spec-main/fixtures/api/leak-exit-webcontentsview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ app.on('ready', function () {
const web = webContents.create({})
new WebContentsView(web) // eslint-disable-line

process.nextTick(() => app.quit())
app.quit()
})
4 changes: 1 addition & 3 deletions spec/fixtures/api/command-line/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ app.on('ready', () => {
process.stdout.write(JSON.stringify(payload))
process.stdout.end()

setImmediate(() => {
app.quit()
})
app.quit()
})
4 changes: 1 addition & 3 deletions spec/fixtures/api/cookie-app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ app.on('ready', async function () {
} finally {
process.stdout.end()

setImmediate(() => {
app.quit()
})
app.quit()
}
})
4 changes: 1 addition & 3 deletions spec/fixtures/api/ipc-main-listeners/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ app.on('ready', () => {
process.stdout.write(JSON.stringify(ipcMain.eventNames()))
process.stdout.end()

setImmediate(() => {
app.quit()
})
app.quit()
})
2 changes: 1 addition & 1 deletion spec/fixtures/api/leak-exit-browserview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ const { BrowserView, app } = require('electron')
app.on('ready', function () {
new BrowserView({}) // eslint-disable-line

process.nextTick(() => app.quit())
app.quit()
})
2 changes: 1 addition & 1 deletion spec/fixtures/api/leak-exit-webcontents.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ const { app, webContents } = require('electron')
app.on('ready', function () {
webContents.create({})

process.nextTick(() => app.quit())
app.quit()
})
4 changes: 1 addition & 3 deletions spec/fixtures/api/locale-check/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ app.on('ready', () => {
process.stdout.write(app.getLocale())
process.stdout.end()

setImmediate(() => {
app.quit()
})
app.quit()
})