Fix callback handle usage

This commit is contained in:
Paul Betts 2015-10-19 18:02:54 -07:00
parent 50fab0733b
commit 4a4b829cfc
4 changed files with 32 additions and 13 deletions

View file

@ -269,10 +269,21 @@ v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
return v8::Local<v8::Value>::New(isolate, default_session_); 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(); 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()) { switch(browser->GetSingleInstanceResult()) {
case ProcessSingleton::NotifyResult::PROCESS_NONE: case ProcessSingleton::NotifyResult::PROCESS_NONE:
return false; return false;

View file

@ -70,11 +70,16 @@ class App : public mate::EventEmitter,
void AllowNTLMCredentialsForAllDomains(bool should_allow); 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(); std::string GetLocale();
v8::Local<v8::Value> DefaultSession(v8::Isolate* isolate); v8::Local<v8::Value> DefaultSession(v8::Isolate* isolate);
v8::Local<v8::Function> single_instance_callback_;
v8::Global<v8::Value> default_session_; v8::Global<v8::Value> default_session_;
DISALLOW_COPY_AND_ASSIGN(App); DISALLOW_COPY_AND_ASSIGN(App);

View file

@ -20,7 +20,7 @@ Browser::Browser()
: is_quiting_(false), : is_quiting_(false),
is_ready_(false), is_ready_(false),
is_shutdown_(false), is_shutdown_(false),
process_notify_callback_(NULL) { process_notify_callback_set_(false) {
WindowList::AddObserver(this); WindowList::AddObserver(this);
} }
@ -169,11 +169,13 @@ bool Browser::HandleBeforeQuit() {
} }
ProcessSingleton::NotifyResult Browser::GetSingleInstanceResult() { ProcessSingleton::NotifyResult Browser::GetSingleInstanceResult() {
LOG(ERROR) << "Process Notify Result: " << process_notify_result_;
return 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_ = callback;
process_notify_callback_set_ = true;
} }
void Browser::OnWindowCloseCancelled(NativeWindow* window) { void Browser::OnWindowCloseCancelled(NativeWindow* window) {
@ -193,8 +195,8 @@ void Browser::OnWindowAllClosed() {
bool Browser::OnProcessSingletonNotification( bool Browser::OnProcessSingletonNotification(
const base::CommandLine& command_line, const base::CommandLine& command_line,
const base::FilePath& current_directory) { const base::FilePath& current_directory) {
if (process_notify_callback_) { if (process_notify_callback_set_) {
return (*process_notify_callback_).Run(command_line, current_directory); return process_notify_callback_.Run(command_line, current_directory);
} else { } else {
return true; // We'll handle this, not a different process return true; // We'll handle this, not a different process
} }

View file

@ -65,9 +65,9 @@ class Browser : public WindowListObserver {
// Clear the recent documents list. // Clear the recent documents list.
void ClearRecentDocuments(); void ClearRecentDocuments();
ProcessSingleton::NotifyResult GetSingleInstanceResult(); ProcessSingleton::NotifyResult GetSingleInstanceResult();
void SetSingleInstanceCallback(const ProcessSingleton::NotificationCallback* callback); void SetSingleInstanceCallback(const ProcessSingleton::NotificationCallback& callback);
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
// Bounce the dock icon. // Bounce the dock icon.
@ -173,10 +173,11 @@ class Browser : public WindowListObserver {
std::string version_override_; std::string version_override_;
std::string name_override_; std::string name_override_;
scoped_ptr<AtomProcessSingleton> process_singleton_; scoped_ptr<AtomProcessSingleton> process_singleton_;
ProcessSingleton::NotifyResult process_notify_result_; 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) #if defined(OS_WIN)
base::string16 app_user_model_id_; base::string16 app_user_model_id_;