]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix callback handle usage
authorPaul Betts <paul@paulbetts.org>
Tue, 20 Oct 2015 01:02:54 +0000 (18:02 -0700)
committerPaul Betts <paul@paulbetts.org>
Tue, 20 Oct 2015 20:17:25 +0000 (13:17 -0700)
atom/browser/api/atom_api_app.cc
atom/browser/api/atom_api_app.h
atom/browser/browser.cc
atom/browser/browser.h

index 2b60d2db965d30e1568500c55bb2ce5531f06bd8..7792fa6bc3a5f5089844fe623ab8621870e4fb5c 100644 (file)
@@ -269,10 +269,21 @@ v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
     return v8::Local<v8::Value>::New(isolate, default_session_);
 }
 
-bool App::MakeSingleInstance(const ProcessSingleton::NotificationCallback& callback) {
+bool App::OnProcessSingletonNotification(
+    const base::CommandLine& command_line,
+    const base::FilePath& current_directory) {
+  return true;
+}
+
+bool App::MakeSingleInstance(v8::Local<v8::Function> callback) {
+  single_instance_callback_ = callback;
+
   auto browser = Browser::Get();
-  browser->SetSingleInstanceCallback(&callback);
-  
+
+  auto no_refcount_this = base::Unretained(this);
+  browser->SetSingleInstanceCallback(
+    base::Bind(&App::OnProcessSingletonNotification, no_refcount_this));
+
   switch(browser->GetSingleInstanceResult()) {
     case ProcessSingleton::NotifyResult::PROCESS_NONE:
       return false;
index 10d4edf117f1849bdff4eae46c4b4c40a1610c3b..2d6a9f7f66b97201f945ee7f0cabff1fadea1caf 100644 (file)
@@ -70,11 +70,16 @@ class App : public mate::EventEmitter,
 
   void AllowNTLMCredentialsForAllDomains(bool should_allow);
 
-  bool MakeSingleInstance(const ProcessSingleton::NotificationCallback& callback);
+  bool MakeSingleInstance(v8::Local<v8::Function> callback);
+
+  bool OnProcessSingletonNotification(
+    const base::CommandLine& command_line,
+    const base::FilePath& current_directory);
 
   std::string GetLocale();
   v8::Local<v8::Value> DefaultSession(v8::Isolate* isolate);
 
+  v8::Local<v8::Function> single_instance_callback_;
   v8::Global<v8::Value> default_session_;
 
   DISALLOW_COPY_AND_ASSIGN(App);
index 39c348bcd6d20353b4c86056f7b0538b964c3408..f2ee8b42350a8fae268909e0811a52e0cf5f0727 100644 (file)
@@ -20,7 +20,7 @@ Browser::Browser()
     : is_quiting_(false),
       is_ready_(false),
       is_shutdown_(false),
-      process_notify_callback_(NULL) {
+      process_notify_callback_set_(false) {
   WindowList::AddObserver(this);
 }
 
@@ -169,11 +169,13 @@ bool Browser::HandleBeforeQuit() {
 }
 
 ProcessSingleton::NotifyResult Browser::GetSingleInstanceResult() {
+  LOG(ERROR) << "Process Notify Result: " << process_notify_result_;
   return process_notify_result_;
 }
-  
-void Browser::SetSingleInstanceCallback(const ProcessSingleton::NotificationCallback* callback) {
+
+void Browser::SetSingleInstanceCallback(const ProcessSingleton::NotificationCallback& callback) {
   process_notify_callback_ = callback;
+  process_notify_callback_set_ = true;
 }
 
 void Browser::OnWindowCloseCancelled(NativeWindow* window) {
@@ -193,8 +195,8 @@ void Browser::OnWindowAllClosed() {
 bool Browser::OnProcessSingletonNotification(
     const base::CommandLine& command_line,
     const base::FilePath& current_directory) {
-  if (process_notify_callback_) {
-    return (*process_notify_callback_).Run(command_line, current_directory);
+  if (process_notify_callback_set_) {
+    return process_notify_callback_.Run(command_line, current_directory);
   } else {
     return true;    // We'll handle this, not a different process
   }
index f14062232ca792f80521e7c0825b4a14cd68afdb..b84e220d27eb92497d7f77cab87cd3726b898c7b 100644 (file)
@@ -65,9 +65,9 @@ class Browser : public WindowListObserver {
 
   // Clear the recent documents list.
   void ClearRecentDocuments();
-  
+
   ProcessSingleton::NotifyResult GetSingleInstanceResult();
-  void SetSingleInstanceCallback(const ProcessSingleton::NotificationCallback* callback);
+  void SetSingleInstanceCallback(const ProcessSingleton::NotificationCallback& callback);
 
 #if defined(OS_MACOSX)
   // Bounce the dock icon.
@@ -173,10 +173,11 @@ class Browser : public WindowListObserver {
 
   std::string version_override_;
   std::string name_override_;
-  
+
   scoped_ptr<AtomProcessSingleton> process_singleton_;
   ProcessSingleton::NotifyResult process_notify_result_;
-  const ProcessSingleton::NotificationCallback* process_notify_callback_;
+  const ProcessSingleton::NotificationCallback process_notify_callback_;
+  bool process_notify_callback_set_;
 
 #if defined(OS_WIN)
   base::string16 app_user_model_id_;