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

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: Addressed comments 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..e740173e081f6e668879e80579ee3a9ed9e3bb6f
--- /dev/null
+++ b/build/android/flag_changer.py
@@ -0,0 +1,50 @@
+#!/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'
+
+ 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()
+
+ if append and self._old_flags:
+ # Avoid appending flags that are already present.
+ new_flags = filter(lambda flag: self._old_flags.find(flag) == -1, flags)
+ self._android_cmd.SetFileContents(CHROME_COMMAND_FILE,
+ 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.
+ ' '.join(new_flags))
Nirnimesh 2011/10/24 18:02:34 same here
michaelbai 2011/10/24 18:33:51 Done.
+ else:
+ self._android_cmd.SetFileContents(CHROME_COMMAND_FILE,
+ 'chrome ' + ' '.join(flags))
Nirnimesh 2011/10/24 18:02:34 and here
michaelbai 2011/10/24 18:33:51 Done.
+
+ def Restore(self):
+ """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