]> khamidou — GitHub mirrors - electron.git/commitdiff
Correctly handle notification callback when shutting down
authorCheng Zhao <zcbenz@gmail.com>
Thu, 22 Oct 2015 08:24:35 +0000 (16:24 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 22 Oct 2015 08:24:35 +0000 (16:24 +0800)
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
atom/browser/api/atom_api_app.h
atom/browser/browser.h

index 5ce918be78ad0db9ded8c5018b983ceb19412720..fa2a97de4d90293b66da49f3c062215ffcecf5d0 100644 (file)
@@ -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<content::ClientCertificateDelegate> delegate,
@@ -277,7 +286,8 @@ v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
     return v8::Local<v8::Value>::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,
index 8d55fc27c3b2ce7601a9c568e47be7d0383783cf..bd87b3885035c48088e31b135d2a9d37c5bc6552 100644 (file)
@@ -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<v8::Value> DefaultSession(v8::Isolate* isolate);
 
index 3c5abd2f04059c25c887986f6c477179e200ab32..bae281d4d370cde87327dfcbde7898c22ca36394 100644 (file)
@@ -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_; }