Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 | |
| 7 # Location where chrome reads command line flags from | |
| 8 CHROME_COMMAND_FILE = '/data/local/chrome-command-line' | |
| 9 | |
| 10 | |
| 11 class FlagChanger(object): | |
| 12 """Temporarily changes the flags Chrome runs with.""" | |
| 13 | |
| 14 def __init__(self, android_cmd): | |
| 15 self._android_cmd = android_cmd | |
| 16 self._old_flags = None | |
| 17 | |
| 18 def Set(self, flags, append=False): | |
| 19 """Sets the command line flags used when chrome is started. | |
| 20 | |
| 21 Args: | |
| 22 flags: A list of flags to set, eg. ['--single-process']. | |
| 23 append: Whether to append to existing flags or overwrite them. | |
| 24 """ | |
| 25 if flags: | |
| 26 assert flags[0] != 'chrome' | |
| 27 | |
| 28 if not self._old_flags: | |
| 29 self._old_flags = self._android_cmd.GetFileContents(CHROME_COMMAND_FILE) | |
| 30 if self._old_flags: | |
| 31 self._old_flags = self._old_flags[0].strip() | |
| 32 | |
| 33 if append and self._old_flags: | |
| 34 # Avoid appending flags that are already present. | |
| 35 new_flags = filter(lambda flag: self._old_flags.find(flag) == -1, flags) | |
| 36 self._android_cmd.SetFileContents(CHROME_COMMAND_FILE, | |
| 37 self._old_flags + ' ' + | |
|
Nirnimesh
2011/10/24 18:02:34
indent by 1 more space to the right
michaelbai
2011/10/24 18:33:51
Done.
| |
| 38 ' '.join(new_flags)) | |
|
Nirnimesh
2011/10/24 18:02:34
same here
michaelbai
2011/10/24 18:33:51
Done.
| |
| 39 else: | |
| 40 self._android_cmd.SetFileContents(CHROME_COMMAND_FILE, | |
| 41 'chrome ' + ' '.join(flags)) | |
|
Nirnimesh
2011/10/24 18:02:34
and here
michaelbai
2011/10/24 18:33:51
Done.
| |
| 42 | |
| 43 def Restore(self): | |
| 44 """Restores the flags to their original state.""" | |
| 45 if self._old_flags == None: | |
| 46 return # Set() was never called. | |
| 47 elif self._old_flags: | |
| 48 self._android_cmd.SetFileContents(CHROME_COMMAND_FILE, self._old_flags) | |
| 49 else: | |
| 50 self._android_cmd.RunShellCommand('rm ' + CHROME_COMMAND_FILE) | |
| OLD | NEW |