diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 2b60d2db96..7792fa6bc3 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -269,10 +269,21 @@ v8::Local App::DefaultSession(v8::Isolate* isolate) { return v8::Local::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 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; diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 10d4edf117..2d6a9f7f66 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -70,11 +70,16 @@ class App : public mate::EventEmitter, void AllowNTLMCredentialsForAllDomains(bool should_allow); - bool MakeSingleInstance(const ProcessSingleton::NotificationCallback& callback); + bool MakeSingleInstance(v8::Local callback); + + bool OnProcessSingletonNotification( + const base::CommandLine& command_line, + const base::FilePath& current_directory); std::string GetLocale(); v8::Local DefaultSession(v8::Isolate* isolate); + v8::Local single_instance_callback_; v8::Global default_session_; DISALLOW_COPY_AND_ASSIGN(App); diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 39c348bcd6..f2ee8b4235 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -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 } diff --git a/atom/browser/browser.h b/atom/browser/browser.h index f14062232c..b84e220d27 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -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 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_;