| OLD | NEW |
| 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 logging | 5 import logging |
| 6 | 6 |
| 7 import pylib.android_commands | |
| 8 import pylib.device.device_utils | 7 import pylib.device.device_utils |
| 9 | 8 |
| 10 from pylib.device import device_errors | 9 from pylib.device import device_errors |
| 11 | 10 |
| 12 | 11 |
| 13 class FlagChanger(object): | 12 class FlagChanger(object): |
| 14 """Changes the flags Chrome runs with. | 13 """Changes the flags Chrome runs with. |
| 15 | 14 |
| 16 There are two different use cases for this file: | 15 There are two different use cases for this file: |
| 17 * Flags are permanently set by calling Set(). | 16 * Flags are permanently set by calling Set(). |
| 18 * Flags can be temporarily set for a particular set of unit tests. These | 17 * Flags can be temporarily set for a particular set of unit tests. These |
| 19 tests should call Restore() to revert the flags to their original state | 18 tests should call Restore() to revert the flags to their original state |
| 20 once the tests have completed. | 19 once the tests have completed. |
| 21 """ | 20 """ |
| 22 | 21 |
| 23 def __init__(self, device, cmdline_file): | 22 def __init__(self, device, cmdline_file): |
| 24 """Initializes the FlagChanger and records the original arguments. | 23 """Initializes the FlagChanger and records the original arguments. |
| 25 | 24 |
| 26 Args: | 25 Args: |
| 27 device: A DeviceUtils instance. | 26 device: A DeviceUtils instance. |
| 28 cmdline_file: Path to the command line file on the device. | 27 cmdline_file: Path to the command line file on the device. |
| 29 """ | 28 """ |
| 30 # TODO(jbudorick) Remove once telemetry switches over. | |
| 31 assert not isinstance(device, pylib.android_commands.AndroidCommands) | |
| 32 self._device = device | 29 self._device = device |
| 33 self._cmdline_file = cmdline_file | 30 self._cmdline_file = cmdline_file |
| 34 | 31 |
| 35 # Save the original flags. | 32 # Save the original flags. |
| 36 try: | 33 try: |
| 37 self._orig_line = self._device.ReadFile(self._cmdline_file).strip() | 34 self._orig_line = self._device.ReadFile(self._cmdline_file).strip() |
| 38 except device_errors.CommandFailedError: | 35 except device_errors.CommandFailedError: |
| 39 self._orig_line = '' | 36 self._orig_line = '' |
| 40 | 37 |
| 41 # Parse out the flags into a list to facilitate adding and removing flags. | 38 # Parse out the flags into a list to facilitate adding and removing flags. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 153 |
| 157 # Tack on the last flag. | 154 # Tack on the last flag. |
| 158 if not current_flag: | 155 if not current_flag: |
| 159 if within_quotations: | 156 if within_quotations: |
| 160 logging.warn('Unterminated quoted argument: ' + line) | 157 logging.warn('Unterminated quoted argument: ' + line) |
| 161 else: | 158 else: |
| 162 tokenized_flags.append(current_flag) | 159 tokenized_flags.append(current_flag) |
| 163 | 160 |
| 164 # Return everything but the program name. | 161 # Return everything but the program name. |
| 165 return tokenized_flags[1:] | 162 return tokenized_flags[1:] |
| OLD | NEW |