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

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: init 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: assert flags[0] != 'chrome'
Nirnimesh 2011/10/21 08:16:15 move "assert flags[0] != 'chrome'" to next line
michaelbai 2011/10/21 21:08:41 Done.
26
27 if not self.old_flags:
28 self.old_flags = self.android_cmd.GetFileContents(CHROME_COMMAND_FILE)
29 if self.old_flags: self.old_flags = self.old_flags[0].strip()
Nirnimesh 2011/10/21 08:16:15 same here
michaelbai 2011/10/21 21:08:41 Done.
30
31 if append and self.old_flags:
32 # Avoid appending flags that already present.
Nirnimesh 2011/10/21 08:16:15 that -> that are
michaelbai 2011/10/21 21:08:41 Done.
33 new_flags = filter(lambda flag: self.old_flags.find(flag) == -1, flags)
34 self.android_cmd.SetFileContents(CHROME_COMMAND_FILE,
35 self.old_flags + ' ' +
36 ' '.join(new_flags))
37 else:
38 self.android_cmd.SetFileContents(CHROME_COMMAND_FILE,
39 'chrome ' + ' '.join(flags))
40
41 def Restore(self):
Nirnimesh 2011/10/21 08:16:15 I'd recommend calling Restore in the d'tor as well
michaelbai 2011/10/21 21:08:41 I checked all the code using FlagChanger, it seeme
42 """Restores the flags to their original state."""
43 if self.old_flags == None:
44 return # Set() was never called.
45 elif self.old_flags:
46 self.android_cmd.SetFileContents(CHROME_COMMAND_FILE, self.old_flags)
47 else:
48 self.android_cmd.RunShellCommand('rm ' + CHROME_COMMAND_FILE)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698