Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: tools/telemetry/telemetry/core/backends/android_command_line_backend.py

Issue 811703007: Create AndroidCommandLineBackend to handle setting up cmdline args (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/core/backends/android_command_line_backend.py
diff --git a/tools/telemetry/telemetry/core/backends/android_command_line_backend.py b/tools/telemetry/telemetry/core/backends/android_command_line_backend.py
new file mode 100644
index 0000000000000000000000000000000000000000..4c8b76bb481f94cc9cd4418edf819da9b2ab4262
--- /dev/null
+++ b/tools/telemetry/telemetry/core/backends/android_command_line_backend.py
@@ -0,0 +1,69 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging
+import pipes
+import sys
+
+from telemetry.core import util
+
+util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android')
+from pylib.device import device_errors # pylint: disable=F0401
+
+
+def QuoteIfNeeded(arg):
nednguyen 2015/01/13 16:03:04 Please make this private & add unittest for it.
ariblue 2015/01/13 20:23:37 Done.
+ # Properly escape "key=valueA valueB" to "key='valueA valueB'"
+ # Values without spaces, or that seem to be quoted are left untouched.
+ # This is required so CommandLine.java can parse valueB correctly rather
+ # than as a separate switch.
+ params = arg.split('=', 1)
+ if len(params) != 2:
+ return arg
+ key, values = params
+ if ' ' not in values:
+ return arg
+ if values[0] in '"\'' and values[-1] == values[0]:
+ return arg
+ return '%s=%s' % (key, pipes.quote(values))
+
+
+class AndroidCommandLineBackend(object):
+
nednguyen 2015/01/13 16:03:04 Can you add pydoc for this class?
ariblue 2015/01/13 20:23:37 Done.
+ def __init__(self, adb, backend_settings, startup_args):
+ self._adb = adb
+ self._backend_settings = backend_settings
+ self._startup_args = startup_args
+ self._saved_command_line_file_contents = ''
+
+ @property
+ def command_line_file(self):
+ return self._backend_settings.GetCommandLineFile(self._adb.IsUserBuild())
+
+ def SetUpCommandLine(self):
+ args = [self._backend_settings.pseudo_exec_name]
+ args.extend(self._startup_args)
+ content = ' '.join(QuoteIfNeeded(arg) for arg in args)
+
+ try:
+ # Save the current command line to restore later, except if it appears to
+ # be a Telemetry created one. This is to prevent a common bug where
+ # --host-resolver-rules borks people's browsers if something goes wrong
+ # with Telemetry.
+ self._saved_command_line_file_contents = ''.join(self._ReadFile())
+ if '--host-resolver-rules' in self._saved_command_line_file_contents:
+ self._saved_command_line_file_contents = ''
+ self._WriteFile(content)
+ except device_errors.CommandFailedError:
+ logging.critical('Cannot set Chrome command line. '
+ 'Fix this by flashing to a userdebug build.')
+ sys.exit(1)
+
+ def RestoreCommandLine(self):
+ self._WriteFile(self._saved_command_line_file_contents)
+
+ def _ReadFile(self):
+ return self._adb.device().ReadFile(self.command_line_file)
+
+ def _WriteFile(self, contents):
+ self._adb.device().WriteFile(self.command_line_file, contents, as_root=True)

Powered by Google App Engine
This is Rietveld 408576698