#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"
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);
}
void Browser::DidFinishLaunching() {
is_ready_ = true;
+ process_singleton_->Unlock() ;
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
}
is_quiting_ = false;
return;
}
-
+
+ process_singleton_->Cleanup();
Shutdown();
}
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
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
#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"
// Clear the recent documents list.
void ClearRecentDocuments();
+
+ ProcessSingleton::NotifyResult GetSingleInstanceResult();
+ void SetSingleInstanceCallback(ProcessSingleton::NotificationCallback* callback);
#if defined(OS_MACOSX)
// Bounce the dock icon.
// 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_;
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_;