]> khamidou — GitHub mirrors - electron.git/commitdiff
Move initialization of Single Instance into MakeSingleInstance call
authorPaul Betts <paul@paulbetts.org>
Tue, 20 Oct 2015 20:38:57 +0000 (13:38 -0700)
committerPaul Betts <paul@paulbetts.org>
Tue, 20 Oct 2015 20:38:57 +0000 (13:38 -0700)
atom/browser/api/atom_api_app.cc
atom/browser/browser.cc
atom/browser/browser.h

index 24c8063bc8dab18fd5b8ffa8b6471b20f1f9daa5..f3955d2d03ab747bdfb12a219a9a70eab70da075 100644 (file)
@@ -270,12 +270,14 @@ v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
 }
 
 bool App::MakeSingleInstance(v8::Local<v8::Function> callback) {
+  auto browser = Browser::Get();
   single_instance_callback_ = callback;
 
+  browser->InitializeSingleInstance();
+
   ProcessSingleton::NotificationCallback cb;
   mate::Converter<ProcessSingleton::NotificationCallback>::FromV8(isolate(), single_instance_callback_, &cb);
 
-  auto browser = Browser::Get();
   browser->SetSingleInstanceCallback(cb);
 
   switch(browser->GetSingleInstanceResult()) {
index 84b149330a65af1f89708b4b11761e1c8ab3d166..5c12a0d338f80dfd963bf789c393ba0f68c16845 100644 (file)
@@ -112,17 +112,6 @@ void Browser::Activate(bool has_visible_windows) {
 }
 
 void Browser::WillFinishLaunching() {
-  base::FilePath userDir;
-  PathService::Get(brightray::DIR_USER_DATA, &userDir);
-  
-  auto no_refcount_this = base::Unretained(this);
-  process_singleton_.reset(new AtomProcessSingleton(
-    userDir,
-    base::Bind(&Browser::OnProcessSingletonNotification, no_refcount_this)));
-
-  LOG(ERROR) << "Setting up Process Singleton: " << userDir.value();
-  process_notify_result_ = process_singleton_->NotifyOtherProcessOrCreate();
-
   FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching());
 }
 
@@ -154,7 +143,7 @@ void Browser::NotifyAndShutdown() {
     is_quiting_ = false;
     return;
   }
-  
+
   process_singleton_->Cleanup();
   Shutdown();
 }
@@ -168,6 +157,18 @@ bool Browser::HandleBeforeQuit() {
   return !prevent_default;
 }
 
+void Browser::InitializeSingleInstance() {
+  base::FilePath userDir;
+  PathService::Get(brightray::DIR_USER_DATA, &userDir);
+
+  auto no_refcount_this = base::Unretained(this);
+  process_singleton_.reset(new AtomProcessSingleton(
+    userDir,
+    base::Bind(&Browser::OnProcessSingletonNotification, no_refcount_this)));
+
+  process_notify_result_ = process_singleton_->NotifyOtherProcessOrCreate();
+}
+
 ProcessSingleton::NotifyResult Browser::GetSingleInstanceResult() {
   LOG(ERROR) << "Process Notify Result: " << process_notify_result_;
   return process_notify_result_;
index b3de4d169ac958c041031cef0969cbf6a9a22c5f..9113c58dd12dd3d02422f6b28ad9803181ebec24 100644 (file)
@@ -66,6 +66,7 @@ class Browser : public WindowListObserver {
   // Clear the recent documents list.
   void ClearRecentDocuments();
 
+  void InitializeSingleInstance();
   ProcessSingleton::NotifyResult GetSingleInstanceResult();
   void SetSingleInstanceCallback(ProcessSingleton::NotificationCallback callback);
 
@@ -157,7 +158,7 @@ class Browser : public WindowListObserver {
   // WindowListObserver implementations:
   void OnWindowCloseCancelled(NativeWindow* window) override;
   void OnWindowAllClosed() override;
-  
+
   bool OnProcessSingletonNotification(
     const base::CommandLine& command_line,
     const base::FilePath& current_directory);