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

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: 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 8 import warnings
9 9
10 10
11 # Location where chrome reads command line flags from
12 CHROME_COMMAND_FILE = '/data/local/chrome-command-line'
13
14 class FlagChanger(object): 11 class FlagChanger(object):
15 """Changes the flags Chrome runs with. 12 """Changes the flags Chrome runs with.
16 13
17 There are two different use cases for this file: 14 There are two different use cases for this file:
18 * Flags are permanently set by calling Set(). 15 * Flags are permanently set by calling Set().
19 * Flags can be temporarily set for a particular set of unit tests. These 16 * 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 17 tests should call Restore() to revert the flags to their original state
21 once the tests have completed. 18 once the tests have completed.
22 """ 19 """
23 20
24 def __init__(self, android_cmd): 21 def __init__(self, adb, cmdline_file):
frankf 2013/08/27 00:28:09 add docstring
craigdh 2013/08/27 17:26:13 Done.
25 self._android_cmd = android_cmd 22 self._adb = adb
23 self._cmdline_file = cmdline_file
26 24
27 # Save the original flags. 25 # Save the original flags.
28 self._orig_line = self._android_cmd.GetFileContents(CHROME_COMMAND_FILE) 26 self._orig_line = self._adb.GetFileContents(self._cmdline_file)
29 if self._orig_line: 27 if self._orig_line:
30 self._orig_line = self._orig_line[0].strip() 28 self._orig_line = self._orig_line[0].strip()
31 29
32 # Parse out the flags into a list to facilitate adding and removing flags. 30 # Parse out the flags into a list to facilitate adding and removing flags.
33 self._current_flags = self._TokenizeFlags(self._orig_line) 31 self._current_flags = self._TokenizeFlags(self._orig_line)
34 32
35 def Get(self): 33 def Get(self):
36 """Returns list of current flags.""" 34 """Returns list of current flags."""
37 return self._current_flags 35 return self._current_flags
38 36
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 def Restore(self): 81 def Restore(self):
84 """Restores the flags to their original state.""" 82 """Restores the flags to their original state."""
85 self._current_flags = self._TokenizeFlags(self._orig_line) 83 self._current_flags = self._TokenizeFlags(self._orig_line)
86 self._UpdateCommandLineFile() 84 self._UpdateCommandLineFile()
87 85
88 def _UpdateCommandLineFile(self): 86 def _UpdateCommandLineFile(self):
89 """Writes out the command line to the file, or removes it if empty.""" 87 """Writes out the command line to the file, or removes it if empty."""
90 logging.info('Current flags: %s', self._current_flags) 88 logging.info('Current flags: %s', self._current_flags)
91 89
92 if self._current_flags: 90 if self._current_flags:
93 self._android_cmd.SetProtectedFileContents(CHROME_COMMAND_FILE, 91 # The first command line argument doesn't matter as we are not actually
94 'chrome ' + 92 # launching the chrome executable using this command line.
95 ' '.join(self._current_flags)) 93 self._adb.SetProtectedFileContents(self._cmdline_file,
94 ' '.join(['_'] + self._current_flags))
96 else: 95 else:
97 self._android_cmd.RunShellCommand('su -c rm ' + CHROME_COMMAND_FILE) 96 self._adb.RunShellCommand('su -c rm ' + self._cmdline_file)
98 97
99 def _TokenizeFlags(self, line): 98 def _TokenizeFlags(self, line):
100 """Changes the string containing the command line into a list of flags. 99 """Changes the string containing the command line into a list of flags.
101 100
102 Follows similar logic to CommandLine.java::tokenizeQuotedArguments: 101 Follows similar logic to CommandLine.java::tokenizeQuotedArguments:
103 * Flags are split using whitespace, unless the whitespace is within a 102 * Flags are split using whitespace, unless the whitespace is within a
104 pair of quotation marks. 103 pair of quotation marks.
105 * Unlike the Java version, we keep the quotation marks around switch 104 * 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 105 values since we need them to re-create the file when new flags are
107 appended. 106 appended.
(...skipping 22 matching lines...) Expand all
130 elif not within_quotations and (c is ' ' or c is '\t'): 129 elif not within_quotations and (c is ' ' or c is '\t'):
131 if current_flag is not "": 130 if current_flag is not "":
132 tokenized_flags.append(current_flag) 131 tokenized_flags.append(current_flag)
133 current_flag = "" 132 current_flag = ""
134 else: 133 else:
135 current_flag += c 134 current_flag += c
136 135
137 # Tack on the last flag. 136 # Tack on the last flag.
138 if not current_flag: 137 if not current_flag:
139 if within_quotations: 138 if within_quotations:
140 warnings.warn("Unterminated quoted string: " + current_flag) 139 warnings.warn("Unterminated quoted string: " + current_flag)
frankf 2013/08/27 00:28:09 use logging
craigdh 2013/08/27 17:26:13 Done.
141 else: 140 else:
142 tokenized_flags.append(current_flag) 141 tokenized_flags.append(current_flag)
143 142
144 # Return everything but the program name. 143 # Return everything but the program name.
145 return tokenized_flags[1:] 144 return tokenized_flags[1:]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698