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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: build/android/flag_changer.py
diff --git a/build/android/flag_changer.py b/build/android/flag_changer.py
new file mode 100644
index 0000000000000000000000000000000000000000..45eb124e9fb0fd64710efbf38a42b9aa6f784ecc
--- /dev/null
+++ b/build/android/flag_changer.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+# Location where chrome reads command line flags from
+CHROME_COMMAND_FILE = '/data/local/chrome-command-line'
+
+
+class FlagChanger(object):
+ """Temporarily changes the flags Chrome runs with."""
+
+ def __init__(self, android_cmd):
+ self.android_cmd = android_cmd
+ self.old_flags = None
+
+ def Set(self, flags, append=False):
+ """Sets the command line flags used when chrome is started.
+
+ Args:
+ flags: A list of flags to set, eg. ['--single-process'].
+ append: Whether to append to existing flags or overwrite them.
+ """
+ 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.
+
+ if not self.old_flags:
+ self.old_flags = self.android_cmd.GetFileContents(CHROME_COMMAND_FILE)
+ 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.
+
+ if append and self.old_flags:
+ # Avoid appending flags that already present.
Nirnimesh 2011/10/21 08:16:15 that -> that are
michaelbai 2011/10/21 21:08:41 Done.
+ new_flags = filter(lambda flag: self.old_flags.find(flag) == -1, flags)
+ self.android_cmd.SetFileContents(CHROME_COMMAND_FILE,
+ self.old_flags + ' ' +
+ ' '.join(new_flags))
+ else:
+ self.android_cmd.SetFileContents(CHROME_COMMAND_FILE,
+ 'chrome ' + ' '.join(flags))
+
+ 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
+ """Restores the flags to their original state."""
+ if self.old_flags == None:
+ return # Set() was never called.
+ elif self.old_flags:
+ self.android_cmd.SetFileContents(CHROME_COMMAND_FILE, self.old_flags)
+ else:
+ self.android_cmd.RunShellCommand('rm ' + CHROME_COMMAND_FILE)

Powered by Google App Engine
This is Rietveld 408576698