]> khamidou — GitHub mirrors - electron.git/commitdiff
Wire everything up
authorPaul Betts <paul@paulbetts.org>
Mon, 19 Oct 2015 23:21:03 +0000 (16:21 -0700)
committerPaul Betts <paul@paulbetts.org>
Tue, 20 Oct 2015 20:16:48 +0000 (13:16 -0700)
atom/browser/api/atom_api_app.cc
atom/browser/api/atom_api_app.h
atom/browser/browser.cc
atom/browser/browser.h

index 27cc137d22746434b27dcf688a16cc517034ae9b..3c858c2f34637693e64e75612e8886c46e7fd8d7 100644 (file)
@@ -19,6 +19,7 @@
 #include "atom/browser/api/atom_api_web_contents.h"
 #include "atom/common/native_mate_converters/callback.h"
 #include "atom/common/native_mate_converters/file_path_converter.h"
+#include "atom/common/native_mate_converters/command_line_converter.h"
 #include "atom/common/node_includes.h"
 #include "atom/common/options_switches.h"
 #include "base/command_line.h"
@@ -268,7 +269,19 @@ v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
     return v8::Local<v8::Value>::New(isolate, default_session_);
 }
 
-bool App::MakeSingleInstance(const SingleInstanceCallback& callback) {
+bool App::MakeSingleInstance(const ProcessSingleton::NotificationCallback& callback) {
+  auto browser = Browser::Get();
+  browser->SetSingleInstanceCallback(&callback);
+  
+  switch(browser->GetSingleInstanceResult()) {
+    case ProcessSingleton::NotifyResult::PROCESS_NONE:
+      return false;
+    case ProcessSingleton::NotifyResult::LOCK_ERROR:
+    case ProcessSingleton::NotifyResult::PROFILE_IN_USE:
+    case ProcessSingleton::NotifyResult::PROCESS_NOTIFIED:
+      return true;
+  }
+  
   return false;
 }
 
index ae79abe8f21df111a75f25a0bd3748874bb70ea8..10d4edf117f1849bdff4eae46c4b4c40a1610c3b 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "atom/browser/api/event_emitter.h"
 #include "atom/browser/browser_observer.h"
+#include "atom/browser/process_singleton.h"
 #include "atom/common/native_mate_converters/callback.h"
 #include "content/public/browser/gpu_data_manager_observer.h"
 #include "native_mate/handle.h"
@@ -25,8 +26,6 @@ namespace atom {
 
 namespace api {
 
-using SingleInstanceCallback = base::Callback<void(const std::string&)>;
-
 class App : public mate::EventEmitter,
             public BrowserObserver,
             public content::GpuDataManagerObserver {
@@ -70,8 +69,8 @@ class App : public mate::EventEmitter,
   void SetAppUserModelId(const std::string& app_id);
 
   void AllowNTLMCredentialsForAllDomains(bool should_allow);
-  
-  bool MakeSingleInstance(const SingleInstanceCallback& callback);
+
+  bool MakeSingleInstance(const ProcessSingleton::NotificationCallback& callback);
 
   std::string GetLocale();
   v8::Local<v8::Value> DefaultSession(v8::Isolate* isolate);
index 10d6cc8330ebe3996cff83df006a730158865ca6..3c55be68824cb3199e076f9279ee80d29c40f7bc 100644 (file)
@@ -171,7 +171,7 @@ ProcessSingleton::NotifyResult Browser::GetSingleInstanceResult() {
   return process_notify_result_;
 }
   
-void Browser::SetSingleInstanceCallback(ProcessSingleton::NotificationCallback* callback) {
+void Browser::SetSingleInstanceCallback(const ProcessSingleton::NotificationCallback* callback) {
   process_notify_callback_ = callback;
 }
 
index 4dffeb093fab2d82f5910f51fd88bd4cd9797843..f14062232ca792f80521e7c0825b4a14cd68afdb 100644 (file)
@@ -67,7 +67,7 @@ class Browser : public WindowListObserver {
   void ClearRecentDocuments();
   
   ProcessSingleton::NotifyResult GetSingleInstanceResult();
-  void SetSingleInstanceCallback(ProcessSingleton::NotificationCallback* callback);
+  void SetSingleInstanceCallback(const ProcessSingleton::NotificationCallback* callback);
 
 #if defined(OS_MACOSX)
   // Bounce the dock icon.
@@ -176,7 +176,7 @@ class Browser : public WindowListObserver {
   
   scoped_ptr<AtomProcessSingleton> process_singleton_;
   ProcessSingleton::NotifyResult process_notify_result_;
-  ProcessSingleton::NotificationCallback* process_notify_callback_;
+  const ProcessSingleton::NotificationCallback* process_notify_callback_;
 
 #if defined(OS_WIN)
   base::string16 app_user_model_id_;