Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Controller objects that control the context in which chrome runs. | 5 """Controller objects that control the context in which chrome runs. |
| 6 | 6 |
| 7 This is responsible for the setup necessary for launching chrome, and for | 7 This is responsible for the setup necessary for launching chrome, and for |
| 8 creating a DevToolsConnection. There are remote device and local | 8 creating a DevToolsConnection. There are remote device and local |
| 9 desktop-specific versions. | 9 desktop-specific versions. |
| 10 """ | 10 """ |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 output.write(''.join(traceback.format_list(self.parent_stack))) | 108 output.write(''.join(traceback.format_list(self.parent_stack))) |
| 109 traceback.print_tb(self.error_traceback, file=output) | 109 traceback.print_tb(self.error_traceback, file=output) |
| 110 output.write('-' * 60 + ' Begin log\n') | 110 output.write('-' * 60 + ' Begin log\n') |
| 111 output.write(self.log) | 111 output.write(self.log) |
| 112 output.write('-' * 60 + ' End log\n') | 112 output.write('-' * 60 + ' End log\n') |
| 113 | 113 |
| 114 def IsIntermittent(self): | 114 def IsIntermittent(self): |
| 115 """Returns whether the error is an known intermittent error.""" | 115 """Returns whether the error is an known intermittent error.""" |
| 116 return self.error_type in self._INTERMITTENT_WHITE_LIST | 116 return self.error_type in self._INTERMITTENT_WHITE_LIST |
| 117 | 117 |
| 118 def RaiseOriginal(self): | |
| 119 """Raises the original exception that has caused <self>.""" | |
| 120 raise self.error_type, self.error_value, self.error_traceback | |
| 121 | |
| 118 | 122 |
| 119 class ChromeControllerBase(object): | 123 class ChromeControllerBase(object): |
| 120 """Base class for all controllers. | 124 """Base class for all controllers. |
| 121 | 125 |
| 122 Defines common operations but should not be created directly. | 126 Defines common operations but should not be created directly. |
| 123 """ | 127 """ |
| 124 METADATA_GATHERER = ChromeControllerMetadataGatherer() | 128 METADATA_GATHERER = ChromeControllerMetadataGatherer() |
| 125 DEVTOOLS_CONNECTION_ATTEMPTS = 10 | 129 DEVTOOLS_CONNECTION_ATTEMPTS = 10 |
| 126 DEVTOOLS_CONNECTION_ATTEMPT_INTERVAL_SECONDS = 1 | 130 DEVTOOLS_CONNECTION_ATTEMPT_INTERVAL_SECONDS = 1 |
| 127 | 131 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 assert self._wpr_attributes.chrome_env_override == {}, \ | 323 assert self._wpr_attributes.chrome_env_override == {}, \ |
| 320 'Remote controller doesn\'t support chrome environment variables.' | 324 'Remote controller doesn\'t support chrome environment variables.' |
| 321 package_info = OPTIONS.ChromePackage() | 325 package_info = OPTIONS.ChromePackage() |
| 322 command_line_path = '/data/local/chrome-command-line' | 326 command_line_path = '/data/local/chrome-command-line' |
| 323 self._device.ForceStop(package_info.package) | 327 self._device.ForceStop(package_info.package) |
| 324 chrome_args = self._GetChromeArguments() | 328 chrome_args = self._GetChromeArguments() |
| 325 logging.info('Launching %s with flags: %s' % (package_info.package, | 329 logging.info('Launching %s with flags: %s' % (package_info.package, |
| 326 subprocess.list2cmdline(chrome_args))) | 330 subprocess.list2cmdline(chrome_args))) |
| 327 with device_setup.FlagReplacer( | 331 with device_setup.FlagReplacer( |
| 328 self._device, command_line_path, self._GetChromeArguments()): | 332 self._device, command_line_path, self._GetChromeArguments()): |
| 333 self._DismissCrashDialogIfNeeded() | |
| 329 start_intent = intent.Intent( | 334 start_intent = intent.Intent( |
| 330 package=package_info.package, activity=package_info.activity, | 335 package=package_info.package, activity=package_info.activity, |
| 331 data='about:blank') | 336 data='about:blank') |
| 332 self._device.adb.Logcat(clear=True, dump=True) | 337 self._device.adb.Logcat(clear=True, dump=True) |
| 333 self._device.StartActivity(start_intent, blocking=True) | 338 self._device.StartActivity(start_intent, blocking=True) |
| 334 try: | 339 try: |
| 335 for attempt_id in xrange(self.DEVTOOLS_CONNECTION_ATTEMPTS): | 340 for attempt_id in xrange(self.DEVTOOLS_CONNECTION_ATTEMPTS): |
| 336 logging.info('Devtools connection attempt %d' % attempt_id) | 341 logging.info('Devtools connection attempt %d' % attempt_id) |
| 337 with device_setup.ForwardPort( | 342 with device_setup.ForwardPort( |
| 338 self._device, 'tcp:%d' % OPTIONS.devtools_port, | 343 self._device, 'tcp:%d' % OPTIONS.devtools_port, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 355 raise ChromeControllerInternalError( | 360 raise ChromeControllerInternalError( |
| 356 'Failed to connect to Chrome devtools after {} ' | 361 'Failed to connect to Chrome devtools after {} ' |
| 357 'attempts.'.format(self.DEVTOOLS_CONNECTION_ATTEMPTS)) | 362 'attempts.'.format(self.DEVTOOLS_CONNECTION_ATTEMPTS)) |
| 358 except ChromeControllerError._PASSTHROUGH_WHITE_LIST: | 363 except ChromeControllerError._PASSTHROUGH_WHITE_LIST: |
| 359 raise | 364 raise |
| 360 except Exception: | 365 except Exception: |
| 361 logcat = ''.join([l + '\n' for l in self._device.adb.Logcat(dump=True)]) | 366 logcat = ''.join([l + '\n' for l in self._device.adb.Logcat(dump=True)]) |
| 362 raise ChromeControllerError(log=logcat) | 367 raise ChromeControllerError(log=logcat) |
| 363 finally: | 368 finally: |
| 364 self._device.ForceStop(package_info.package) | 369 self._device.ForceStop(package_info.package) |
| 370 self._DismissCrashDialogIfNeeded() | |
| 365 | 371 |
| 366 def ResetBrowserState(self): | 372 def ResetBrowserState(self): |
| 367 """Override resetting Chrome local state.""" | 373 """Override resetting Chrome local state.""" |
| 368 logging.info('Resetting Chrome local state') | 374 logging.info('Resetting Chrome local state') |
| 369 package = OPTIONS.ChromePackage().package | 375 package = OPTIONS.ChromePackage().package |
| 370 # Remove the Chrome Profile and the various disk caches. Other parts | 376 # Remove the Chrome Profile and the various disk caches. Other parts |
| 371 # theoretically should not affect loading performance. Also remove the tab | 377 # theoretically should not affect loading performance. Also remove the tab |
| 372 # state to prevent it from growing infinitely. [:D] | 378 # state to prevent it from growing infinitely. [:D] |
| 373 for directory in ['app_chrome/Default', 'cache', 'app_chrome/ShaderCache', | 379 for directory in ['app_chrome/Default', 'cache', 'app_chrome/ShaderCache', |
| 374 'app_tabs']: | 380 'app_tabs']: |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 395 assert not self._wpr_attributes, 'WPR is already running.' | 401 assert not self._wpr_attributes, 'WPR is already running.' |
| 396 with device_setup.RemoteWprHost(self._device, wpr_archive_path, | 402 with device_setup.RemoteWprHost(self._device, wpr_archive_path, |
| 397 record=record, | 403 record=record, |
| 398 network_condition_name=network_condition_name, | 404 network_condition_name=network_condition_name, |
| 399 disable_script_injection=disable_script_injection, | 405 disable_script_injection=disable_script_injection, |
| 400 out_log_path=out_log_path) as wpr_attributes: | 406 out_log_path=out_log_path) as wpr_attributes: |
| 401 self._wpr_attributes = wpr_attributes | 407 self._wpr_attributes = wpr_attributes |
| 402 yield | 408 yield |
| 403 self._wpr_attributes = None | 409 self._wpr_attributes = None |
| 404 | 410 |
| 411 def _DismissCrashDialogIfNeeded(self): | |
| 412 for _ in xrange(10): | |
| 413 if not self._device.DismissCrashDialogIfNeeded(): | |
| 414 break | |
|
gabadie
2016/06/06 13:40:37
FYI: copy pasted from https://cs.chromium.org/chro
pasko
2016/06/06 13:58:52
Thanks for the pointer. Ugh.
| |
| 415 | |
| 405 | 416 |
| 406 class LocalChromeController(ChromeControllerBase): | 417 class LocalChromeController(ChromeControllerBase): |
| 407 """Controller for a local (desktop) chrome instance.""" | 418 """Controller for a local (desktop) chrome instance.""" |
| 408 | 419 |
| 409 def __init__(self): | 420 def __init__(self): |
| 410 """Initialize the controller. | 421 """Initialize the controller. |
| 411 | 422 |
| 412 Caution: The browser state might need to be manually reseted. | 423 Caution: The browser state might need to be manually reseted. |
| 413 """ | 424 """ |
| 414 super(LocalChromeController, self).__init__() | 425 super(LocalChromeController, self).__init__() |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 if (not os.path.isdir(self._profile_dir) or | 600 if (not os.path.isdir(self._profile_dir) or |
| 590 os.listdir(self._profile_dir) == []): | 601 os.listdir(self._profile_dir) == []): |
| 591 # Launch chrome so that it populates the profile directory. | 602 # Launch chrome so that it populates the profile directory. |
| 592 with self.Open(): | 603 with self.Open(): |
| 593 pass | 604 pass |
| 594 assert os.path.isdir(self._profile_dir) | 605 assert os.path.isdir(self._profile_dir) |
| 595 assert os.path.isdir(os.path.dirname(self._GetCacheDirectoryPath())) | 606 assert os.path.isdir(os.path.dirname(self._GetCacheDirectoryPath())) |
| 596 | 607 |
| 597 def _GetCacheDirectoryPath(self): | 608 def _GetCacheDirectoryPath(self): |
| 598 return os.path.join(self._profile_dir, 'Default', 'Cache') | 609 return os.path.join(self._profile_dir, 'Default', 'Cache') |
| OLD | NEW |