fix: shutdown after message loop is ready (#16671)

This commit is contained in:
Cheng Zhao 2019-02-02 00:21:49 +09:00 committed by John Kleinschmidt
parent ab503c7e43
commit 31c7ed9b8c
7 changed files with 14 additions and 38 deletions

View file

@ -455,7 +455,7 @@ bool AtomBrowserMainParts::MainMessageLoopRun(int* result_code) {
void AtomBrowserMainParts::PreDefaultMainMessageLoopRun( void AtomBrowserMainParts::PreDefaultMainMessageLoopRun(
base::OnceClosure quit_closure) { base::OnceClosure quit_closure) {
Browser::SetMainMessageLoopQuitClosure(std::move(quit_closure)); Browser::Get()->SetMainMessageLoopQuitClosure(std::move(quit_closure));
} }
void AtomBrowserMainParts::PostMainMessageLoopStart() { void AtomBrowserMainParts::PostMainMessageLoopStart() {

View file

@ -25,9 +25,6 @@
namespace atom { namespace atom {
// Null until/unless the default main message loop is running.
base::NoDestructor<base::OnceClosure> g_quit_main_message_loop;
Browser::LoginItemSettings::LoginItemSettings() = default; Browser::LoginItemSettings::LoginItemSettings() = default;
Browser::LoginItemSettings::~LoginItemSettings() = default; Browser::LoginItemSettings::~LoginItemSettings() = default;
Browser::LoginItemSettings::LoginItemSettings(const LoginItemSettings& other) = Browser::LoginItemSettings::LoginItemSettings(const LoginItemSettings& other) =
@ -95,11 +92,12 @@ void Browser::Shutdown() {
for (BrowserObserver& observer : observers_) for (BrowserObserver& observer : observers_)
observer.OnQuit(); observer.OnQuit();
if (*g_quit_main_message_loop) { if (quit_main_message_loop_) {
std::move(*g_quit_main_message_loop).Run(); std::move(quit_main_message_loop_).Run();
} else { } else {
// There is no message loop available so we are in early stage. // There is no message loop available so we are in early stage, wait until
exit(0); // the quit_main_message_loop_ is available.
// Exiting now would leave defunct processes behind.
} }
} }
@ -196,7 +194,10 @@ void Browser::PreMainMessageLoopRun() {
} }
void Browser::SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) { void Browser::SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) {
*g_quit_main_message_loop = std::move(quit_closure); if (is_shutdown_)
std::move(quit_closure).Run();
else
quit_main_message_loop_ = std::move(quit_closure);
} }
void Browser::NotifyAndShutdown() { void Browser::NotifyAndShutdown() {

View file

@ -244,7 +244,7 @@ class Browser : public WindowListObserver {
// Stores the supplied |quit_closure|, to be run when the last Browser // Stores the supplied |quit_closure|, to be run when the last Browser
// instance is destroyed. // instance is destroyed.
static void SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure); void SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure);
void AddObserver(BrowserObserver* obs) { observers_.AddObserver(obs); } void AddObserver(BrowserObserver* obs) { observers_.AddObserver(obs); }
@ -287,6 +287,9 @@ class Browser : public WindowListObserver {
// The browser is being shutdown. // The browser is being shutdown.
bool is_shutdown_ = false; bool is_shutdown_ = false;
// Null until/unless the default main message loop is running.
base::OnceClosure quit_main_message_loop_;
int badge_count_ = 0; int badge_count_ = 0;
util::Promise* ready_promise_ = nullptr; util::Promise* ready_promise_ = nullptr;

View file

@ -1211,13 +1211,6 @@ describe('default behavior', () => {
}) })
describe('window-all-closed', () => { describe('window-all-closed', () => {
before(function () {
// FIXME(jkleinsc): Test is consistently failing on Windows 32 bit.
if (process.arch === 'ia32') {
this.skip()
}
})
it('quits when the app does not handle the event', async () => { it('quits when the app does not handle the event', async () => {
const result = await runTestApp('window-all-closed') const result = await runTestApp('window-all-closed')
expect(result).to.equal(false) expect(result).to.equal(false)

View file

@ -228,13 +228,6 @@ describe('BrowserView module', () => {
}) })
describe('new BrowserView()', () => { describe('new BrowserView()', () => {
before(function () {
// FIXME(jkleinsc): Test is consistently failing on Windows 32 bit.
if (process.arch === 'ia32') {
this.skip()
}
})
it('does not crash on exit', async () => { it('does not crash on exit', async () => {
const appPath = path.join(fixtures, 'api', 'leak-exit-browserview.js') const appPath = path.join(fixtures, 'api', 'leak-exit-browserview.js')
const electronPath = remote.getGlobal('process').execPath const electronPath = remote.getGlobal('process').execPath

View file

@ -916,13 +916,6 @@ describe('webContents module', () => {
}) })
describe('create()', () => { describe('create()', () => {
before(function () {
// FIXME(jkleinsc): Test is consistently failing on Windows 32 bit.
if (process.arch === 'ia32') {
this.skip()
}
})
it('does not crash on exit', async () => { it('does not crash on exit', async () => {
const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-webcontents.js') const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-webcontents.js')
const electronPath = remote.getGlobal('process').execPath const electronPath = remote.getGlobal('process').execPath

View file

@ -34,13 +34,6 @@ describe('WebContentsView', () => {
}) })
describe('new WebContentsView()', () => { describe('new WebContentsView()', () => {
before(function () {
// FIXME(jkleinsc): Test is consistently failing on Windows 32 bit.
if (process.arch === 'ia32') {
this.skip()
}
})
it('does not crash on exit', async () => { it('does not crash on exit', async () => {
const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-webcontentsview.js') const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-webcontentsview.js')
const electronPath = remote.getGlobal('process').execPath const electronPath = remote.getGlobal('process').execPath