blob: 3834d1c1c1805d7adb45a06b2f5c83eec4ba793a [file] [log] [blame]
[email protected]9c7453d2012-01-21 00:45:401// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]1a47d7e2010-10-15 00:37:242// 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_
[email protected]1a47d7e2010-10-15 00:37:247
[email protected]e2ddbc92010-10-15 20:02:078#include <map>
[email protected]1a47d7e2010-10-15 00:37:249#include <string>
10
[email protected]e2ddbc92010-10-15 20:02:0711#include "base/command_line.h"
[email protected]83e9fa702013-02-25 19:30:4412#include "base/string16.h"
[email protected]e2ddbc92010-10-15 20:02:0713
[email protected]1a47d7e2010-10-15 00:37:2414class PrefService;
15
[email protected]f3a1c642011-07-12 19:15:0316namespace base {
17class ListValue;
18}
19
[email protected]1a47d7e2010-10-15 00:37:2420namespace about_flags {
21
[email protected]a314ee5a2010-10-26 21:23:2822// Enumeration of OSs.
23// This is exposed only for testing.
[email protected]9c7453d2012-01-21 00:45:4024enum { kOsMac = 1 << 0, kOsWin = 1 << 1, kOsLinux = 1 << 2 , kOsCrOS = 1 << 3,
[email protected]37736bd2013-04-18 11:53:5825 kOsAndroid = 1 << 4, kOsCrOSOwnerOnly = 1 << 5 };
[email protected]a314ee5a2010-10-26 21:23:2826
27// Experiment is used internally by about_flags to describe an experiment (and
28// for testing).
29// This is exposed only for testing.
30struct Experiment {
[email protected]8a6ff28d2010-12-02 16:35:1931 enum Type {
32 // An experiment with a single value. This is typically what you want.
33 SINGLE_VALUE,
34
35 // The experiment has multiple values only one of which is ever enabled.
[email protected]28e35af2011-02-09 12:56:2236 // The first of the values should correspond to a deactivated state for this
37 // lab (i.e. no command line option). For MULTI_VALUE experiments the
38 // command_line of the Experiment is not used. If the experiment is enabled
39 // the command line of the selected Choice is enabled.
[email protected]8a6ff28d2010-12-02 16:35:1940 MULTI_VALUE,
[email protected]83e9fa702013-02-25 19:30:4441
42 // The experiment has three possible values: Default, Enabled and Disabled.
43 // This should be used for experiments that may have their own logic to
44 // decide if the feature should be on when not explicitly specified via
45 // about flags - for example via FieldTrials.
46 ENABLE_DISABLE_VALUE,
[email protected]8a6ff28d2010-12-02 16:35:1947 };
48
49 // Used for MULTI_VALUE types to describe one of the possible values the user
50 // can select.
51 struct Choice {
52 // ID of the message containing the choice name.
53 int description_id;
54
[email protected]a82744532011-02-11 16:15:5355 // Command line switch and value to enabled for this choice.
56 const char* command_line_switch;
57 // Simple switches that have no value should use "" for command_line_value.
58 const char* command_line_value;
[email protected]8a6ff28d2010-12-02 16:35:1959 };
60
[email protected]a314ee5a2010-10-26 21:23:2861 // The internal name of the experiment. This is never shown to the user.
62 // It _is_ however stored in the prefs file, so you shouldn't change the
63 // name of existing flags.
64 const char* internal_name;
65
66 // String id of the message containing the experiment's name.
67 int visible_name_id;
68
69 // String id of the message containing the experiment's description.
70 int visible_description_id;
71
72 // The platforms the experiment is available on
73 // Needs to be more than a compile-time #ifdef because of profile sync.
74 unsigned supported_platforms; // bitmask
75
[email protected]8a6ff28d2010-12-02 16:35:1976 // Type of experiment.
77 Type type;
78
[email protected]83e9fa702013-02-25 19:30:4479 // The commandline switch and value that are added when this flag is active.
[email protected]a82744532011-02-11 16:15:5380 // This is different from |internal_name| so that the commandline flag can be
[email protected]a314ee5a2010-10-26 21:23:2881 // renamed without breaking the prefs file.
[email protected]83e9fa702013-02-25 19:30:4482 // This is used if type is SINGLE_VALUE or ENABLE_DISABLE_VALUE.
[email protected]a82744532011-02-11 16:15:5383 const char* command_line_switch;
84 // Simple switches that have no value should use "" for command_line_value.
85 const char* command_line_value;
[email protected]8a6ff28d2010-12-02 16:35:1986
[email protected]83e9fa702013-02-25 19:30:4487 // For ENABLE_DISABLE_VALUE, the command line switch and value to explictly
88 // disable the feature.
89 const char* disable_command_line_switch;
90 const char* disable_command_line_value;
91
[email protected]8a6ff28d2010-12-02 16:35:1992 // This is used if type is MULTI_VALUE.
93 const Choice* choices;
94
95 // Number of |choices|.
96 // This is used if type is MULTI_VALUE.
97 int num_choices;
[email protected]83e9fa702013-02-25 19:30:4498
99 // Returns the name used in prefs for the choice at the specified |index|.
100 std::string NameForChoice(int index) const;
101
102 // Returns the human readable description for the choice at |index|.
103 string16 DescriptionForChoice(int index) const;
[email protected]a314ee5a2010-10-26 21:23:28104};
105
[email protected]1a47d7e2010-10-15 00:37:24106// Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the
107// commandline flags belonging to the active experiments to |command_line|.
108void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line);
109
[email protected]37736bd2013-04-18 11:53:58110// Differentiate between generic flags available on a per session base and flags
111// that influence the whole machine and can be said by the admin only. This flag
112// is relevant for ChromeOS for now only and dictates whether entries marked
113// with the |kOsCrOSOwnerOnly| label should be enabled in the UI or not.
114enum FlagAccess { kGeneralAccessFlagsOnly, kOwnerAccessToFlags };
115
[email protected]1a47d7e2010-10-15 00:37:24116// Get a list of all available experiments. The caller owns the result.
[email protected]37736bd2013-04-18 11:53:58117base::ListValue* GetFlagsExperimentsData(PrefService* prefs, FlagAccess access);
[email protected]1a47d7e2010-10-15 00:37:24118
119// Returns true if one of the experiment flags has been flipped since startup.
120bool IsRestartNeededToCommitChanges();
121
122// Enables or disables the experiment with id |internal_name|.
123void SetExperimentEnabled(
124 PrefService* prefs, const std::string& internal_name, bool enable);
125
[email protected]e2ddbc92010-10-15 20:02:07126// Removes all switches that were added to a command line by a previous call to
127// |ConvertFlagsToSwitches()|.
128void RemoveFlagsSwitches(
129 std::map<std::string, CommandLine::StringType>* switch_list);
130
[email protected]cb93bf52013-02-20 01:20:00131// Reset all flags to the default state by clearing all flags.
132void ResetAllFlags(PrefService* prefs);
133
[email protected]a314ee5a2010-10-26 21:23:28134// Returns the value for the current platform. This is one of the values defined
135// by the OS enum above.
136// This is exposed only for testing.
137int GetCurrentPlatform();
138
[email protected]4bc5050c2010-11-18 17:55:54139// Sends UMA stats about experimental flag usage. This should be called once per
140// startup.
141void RecordUMAStatistics(const PrefService* prefs);
142
[email protected]e2ddbc92010-10-15 20:02:07143namespace testing {
[email protected]83e9fa702013-02-25 19:30:44144
[email protected]e2ddbc92010-10-15 20:02:07145// Clears internal global state, for unit tests.
146void ClearState();
[email protected]a314ee5a2010-10-26 21:23:28147
148// Sets the list of experiments. Pass in NULL to use the default set. This does
149// NOT take ownership of the supplied Experiments.
150void SetExperiments(const Experiment* e, size_t count);
[email protected]8a6ff28d2010-12-02 16:35:19151
152// Returns the current set of experiments.
153const Experiment* GetExperiments(size_t* count);
154
155// Separator used for multi values. Multi values are represented in prefs as
156// name-of-experiment + kMultiSeparator + selected_index.
157extern const char kMultiSeparator[];
158
[email protected]e2ddbc92010-10-15 20:02:07159} // namespace testing
160
[email protected]1a47d7e2010-10-15 00:37:24161} // namespace about_flags
162
163#endif // CHROME_BROWSER_ABOUT_FLAGS_H_