Set up Browser to create the process singleton
This commit is contained in:
parent
4d5495a0a0
commit
7491ae4000
2 changed files with 48 additions and 2 deletions
|
@ -9,6 +9,8 @@
|
|||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "base/path_service.h"
|
||||
#include "brightray/browser/brightray_paths.h"
|
||||
#include "content/public/browser/client_certificate_delegate.h"
|
||||
#include "net/ssl/ssl_cert_request_info.h"
|
||||
|
||||
|
@ -17,7 +19,18 @@ namespace atom {
|
|||
Browser::Browser()
|
||||
: is_quiting_(false),
|
||||
is_ready_(false),
|
||||
is_shutdown_(false) {
|
||||
is_shutdown_(false),
|
||||
process_notify_callback_(NULL) {
|
||||
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();
|
||||
|
||||
WindowList::AddObserver(this);
|
||||
}
|
||||
|
||||
|
@ -114,6 +127,7 @@ void Browser::WillFinishLaunching() {
|
|||
|
||||
void Browser::DidFinishLaunching() {
|
||||
is_ready_ = true;
|
||||
process_singleton_->Unlock() ;
|
||||
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
|
||||
}
|
||||
|
||||
|
@ -139,7 +153,8 @@ void Browser::NotifyAndShutdown() {
|
|||
is_quiting_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
process_singleton_->Cleanup();
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
|
@ -152,6 +167,14 @@ bool Browser::HandleBeforeQuit() {
|
|||
return !prevent_default;
|
||||
}
|
||||
|
||||
ProcessSingleton::NotifyResult Browser::GetSingleInstanceResult() {
|
||||
return process_notify_result_;
|
||||
}
|
||||
|
||||
void Browser::SetSingleInstanceCallback(ProcessSingleton::NotificationCallback* callback) {
|
||||
process_notify_callback_ = callback;
|
||||
}
|
||||
|
||||
void Browser::OnWindowCloseCancelled(NativeWindow* window) {
|
||||
if (is_quiting_)
|
||||
// Once a beforeunload handler has prevented the closing, we think the quit
|
||||
|
@ -166,4 +189,14 @@ void Browser::OnWindowAllClosed() {
|
|||
FOR_EACH_OBSERVER(BrowserObserver, observers_, 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);
|
||||
} else {
|
||||
return true; // We'll handle this, not a different process
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
#include <vector>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "atom/browser/atom_process_singleton.h"
|
||||
#include "atom/browser/browser_observer.h"
|
||||
#include "atom/browser/window_list_observer.h"
|
||||
|
||||
|
@ -63,6 +65,9 @@ class Browser : public WindowListObserver {
|
|||
|
||||
// Clear the recent documents list.
|
||||
void ClearRecentDocuments();
|
||||
|
||||
ProcessSingleton::NotifyResult GetSingleInstanceResult();
|
||||
void SetSingleInstanceCallback(ProcessSingleton::NotificationCallback* callback);
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
// Bounce the dock icon.
|
||||
|
@ -152,6 +157,10 @@ 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);
|
||||
|
||||
// Observers of the browser.
|
||||
base::ObserverList<BrowserObserver> observers_;
|
||||
|
@ -164,6 +173,10 @@ class Browser : public WindowListObserver {
|
|||
|
||||
std::string version_override_;
|
||||
std::string name_override_;
|
||||
|
||||
scoped_ptr<AtomProcessSingleton> process_singleton_;
|
||||
ProcessSingleton::NotifyResult process_notify_result_;
|
||||
ProcessSingleton::NotificationCallback* process_notify_callback_;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
base::string16 app_user_model_id_;
|
||||
|
|
Loading…
Reference in a new issue