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_;
|
base::FilePath user_data_dir_;
|
||||||
ShouldKillRemoteProcessCallback should_kill_remote_process_callback_;
|
ShouldKillRemoteProcessCallback should_kill_remote_process_callback_;
|
||||||
#elif defined(OS_POSIX) && !defined(OS_ANDROID)
|
#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.
|
// 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
|
// Assumes that the current pid is the root of all pids of the current
|
||||||
// instance.
|
// instance.
|
||||||
|
|
|
@ -316,8 +316,7 @@ bool IsChromeProcess(pid_t pid) {
|
||||||
PathService::Get(base::FILE_EXE, &exec_path);
|
PathService::Get(base::FILE_EXE, &exec_path);
|
||||||
|
|
||||||
return (!other_chrome_path.empty() &&
|
return (!other_chrome_path.empty() &&
|
||||||
other_chrome_path.BaseName() ==
|
other_chrome_path.BaseName() == exec_path.BaseName());
|
||||||
exec_path.BaseName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A helper class to hold onto a socket.
|
// A helper class to hold onto a socket.
|
||||||
|
@ -988,13 +987,15 @@ bool ProcessSingleton::Create() {
|
||||||
if (listen(sock, 5) < 0)
|
if (listen(sock, 5) < 0)
|
||||||
NOTREACHED() << "listen failed: " << base::safe_strerror(errno);
|
NOTREACHED() << "listen failed: " << base::safe_strerror(errno);
|
||||||
|
|
||||||
DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
|
// In Electron the ProcessSingleton is created earlier than the IO
|
||||||
BrowserThread::PostTask(
|
// thread gets created, so we have to postpone the call until message
|
||||||
BrowserThread::IO,
|
// loop is up an running.
|
||||||
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner(
|
||||||
|
base::ThreadTaskRunnerHandle::Get());
|
||||||
|
task_runner->PostTask(
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::Bind(&ProcessSingleton::LinuxWatcher::StartListening,
|
base::Bind(&ProcessSingleton::StartListening,
|
||||||
watcher_.get(),
|
base::Unretained(this), sock));
|
||||||
sock));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1005,6 +1006,16 @@ void ProcessSingleton::Cleanup() {
|
||||||
UnlinkPath(lock_path_);
|
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) {
|
bool ProcessSingleton::IsSameChromeInstance(pid_t pid) {
|
||||||
pid_t cur_pid = current_pid_;
|
pid_t cur_pid = current_pid_;
|
||||||
while (pid != cur_pid) {
|
while (pid != cur_pid) {
|
||||||
|
|
Loading…
Reference in a new issue