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

Unified Diff: components/flags_ui/flags_state.cc

Issue 2298223002: Fix logging of Launch.FlagsAtStartup histogram. (Closed)
Patch Set: Address comments. Created 4 years, 4 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 | « components/flags_ui/flags_state.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/flags_ui/flags_state.cc
diff --git a/components/flags_ui/flags_state.cc b/components/flags_ui/flags_state.cc
index 00c0c2a258483c851e30c0989758d1d9b0b13517..f7d0eb8233b34927472867ef4525f4c9c54412a5 100644
--- a/components/flags_ui/flags_state.cc
+++ b/components/flags_ui/flags_state.cc
@@ -228,9 +228,7 @@ base::FieldTrial* RegisterFeatureVariationParameters(
} // namespace
-// Keeps track of affected switches for each FeatureEntry, based on which
-// choice is selected for it.
-struct SwitchEntry {
+struct FlagsState::SwitchEntry {
// Corresponding base::Feature to toggle.
std::string feature_name;
@@ -261,55 +259,33 @@ void FlagsState::ConvertFlagsToSwitches(
const char* enable_features_flag_name,
const char* disable_features_flag_name) {
std::set<std::string> enabled_entries;
-
- GetSanitizedEnabledFlagsForCurrentPlatform(flags_storage, &enabled_entries);
-
std::map<std::string, SwitchEntry> name_to_switch_map;
- for (size_t i = 0; i < num_feature_entries_; ++i) {
- const FeatureEntry& e = feature_entries_[i];
- switch (e.type) {
- case FeatureEntry::SINGLE_VALUE:
- case FeatureEntry::SINGLE_DISABLE_VALUE:
- AddSwitchMapping(e.internal_name, e.command_line_switch,
- e.command_line_value, &name_to_switch_map);
- break;
- case FeatureEntry::MULTI_VALUE:
- for (int j = 0; j < e.num_options; ++j) {
- AddSwitchMapping(
- e.NameForOption(j), e.ChoiceForOption(j).command_line_switch,
- e.ChoiceForOption(j).command_line_value, &name_to_switch_map);
- }
- break;
- case FeatureEntry::ENABLE_DISABLE_VALUE:
- AddSwitchMapping(e.NameForOption(0), std::string(), std::string(),
- &name_to_switch_map);
- AddSwitchMapping(e.NameForOption(1), e.command_line_switch,
- e.command_line_value, &name_to_switch_map);
- AddSwitchMapping(e.NameForOption(2), e.disable_command_line_switch,
- e.disable_command_line_value, &name_to_switch_map);
- break;
- case FeatureEntry::FEATURE_VALUE:
- case FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE:
- for (int j = 0; j < e.num_options; ++j) {
- FeatureEntry::FeatureState state = e.StateForOption(j);
- if (state == FeatureEntry::FeatureState::DEFAULT) {
- AddFeatureMapping(e.NameForOption(j), std::string(), false,
- &name_to_switch_map);
- } else {
- AddFeatureMapping(e.NameForOption(j), e.feature->name,
- state == FeatureEntry::FeatureState::ENABLED,
- &name_to_switch_map);
- }
- }
- break;
- }
- }
-
+ GenerateFlagsToSwitchesMapping(flags_storage, &enabled_entries,
+ &name_to_switch_map);
AddSwitchesToCommandLine(enabled_entries, name_to_switch_map, sentinels,
command_line, enable_features_flag_name,
disable_features_flag_name);
}
+std::set<std::string> FlagsState::GetSwitchesFromFlags(
+ FlagsStorage* flags_storage) {
+ std::set<std::string> enabled_entries;
+ std::map<std::string, SwitchEntry> name_to_switch_map;
+ GenerateFlagsToSwitchesMapping(flags_storage, &enabled_entries,
+ &name_to_switch_map);
+
+ std::set<std::string> switches;
+ for (const std::string& entry_name : enabled_entries) {
+ const auto& entry_it = name_to_switch_map.find(entry_name);
+ DCHECK(entry_it != name_to_switch_map.end());
+
+ const SwitchEntry& entry = entry_it->second;
+ if (!entry.switch_name.empty())
+ switches.insert("--" + entry.switch_name);
+ }
+ return switches;
+}
+
bool FlagsState::IsRestartNeededToCommitChanges() {
return needs_restart_;
}
@@ -732,4 +708,51 @@ void FlagsState::GetSanitizedEnabledFlagsForCurrentPlatform(
result->swap(new_enabled_entries);
}
+void FlagsState::GenerateFlagsToSwitchesMapping(
+ FlagsStorage* flags_storage,
+ std::set<std::string>* enabled_entries,
+ std::map<std::string, SwitchEntry>* name_to_switch_map) {
+ GetSanitizedEnabledFlagsForCurrentPlatform(flags_storage, enabled_entries);
+
+ for (size_t i = 0; i < num_feature_entries_; ++i) {
+ const FeatureEntry& e = feature_entries_[i];
+ switch (e.type) {
+ case FeatureEntry::SINGLE_VALUE:
+ case FeatureEntry::SINGLE_DISABLE_VALUE:
+ AddSwitchMapping(e.internal_name, e.command_line_switch,
+ e.command_line_value, name_to_switch_map);
+ break;
+ case FeatureEntry::MULTI_VALUE:
+ for (int j = 0; j < e.num_options; ++j) {
+ AddSwitchMapping(
+ e.NameForOption(j), e.ChoiceForOption(j).command_line_switch,
+ e.ChoiceForOption(j).command_line_value, name_to_switch_map);
+ }
+ break;
+ case FeatureEntry::ENABLE_DISABLE_VALUE:
+ AddSwitchMapping(e.NameForOption(0), std::string(), std::string(),
+ name_to_switch_map);
+ AddSwitchMapping(e.NameForOption(1), e.command_line_switch,
+ e.command_line_value, name_to_switch_map);
+ AddSwitchMapping(e.NameForOption(2), e.disable_command_line_switch,
+ e.disable_command_line_value, name_to_switch_map);
+ break;
+ case FeatureEntry::FEATURE_VALUE:
+ case FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE:
+ for (int j = 0; j < e.num_options; ++j) {
+ FeatureEntry::FeatureState state = e.StateForOption(j);
+ if (state == FeatureEntry::FeatureState::DEFAULT) {
+ AddFeatureMapping(e.NameForOption(j), std::string(), false,
+ name_to_switch_map);
+ } else {
+ AddFeatureMapping(e.NameForOption(j), e.feature->name,
+ state == FeatureEntry::FeatureState::ENABLED,
+ name_to_switch_map);
+ }
+ }
+ break;
+ }
+ }
+}
+
} // namespace flags_ui
« no previous file with comments | « components/flags_ui/flags_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698