Make Browser::Quit more robust

This commit is contained in:
Cheng Zhao 2015-10-04 19:20:52 +08:00
parent eb7ed5b456
commit bdd2f91913
2 changed files with 16 additions and 2 deletions

View file

@ -16,7 +16,8 @@ namespace atom {
Browser::Browser() Browser::Browser()
: is_quiting_(false), : is_quiting_(false),
is_ready_(false) { is_ready_(false),
is_shutdown_(false) {
WindowList::AddObserver(this); WindowList::AddObserver(this);
} }
@ -30,6 +31,9 @@ Browser* Browser::Get() {
} }
void Browser::Quit() { void Browser::Quit() {
if (is_quiting_)
return;
is_quiting_ = HandleBeforeQuit(); is_quiting_ = HandleBeforeQuit();
if (!is_quiting_) if (!is_quiting_)
return; return;
@ -42,9 +46,13 @@ void Browser::Quit() {
} }
void Browser::Shutdown() { void Browser::Shutdown() {
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnQuit()); if (is_shutdown_)
return;
is_shutdown_ = true;
is_quiting_ = true; is_quiting_ = true;
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnQuit());
base::MessageLoop::current()->PostTask( base::MessageLoop::current()->PostTask(
FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
} }
@ -121,6 +129,9 @@ void Browser::ClientCertificateSelector(
} }
void Browser::NotifyAndShutdown() { void Browser::NotifyAndShutdown() {
if (is_shutdown_)
return;
bool prevent_default = false; bool prevent_default = false;
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default)); FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default));

View file

@ -159,6 +159,9 @@ class Browser : public WindowListObserver {
// Whether "ready" event has been emitted. // Whether "ready" event has been emitted.
bool is_ready_; bool is_ready_;
// The browse is being shutdown.
bool is_shutdown_;
std::string version_override_; std::string version_override_;
std::string name_override_; std::string name_override_;