Singleton must be created on request

The creation of singleton relies on the `userData` dir, which can be
changed by user, we have to ensure singleton uses the `userData` dir set
by user.
This commit is contained in:
Cheng Zhao 2018-01-03 18:59:12 +09:00
parent 0cce6b3d21
commit 952928dc79
7 changed files with 41 additions and 46 deletions

View file

@ -565,6 +565,11 @@ void App::OnWindowAllClosed() {
void App::OnQuit() {
int exitCode = AtomBrowserMainParts::Get()->GetExitCode();
Emit("quit", exitCode);
if (process_singleton_) {
process_singleton_->Cleanup();
process_singleton_.reset();
}
}
void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
@ -592,12 +597,15 @@ void App::OnFinishLaunching(const base::DictionaryValue& launch_info) {
Emit("ready", launch_info);
}
void App::OnAccessibilitySupportChanged() {
Emit("accessibility-support-changed", IsAccessibilitySupportEnabled());
}
void App::OnPreMainMessageLoopRun() {
content::BrowserChildProcessObserver::Add(this);
if (process_singleton_) {
process_singleton_->OnBrowserReady();
}
}
void App::OnAccessibilitySupportChanged() {
Emit("accessibility-support-changed", IsAccessibilitySupportEnabled());
}
#if defined(OS_MACOSX)
@ -848,18 +856,19 @@ std::string App::GetLocale() {
bool App::MakeSingleInstance(
const ProcessSingleton::NotificationCallback& callback) {
auto process_singleton = AtomBrowserMainParts::Get()->process_singleton();
if (process_singleton_created_)
if (process_singleton_)
return false;
process_singleton->RegisterSingletonNotificationCallback(
base::Bind(NotificationCallbackWrapper, callback));
base::FilePath user_dir;
PathService::Get(brightray::DIR_USER_DATA, &user_dir);
process_singleton_.reset(new ProcessSingleton(
user_dir, base::Bind(NotificationCallbackWrapper, callback)));
switch (process_singleton->NotifyOtherProcessOrCreate()) {
switch (process_singleton_->NotifyOtherProcessOrCreate()) {
case ProcessSingleton::NotifyResult::LOCK_ERROR:
case ProcessSingleton::NotifyResult::PROFILE_IN_USE:
case ProcessSingleton::NotifyResult::PROCESS_NOTIFIED: {
process_singleton_created_ = true;
process_singleton_.reset();
return true;
}
case ProcessSingleton::NotifyResult::PROCESS_NONE:
@ -869,9 +878,9 @@ bool App::MakeSingleInstance(
}
void App::ReleaseSingleInstance() {
auto process_singleton = AtomBrowserMainParts::Get()->process_singleton();
if (process_singleton) {
process_singleton->Cleanup();
if (process_singleton_) {
process_singleton_->Cleanup();
process_singleton_.reset();
}
}