From e14fd62f4626bb016f3bf2f2e48ec7d892924304 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 22 Oct 2015 16:24:35 +0800 Subject: [PATCH] Correctly handle notification callback when shutting down When returning false in the notification callback the ProcessSingleton will assume current process is quitting, we should met its expectation. --- atom/browser/api/atom_api_app.cc | 15 +++++++++++++-- atom/browser/api/atom_api_app.h | 6 ++---- atom/browser/browser.h | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 5ce918be78ad..fa2a97de4d90 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -112,6 +112,15 @@ int GetPathConstant(const std::string& name) { return -1; } +// Run the NotificationCallback and returns whether browser is shuting down. +bool NotificationCallbackWrapper( + const ProcessSingleton::NotificationCallback& callback, + const base::CommandLine& command_line, + const base::FilePath& current_directory) { + callback.Run(command_line, current_directory); + return !Browser::Get()->is_shutting_down(); +} + void OnClientCertificateSelected( v8::Isolate* isolate, std::shared_ptr delegate, @@ -277,7 +286,8 @@ v8::Local App::DefaultSession(v8::Isolate* isolate) { return v8::Local::New(isolate, default_session_); } -bool App::MakeSingleInstance(ProcessSingleton::NotificationCallback callback) { +bool App::MakeSingleInstance( + const ProcessSingleton::NotificationCallback& callback) { #if defined(OS_MACOSX) LOG(ERROR) << "MakeSingleInstance is not implemnted on OS X"; return false; @@ -289,7 +299,8 @@ bool App::MakeSingleInstance(ProcessSingleton::NotificationCallback callback) { PathService::Get(brightray::DIR_USER_DATA, &user_dir); process_singleton_startup_lock_.reset( - new ProcessSingletonStartupLock(callback)); + new ProcessSingletonStartupLock( + base::Bind(NotificationCallbackWrapper, callback))); process_singleton_.reset( new ProcessSingleton( user_dir, diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 8d55fc27c3b2..bd87b3885035 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -68,11 +68,9 @@ class App : public mate::EventEmitter, void SetDesktopName(const std::string& desktop_name); void SetAppUserModelId(const std::string& app_id); - void AllowNTLMCredentialsForAllDomains(bool should_allow); - - bool MakeSingleInstance(ProcessSingleton::NotificationCallback callback); - + bool MakeSingleInstance( + const ProcessSingleton::NotificationCallback& callback); std::string GetLocale(); v8::Local DefaultSession(v8::Isolate* isolate); diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 3c5abd2f0405..bae281d4d370 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -130,6 +130,7 @@ class Browser : public WindowListObserver { observers_.RemoveObserver(obs); } + bool is_shutting_down() const { return is_shutdown_; } bool is_quiting() const { return is_quiting_; } bool is_ready() const { return is_ready_; }