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

Side by Side Diff: build/android/pylib/flag_changer.py

Issue 23467004: [android] Update FlagChanger to work with additional apks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 import constants 5 import constants
6 import logging 6 import logging
7 import traceback 7 import traceback
8 import warnings
9 8
10 9
11 # Location where chrome reads command line flags from
12 CHROME_COMMAND_FILE = '/data/local/chrome-command-line'
13
14 class FlagChanger(object): 10 class FlagChanger(object):
15 """Changes the flags Chrome runs with. 11 """Changes the flags Chrome runs with.
16 12
17 There are two different use cases for this file: 13 There are two different use cases for this file:
18 * Flags are permanently set by calling Set(). 14 * Flags are permanently set by calling Set().
19 * Flags can be temporarily set for a particular set of unit tests. These 15 * Flags can be temporarily set for a particular set of unit tests. These
20 tests should call Restore() to revert the flags to their original state 16 tests should call Restore() to revert the flags to their original state
21 once the tests have completed. 17 once the tests have completed.
22 """ 18 """
23 19
24 def __init__(self, android_cmd): 20 def __init__(self, adb, cmdline_file):
craigdh 2013/08/28 00:03:03 make cmdline_file optional so as not to break down
craigdh 2013/08/28 19:17:10 Done.
25 self._android_cmd = android_cmd 21 """Initializes the FlagChanger and records the original arguments.
22
23 Args:
24 adb: An instance of AndroidCommands.
25 cmdline_file: Path to the command line file on the device.
26 """
27 self._adb = adb
28 self._cmdline_file = cmdline_file
26 29
27 # Save the original flags. 30 # Save the original flags.
28 self._orig_line = self._android_cmd.GetFileContents(CHROME_COMMAND_FILE) 31 self._orig_line = self._adb.GetFileContents(self._cmdline_file)
29 if self._orig_line: 32 if self._orig_line:
30 self._orig_line = self._orig_line[0].strip() 33 self._orig_line = self._orig_line[0].strip()
31 34
32 # Parse out the flags into a list to facilitate adding and removing flags. 35 # Parse out the flags into a list to facilitate adding and removing flags.
33 self._current_flags = self._TokenizeFlags(self._orig_line) 36 self._current_flags = self._TokenizeFlags(self._orig_line)
34 37
35 def Get(self): 38 def Get(self):
36 """Returns list of current flags.""" 39 """Returns list of current flags."""
37 return self._current_flags 40 return self._current_flags
38 41
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 def Restore(self): 86 def Restore(self):
84 """Restores the flags to their original state.""" 87 """Restores the flags to their original state."""
85 self._current_flags = self._TokenizeFlags(self._orig_line) 88 self._current_flags = self._TokenizeFlags(self._orig_line)
86 self._UpdateCommandLineFile() 89 self._UpdateCommandLineFile()
87 90
88 def _UpdateCommandLineFile(self): 91 def _UpdateCommandLineFile(self):
89 """Writes out the command line to the file, or removes it if empty.""" 92 """Writes out the command line to the file, or removes it if empty."""
90 logging.info('Current flags: %s', self._current_flags) 93 logging.info('Current flags: %s', self._current_flags)
91 94
92 if self._current_flags: 95 if self._current_flags:
93 self._android_cmd.SetProtectedFileContents(CHROME_COMMAND_FILE, 96 # The first command line argument doesn't matter as we are not actually
94 'chrome ' + 97 # launching the chrome executable using this command line.
95 ' '.join(self._current_flags)) 98 self._adb.SetProtectedFileContents(self._cmdline_file,
99 ' '.join(['_'] + self._current_flags))
96 else: 100 else:
97 self._android_cmd.RunShellCommand('su -c rm ' + CHROME_COMMAND_FILE) 101 self._adb.RunShellCommand('su -c rm ' + self._cmdline_file)
98 102
99 def _TokenizeFlags(self, line): 103 def _TokenizeFlags(self, line):
100 """Changes the string containing the command line into a list of flags. 104 """Changes the string containing the command line into a list of flags.
101 105
102 Follows similar logic to CommandLine.java::tokenizeQuotedArguments: 106 Follows similar logic to CommandLine.java::tokenizeQuotedArguments:
103 * Flags are split using whitespace, unless the whitespace is within a 107 * Flags are split using whitespace, unless the whitespace is within a
104 pair of quotation marks. 108 pair of quotation marks.
105 * Unlike the Java version, we keep the quotation marks around switch 109 * Unlike the Java version, we keep the quotation marks around switch
106 values since we need them to re-create the file when new flags are 110 values since we need them to re-create the file when new flags are
107 appended. 111 appended.
(...skipping 22 matching lines...) Expand all
130 elif not within_quotations and (c is ' ' or c is '\t'): 134 elif not within_quotations and (c is ' ' or c is '\t'):
131 if current_flag is not "": 135 if current_flag is not "":
132 tokenized_flags.append(current_flag) 136 tokenized_flags.append(current_flag)
133 current_flag = "" 137 current_flag = ""
134 else: 138 else:
135 current_flag += c 139 current_flag += c
136 140
137 # Tack on the last flag. 141 # Tack on the last flag.
138 if not current_flag: 142 if not current_flag:
139 if within_quotations: 143 if within_quotations:
140 warnings.warn("Unterminated quoted string: " + current_flag) 144 logging.warn("Unterminated quoted argument: " + current_flag)
frankf 2013/08/27 23:57:46 single quote
craigdh 2013/08/28 19:17:10 Done.
141 else: 145 else:
142 tokenized_flags.append(current_flag) 146 tokenized_flags.append(current_flag)
143 147
144 # Return everything but the program name. 148 # Return everything but the program name.
145 return tokenized_flags[1:] 149 return tokenized_flags[1:]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698