def BindDevToolsClient(self): # In addition to the work performed by the base class, quickly check if # the browser process is still alive. if not self.IsBrowserRunning(): raise exceptions.ProcessGoneException('Return code: %d' % self._proc.returncode) super(DesktopBrowserBackend, self).BindDevToolsClient()
def HasBrowserFinishedLaunching(self): # In addition to the functional check performed by the base class, quickly # check if the browser process is still alive. if not self.IsBrowserRunning(): raise exceptions.ProcessGoneException("Return code: %d" % self._proc.returncode) # Start DevTools on an ephemeral port and wait for the well-known file # containing the port number to exist. port_file = self._GetDevToolsActivePortPath() if not os.path.isfile(port_file): # File isn't ready yet. Return false. Will retry. return False # Attempt to avoid reading the file until it's populated. got_port = False try: if os.stat(port_file).st_size > 0: with open(port_file) as f: port_string = f.read() self._port = int(port_string) logging.info('Discovered ephemeral port %s' % self._port) got_port = True except Exception: # Both stat and open can throw exceptions. pass if not got_port: # File isn't ready yet. Return false. Will retry. return False return super(DesktopBrowserBackend, self).HasBrowserFinishedLaunching()
def _GetProcFileForPid(self, pid, filename): try: return self.GetFileContents('/proc/%s/%s' % (pid, filename)) except IOError: if not self._IsPidAlive(pid): raise exceptions.ProcessGoneException() raise
def HasBrowserFinishedLaunching(self): # In addition to the functional check performed by the base class, quickly # check if the browser process is still alive. if not self.IsBrowserRunning(): raise exceptions.ProcessGoneException("Return code: %d" % self._proc.returncode) return super(DesktopMandolineBackend, self).HasBrowserFinishedLaunching()
def _GetWin32ProcessInfo(self, func, pid): try: return func(self._GetProcessHandle(pid)) except pywintypes.error, e: errcode = e[0] if errcode == 87: raise exceptions.ProcessGoneException() raise
def _GetWin32ProcessInfo(self, func, pid): mask = (win32con.PROCESS_QUERY_INFORMATION | win32con.PROCESS_VM_READ) handle = None try: handle = win32api.OpenProcess(mask, False, pid) return func(handle) except pywintypes.error, e: errcode = e[0] if errcode == 87: raise exceptions.ProcessGoneException() raise
def _GetDevToolsClientConfig(self): # TODO(crbug.com/787834): Split into reading DevToolsActivePort, retrying # if needed, and setting up fowarder. # In addition to the functional check performed by the base class, quickly # check if the browser process is still alive. if not self.IsBrowserRunning(): raise exceptions.ProcessGoneException("Return code: %d" % self._proc.returncode) # Start DevTools on an ephemeral port and wait for the well-known file # containing the port number to exist. port_file = self._GetDevToolsActivePortPath() if not os.path.isfile(port_file): # File isn't ready yet. Return false. Will retry. return False # Attempt to avoid reading the file until it's populated. got_port = False try: if os.stat(port_file).st_size > 0: with open(port_file) as f: port_target = f.read().split('\n') local_port = int(port_target[0]) if len(port_target) > 1 and port_target[1]: browser_target = port_target[1] else: browser_target = None logging.info('Discovered ephemeral port %s', local_port) logging.info('Browser target: %s', browser_target) got_port = True except IOError: # Both stat and open can throw exceptions. pass if not got_port: # File isn't ready yet. Return false. Will retry. return False return devtools_client_backend.DevToolsClientConfig( local_port=local_port, browser_target=browser_target, app_backend=self)
def GetCommandLine(self, pid): try: return next(p.name for p in self._device.ListProcesses() if p.pid == pid) except StopIteration: raise exceptions.ProcessGoneException()
def GetCommandLine(self, pid): ps = self._GetPsOutput(['pid', 'name'], pid) if not ps: raise exceptions.ProcessGoneException() return ps[0][1]
def GetCommandLine(self, pid): for pi in self.GetSystemProcessInfo(): if pid == pi['ProcessId']: return pi['CommandLine'] raise exceptions.ProcessGoneException()
def GetCommandLine(self, pid): ps = self._GetPsOutput(['pid', 'name']) for curr_pid, curr_name in ps: if int(curr_pid) == pid: return curr_name raise exceptions.ProcessGoneException()