[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_ABOUT_FLAGS_H_ |
| 6 | #define CHROME_BROWSER_ABOUT_FLAGS_H_ |
| 7 | #pragma once |
| 8 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 9 | #include <map> |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 10 | #include <string> |
| 11 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 12 | #include "base/command_line.h" |
| 13 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 14 | class ListValue; |
| 15 | class PrefService; |
| 16 | |
| 17 | namespace about_flags { |
| 18 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 19 | // Enumeration of OSs. |
| 20 | // This is exposed only for testing. |
| 21 | enum { kOsMac = 1 << 0, kOsWin = 1 << 1, kOsLinux = 1 << 2 , kOsCrOS = 1 << 3 }; |
| 22 | |
| 23 | // Experiment is used internally by about_flags to describe an experiment (and |
| 24 | // for testing). |
| 25 | // This is exposed only for testing. |
| 26 | struct Experiment { |
| 27 | // The internal name of the experiment. This is never shown to the user. |
| 28 | // It _is_ however stored in the prefs file, so you shouldn't change the |
| 29 | // name of existing flags. |
| 30 | const char* internal_name; |
| 31 | |
| 32 | // String id of the message containing the experiment's name. |
| 33 | int visible_name_id; |
| 34 | |
| 35 | // String id of the message containing the experiment's description. |
| 36 | int visible_description_id; |
| 37 | |
| 38 | // The platforms the experiment is available on |
| 39 | // Needs to be more than a compile-time #ifdef because of profile sync. |
| 40 | unsigned supported_platforms; // bitmask |
| 41 | |
| 42 | // The commandline parameter that's added when this lab is active. This is |
| 43 | // different from |internal_name| so that the commandline flag can be |
| 44 | // renamed without breaking the prefs file. |
| 45 | const char* command_line; |
| 46 | }; |
| 47 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 48 | // Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the |
| 49 | // commandline flags belonging to the active experiments to |command_line|. |
| 50 | void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line); |
| 51 | |
| 52 | // Get a list of all available experiments. The caller owns the result. |
| 53 | ListValue* GetFlagsExperimentsData(PrefService* prefs); |
| 54 | |
| 55 | // Returns true if one of the experiment flags has been flipped since startup. |
| 56 | bool IsRestartNeededToCommitChanges(); |
| 57 | |
| 58 | // Enables or disables the experiment with id |internal_name|. |
| 59 | void SetExperimentEnabled( |
| 60 | PrefService* prefs, const std::string& internal_name, bool enable); |
| 61 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 62 | // Removes all switches that were added to a command line by a previous call to |
| 63 | // |ConvertFlagsToSwitches()|. |
| 64 | void RemoveFlagsSwitches( |
| 65 | std::map<std::string, CommandLine::StringType>* switch_list); |
| 66 | |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 67 | // Returns the value for the current platform. This is one of the values defined |
| 68 | // by the OS enum above. |
| 69 | // This is exposed only for testing. |
| 70 | int GetCurrentPlatform(); |
| 71 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame^] | 72 | // Sends UMA stats about experimental flag usage. This should be called once per |
| 73 | // startup. |
| 74 | void RecordUMAStatistics(const PrefService* prefs); |
| 75 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 76 | namespace testing { |
| 77 | // Clears internal global state, for unit tests. |
| 78 | void ClearState(); |
[email protected] | a314ee5a | 2010-10-26 21:23:28 | [diff] [blame] | 79 | |
| 80 | // Sets the list of experiments. Pass in NULL to use the default set. This does |
| 81 | // NOT take ownership of the supplied Experiments. |
| 82 | void SetExperiments(const Experiment* e, size_t count); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 83 | } // namespace testing |
| 84 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 85 | } // namespace about_flags |
| 86 | |
| 87 | #endif // CHROME_BROWSER_ABOUT_FLAGS_H_ |