linux: Delay listening to socket until message loop is ready
This commit is contained in:
parent
05c6300329
commit
f01e84a418
2 changed files with 22 additions and 8 deletions
|
@ -133,6 +133,9 @@ class ProcessSingleton : public base::NonThreadSafe {
|
|||
base::FilePath user_data_dir_;
|
||||
ShouldKillRemoteProcessCallback should_kill_remote_process_callback_;
|
||||
#elif defined(OS_POSIX) && !defined(OS_ANDROID)
|
||||
// Start listening to the socket.
|
||||
void StartListening(int sock);
|
||||
|
||||
// Return true if the given pid is one of our child processes.
|
||||
// Assumes that the current pid is the root of all pids of the current
|
||||
// instance.
|
||||
|
|
|
@ -316,8 +316,7 @@ bool IsChromeProcess(pid_t pid) {
|
|||
PathService::Get(base::FILE_EXE, &exec_path);
|
||||
|
||||
return (!other_chrome_path.empty() &&
|
||||
other_chrome_path.BaseName() ==
|
||||
exec_path.BaseName());
|
||||
other_chrome_path.BaseName() == exec_path.BaseName());
|
||||
}
|
||||
|
||||
// A helper class to hold onto a socket.
|
||||
|
@ -988,13 +987,15 @@ bool ProcessSingleton::Create() {
|
|||
if (listen(sock, 5) < 0)
|
||||
NOTREACHED() << "listen failed: " << base::safe_strerror(errno);
|
||||
|
||||
DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO,
|
||||
// In Electron the ProcessSingleton is created earlier than the IO
|
||||
// thread gets created, so we have to postpone the call until message
|
||||
// loop is up an running.
|
||||
scoped_refptr<base::SingleThreadTaskRunner> task_runner(
|
||||
base::ThreadTaskRunnerHandle::Get());
|
||||
task_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&ProcessSingleton::LinuxWatcher::StartListening,
|
||||
watcher_.get(),
|
||||
sock));
|
||||
base::Bind(&ProcessSingleton::StartListening,
|
||||
base::Unretained(this), sock));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1005,6 +1006,16 @@ void ProcessSingleton::Cleanup() {
|
|||
UnlinkPath(lock_path_);
|
||||
}
|
||||
|
||||
void ProcessSingleton::StartListening(int sock) {
|
||||
DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO,
|
||||
FROM_HERE,
|
||||
base::Bind(&ProcessSingleton::LinuxWatcher::StartListening,
|
||||
watcher_.get(),
|
||||
sock));
|
||||
}
|
||||
|
||||
bool ProcessSingleton::IsSameChromeInstance(pid_t pid) {
|
||||
pid_t cur_pid = current_pid_;
|
||||
while (pid != cur_pid) {
|
||||
|
|
Loading…
Reference in a new issue