Fix app.makeSingleInstance hanging on posix systems
Wait for the IO thread to be a thing before attempting to listen on the socket Fixes #9880
This commit is contained in:
parent
fb6a4febb0
commit
28900a9b63
4 changed files with 35 additions and 6 deletions
|
@ -577,6 +577,10 @@ void App::OnFinishLaunching(const base::DictionaryValue& launch_info) {
|
||||||
media::AudioManager::SetGlobalAppName(Browser::Get()->GetName());
|
media::AudioManager::SetGlobalAppName(Browser::Get()->GetName());
|
||||||
#endif
|
#endif
|
||||||
Emit("ready", launch_info);
|
Emit("ready", launch_info);
|
||||||
|
|
||||||
|
if (process_singleton_) {
|
||||||
|
process_singleton_->OnBrowserReady();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::OnAccessibilitySupportChanged() {
|
void App::OnAccessibilitySupportChanged() {
|
||||||
|
|
|
@ -74,6 +74,8 @@ class ProcessSingleton : public base::NonThreadSafe {
|
||||||
// TODO(brettw): Make the implementation of this method non-platform-specific
|
// TODO(brettw): Make the implementation of this method non-platform-specific
|
||||||
// by making Linux re-use the Windows implementation.
|
// by making Linux re-use the Windows implementation.
|
||||||
NotifyResult NotifyOtherProcessOrCreate();
|
NotifyResult NotifyOtherProcessOrCreate();
|
||||||
|
void StartListeningOnSocket();
|
||||||
|
void OnBrowserReady();
|
||||||
|
|
||||||
// Sets ourself up as the singleton instance. Returns true on success. If
|
// Sets ourself up as the singleton instance. Returns true on success. If
|
||||||
// false is returned, we are not the singleton instance and the caller must
|
// false is returned, we are not the singleton instance and the caller must
|
||||||
|
@ -173,6 +175,8 @@ class ProcessSingleton : public base::NonThreadSafe {
|
||||||
// because it posts messages between threads.
|
// because it posts messages between threads.
|
||||||
class LinuxWatcher;
|
class LinuxWatcher;
|
||||||
scoped_refptr<LinuxWatcher> watcher_;
|
scoped_refptr<LinuxWatcher> watcher_;
|
||||||
|
int sock_;
|
||||||
|
bool listen_on_ready_ = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(ProcessSingleton);
|
DISALLOW_COPY_AND_ASSIGN(ProcessSingleton);
|
||||||
|
|
|
@ -55,6 +55,7 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "atom/browser/browser.h"
|
||||||
#include "atom/common/atom_command_line.h"
|
#include "atom/common/atom_command_line.h"
|
||||||
|
|
||||||
#include "base/base_paths.h"
|
#include "base/base_paths.h"
|
||||||
|
@ -881,6 +882,22 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessOrCreate() {
|
||||||
base::TimeDelta::FromSeconds(kTimeoutInSeconds));
|
base::TimeDelta::FromSeconds(kTimeoutInSeconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProcessSingleton::StartListeningOnSocket() {
|
||||||
|
BrowserThread::PostTask(
|
||||||
|
BrowserThread::IO,
|
||||||
|
FROM_HERE,
|
||||||
|
base::Bind(&ProcessSingleton::LinuxWatcher::StartListening,
|
||||||
|
watcher_,
|
||||||
|
sock_));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessSingleton::OnBrowserReady() {
|
||||||
|
if (listen_on_ready_) {
|
||||||
|
StartListeningOnSocket();
|
||||||
|
listen_on_ready_ = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ProcessSingleton::NotifyResult
|
ProcessSingleton::NotifyResult
|
||||||
ProcessSingleton::NotifyOtherProcessWithTimeoutOrCreate(
|
ProcessSingleton::NotifyOtherProcessWithTimeoutOrCreate(
|
||||||
const base::CommandLine& command_line,
|
const base::CommandLine& command_line,
|
||||||
|
@ -1032,12 +1049,13 @@ bool ProcessSingleton::Create() {
|
||||||
NOTREACHED() << "listen failed: " << base::safe_strerror(errno);
|
NOTREACHED() << "listen failed: " << base::safe_strerror(errno);
|
||||||
|
|
||||||
DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
|
DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
|
||||||
BrowserThread::PostTask(
|
sock_ = sock;
|
||||||
BrowserThread::IO,
|
|
||||||
FROM_HERE,
|
if (atom::Browser::Get()->is_ready()) {
|
||||||
base::Bind(&ProcessSingleton::LinuxWatcher::StartListening,
|
StartListeningOnSocket();
|
||||||
watcher_,
|
} else {
|
||||||
sock));
|
listen_on_ready_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,6 +258,9 @@ ProcessSingleton::NotifyOtherProcessOrCreate() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProcessSingleton::StartListeningOnSocket() {}
|
||||||
|
void ProcessSingleton::OnBrowserReady() {}
|
||||||
|
|
||||||
// Look for a Chrome instance that uses the same profile directory. If there
|
// Look for a Chrome instance that uses the same profile directory. If there
|
||||||
// isn't one, create a message window with its title set to the profile
|
// isn't one, create a message window with its title set to the profile
|
||||||
// directory path.
|
// directory path.
|
||||||
|
|
Loading…
Add table
Reference in a new issue