+ def _GetSessionManagerPid(self, procs):
+ """Returns the pid of the session_manager process, given the list of
+ processes."""
+ for pid, process, _, _ in procs:
+ if process.startswith('/sbin/session_manager '):
+ return pid
+ return None
+
+ def GetChromeProcess(self):
+ """Locates the the main chrome browser process.
+
+ Chrome on cros is usually in /opt/google/chrome, but could be in
+ /usr/local/ for developer workflows - debug chrome is too large to fit on
+ rootfs.
+
+ Chrome spawns multiple processes for renderers. pids wrap around after they
+ are exhausted so looking for the smallest pid is not always correct. We
+ locate the session_manager's pid, and look for the chrome process that's an
+ immediate child. This is the main browser process.
+ """
+ procs = self.ListProcesses()
+ session_manager_pid = self._GetSessionManagerPid(procs)
+ if not session_manager_pid:
+ return None
+
+ # Find the chrome process that is the child of the session_manager.
+ for pid, process, ppid, _ in procs:
+ if ppid != session_manager_pid:
+ continue
+ for path in _CHROME_PATHS:
+ if process.startswith(path):
+ return {'pid': pid, 'path': path, 'args': process}
+ return None
+
+ def GetChromePid(self):
+ """Returns pid of main chrome browser process."""
+ result = self.GetChromeProcess()
+ if result and 'pid' in result:
+ return result['pid']
+ return None
+