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

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

Issue 8364020: Upstream: Test scripts for Android (phase 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync again Created 9 years, 2 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
(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 + ' ' +
38 ' '.join(new_flags))
39 else:
40 self._android_cmd.SetFileContents(CHROME_COMMAND_FILE,
41 'chrome ' + ' '.join(flags))
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)
OLDNEW
« no previous file with comments | « build/android/chrome_test_server_spawner.py ('k') | build/android/gtest_filter/base_unittests_disabled » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698