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

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: 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..636022b9abd80b6a21b2d702b1a53fea956cb5c6
--- /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 + ' ' +
+ ' '.join(new_flags))
+ else:
+ self._android_cmd.SetFileContents(CHROME_COMMAND_FILE,
+ 'chrome ' + ' '.join(flags))
+
+ 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)
« 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