[email protected] | 9c7453d | 2012-01-21 00:45:40 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 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_ |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 7 | |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 8 | #include <stddef.h> |
[email protected] | 4b66a7d | 2014-08-15 17:13:31 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 11 | #include <map> |
[email protected] | 4b66a7d | 2014-08-15 17:13:31 | [diff] [blame] | 12 | #include <set> |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 13 | #include <string> |
jkrcal | bf07337 | 2016-07-29 07:21:31 | [diff] [blame] | 14 | #include <vector> |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 15 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 16 | #include "base/command_line.h" |
alemate | 0107c327 | 2014-09-03 04:30:04 | [diff] [blame] | 17 | #include "base/metrics/histogram_base.h" |
[email protected] | e746341 | 2013-06-10 22:53:46 | [diff] [blame] | 18 | #include "base/strings/string16.h" |
sdefresne | 246c564 | 2015-11-16 21:47:29 | [diff] [blame] | 19 | #include "components/flags_ui/feature_entry.h" |
sdefresne | 0e56634 | 2015-11-24 08:55:46 | [diff] [blame] | 20 | #include "components/flags_ui/flags_state.h" |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 21 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 22 | namespace base { |
jkrcal | d1d2008 | 2016-07-14 15:04:24 | [diff] [blame] | 23 | class FeatureList; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 24 | class ListValue; |
| 25 | } |
| 26 | |
droger | 888be0b | 2015-10-01 14:28:52 | [diff] [blame] | 27 | namespace flags_ui { |
[email protected] | e6d1c4f | 2013-06-12 17:37:40 | [diff] [blame] | 28 | class FlagsStorage; |
droger | 888be0b | 2015-10-01 14:28:52 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | namespace about_flags { |
[email protected] | e6d1c4f | 2013-06-12 17:37:40 | [diff] [blame] | 32 | |
asvitkine | e9ed35e | 2015-10-14 22:33:59 | [diff] [blame] | 33 | // Reads the state from |flags_storage| and adds the command line flags |
| 34 | // belonging to the active feature entries to |command_line|. |
droger | 888be0b | 2015-10-01 14:28:52 | [diff] [blame] | 35 | void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 36 | base::CommandLine* command_line, |
sdefresne | 0e56634 | 2015-11-24 08:55:46 | [diff] [blame] | 37 | flags_ui::SentinelsMode sentinels); |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 38 | |
jkrcal | d1d2008 | 2016-07-14 15:04:24 | [diff] [blame] | 39 | // Registers variations parameter values selected for features in about:flags. |
| 40 | // The selected flags are retrieved from |flags_storage|, the registered |
| 41 | // variation parameters are connected to their corresponding features in |
jkrcal | bf07337 | 2016-07-29 07:21:31 | [diff] [blame] | 42 | // |feature_list|. Returns the (possibly empty) list of additional variation ids |
| 43 | // to register in the MetricsService that come from variations selected using |
| 44 | // chrome://flags. |
| 45 | std::vector<std::string> RegisterAllFeatureVariationParameters( |
jkrcal | d1d2008 | 2016-07-14 15:04:24 | [diff] [blame] | 46 | flags_ui::FlagsStorage* flags_storage, |
| 47 | base::FeatureList* feature_list); |
jkrcal | 1383d1d | 2016-06-17 12:40:56 | [diff] [blame] | 48 | |
[email protected] | 6d98abf | 2013-06-17 23:35:51 | [diff] [blame] | 49 | // Compares a set of switches of the two provided command line objects and |
| 50 | // returns true if they are the same and false otherwise. |
[email protected] | 4b66a7d | 2014-08-15 17:13:31 | [diff] [blame] | 51 | // If |out_difference| is not NULL, it's filled with set_symmetric_difference |
| 52 | // between sets. |
[email protected] | 6d98abf | 2013-06-17 23:35:51 | [diff] [blame] | 53 | bool AreSwitchesIdenticalToCurrentCommandLine( |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 54 | const base::CommandLine& new_cmdline, |
[email protected] | 4b66a7d | 2014-08-15 17:13:31 | [diff] [blame] | 55 | const base::CommandLine& active_cmdline, |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 56 | std::set<base::CommandLine::StringType>* out_difference); |
[email protected] | 6d98abf | 2013-06-17 23:35:51 | [diff] [blame] | 57 | |
asvitkine | e9ed35e | 2015-10-14 22:33:59 | [diff] [blame] | 58 | // Gets the list of feature entries. Entries that are available for the current |
| 59 | // platform are appended to |supported_entries|; all other entries are appended |
| 60 | // to |unsupported_entries|. |
| 61 | void GetFlagFeatureEntries(flags_ui::FlagsStorage* flags_storage, |
sdefresne | 0e56634 | 2015-11-24 08:55:46 | [diff] [blame] | 62 | flags_ui::FlagAccess access, |
asvitkine | e9ed35e | 2015-10-14 22:33:59 | [diff] [blame] | 63 | base::ListValue* supported_entries, |
| 64 | base::ListValue* unsupported_entries); |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 65 | |
Yann Dago | baa08aa | 2019-07-29 20:52:37 | [diff] [blame] | 66 | // Gets the list of feature entries for enterprises. Entries that are available |
| 67 | // for the current platform are appended to |supported_entries|; all other |
| 68 | // entries are appended to |unsupported_entries|. |
| 69 | void GetFlagFeatureEntriesForEnterprises(flags_ui::FlagsStorage* flags_storage, |
| 70 | flags_ui::FlagAccess access, |
| 71 | base::ListValue* supported_entries, |
| 72 | base::ListValue* unsupported_entries); |
| 73 | |
asvitkine | e9ed35e | 2015-10-14 22:33:59 | [diff] [blame] | 74 | // Returns true if one of the feature entry flags has been flipped since |
| 75 | // startup. |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 76 | bool IsRestartNeededToCommitChanges(); |
| 77 | |
asvitkine | e9ed35e | 2015-10-14 22:33:59 | [diff] [blame] | 78 | // Enables or disables the current with id |internal_name|. |
| 79 | void SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage, |
| 80 | const std::string& internal_name, |
| 81 | bool enable); |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 82 | |
Mustafa Emre Acer | b3aa36a8 | 2018-05-22 21:44:05 | [diff] [blame] | 83 | // Sets a flag value with a list of origins given by |value|. Origins in |value| |
| 84 | // can be separated by a comma or whitespace. Invalid URLs will be dropped when |
| 85 | // setting the command line flag. |
| 86 | // E.g. SetOriginListFlag("test-flag", |
| 87 | // "http://example.test1 http://example.test2", |
| 88 | // flags_storage); |
| 89 | // will add --test-flag=http://example.test to the command line. |
| 90 | void SetOriginListFlag(const std::string& internal_name, |
| 91 | const std::string& value, |
| 92 | flags_ui::FlagsStorage* flags_storage); |
| 93 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 94 | // Removes all switches that were added to a command line by a previous call to |
| 95 | // |ConvertFlagsToSwitches()|. |
Jeremy Roman | 863386d | 2017-10-31 19:25:38 | [diff] [blame] | 96 | void RemoveFlagsSwitches(base::CommandLine::SwitchMap* switch_list); |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 97 | |
[email protected] | cb93bf5 | 2013-02-20 01:20:00 | [diff] [blame] | 98 | // Reset all flags to the default state by clearing all flags. |
droger | 888be0b | 2015-10-01 14:28:52 | [diff] [blame] | 99 | void ResetAllFlags(flags_ui::FlagsStorage* flags_storage); |
[email protected] | cb93bf5 | 2013-02-20 01:20:00 | [diff] [blame] | 100 | |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 101 | // Sends UMA stats about experimental flag usage. This should be called once per |
| 102 | // startup. |
droger | 888be0b | 2015-10-01 14:28:52 | [diff] [blame] | 103 | void RecordUMAStatistics(flags_ui::FlagsStorage* flags_storage); |
[email protected] | 4bc5050c | 2010-11-18 17:55:54 | [diff] [blame] | 104 | |
[email protected] | 4b66a7d | 2014-08-15 17:13:31 | [diff] [blame] | 105 | // Returns the UMA id for the specified switch name. |
alemate | 0107c327 | 2014-09-03 04:30:04 | [diff] [blame] | 106 | base::HistogramBase::Sample GetSwitchUMAId(const std::string& switch_name); |
[email protected] | 4b66a7d | 2014-08-15 17:13:31 | [diff] [blame] | 107 | |
asvitkine | ab33c92 | 2016-08-30 20:34:19 | [diff] [blame] | 108 | // Sends stats (as UMA histogram) about a set of command line |flags| in |
lawrencewu | 95059d1e | 2016-09-19 18:07:02 | [diff] [blame] | 109 | // a histogram, with an enum value for each flag in |switches| and |features|, |
| 110 | // based on the hash of the flag name. |
asvitkine | ab33c92 | 2016-08-30 20:34:19 | [diff] [blame] | 111 | void ReportAboutFlagsHistogram(const std::string& uma_histogram_name, |
lawrencewu | 95059d1e | 2016-09-19 18:07:02 | [diff] [blame] | 112 | const std::set<std::string>& switches, |
| 113 | const std::set<std::string>& features); |
[email protected] | 4b66a7d | 2014-08-15 17:13:31 | [diff] [blame] | 114 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 115 | namespace testing { |
[email protected] | 83e9fa70 | 2013-02-25 19:30:44 | [diff] [blame] | 116 | |
sdefresne | 0e56634 | 2015-11-24 08:55:46 | [diff] [blame] | 117 | // Returns the global set of feature entries. |
sdefresne | 246c564 | 2015-11-16 21:47:29 | [diff] [blame] | 118 | const flags_ui::FeatureEntry* GetFeatureEntries(size_t* count); |
[email protected] | 8a6ff28d | 2010-12-02 16:35:19 | [diff] [blame] | 119 | |
asvitkine | bff63b2 | 2014-11-25 01:03:52 | [diff] [blame] | 120 | // This value is reported as switch histogram ID if switch name has unknown |
| 121 | // format. |
| 122 | extern const base::HistogramBase::Sample kBadSwitchFormatHistogramId; |
| 123 | |
[email protected] | e2ddbc9 | 2010-10-15 20:02:07 | [diff] [blame] | 124 | } // namespace testing |
| 125 | |
[email protected] | 1a47d7e | 2010-10-15 00:37:24 | [diff] [blame] | 126 | } // namespace about_flags |
| 127 | |
| 128 | #endif // CHROME_BROWSER_ABOUT_FLAGS_H_ |