| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/flags_ui/flags_state.h" | 5 #include "components/flags_ui/flags_state.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 16 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 21 #include "components/flags_ui/feature_entry.h" | 22 #include "components/flags_ui/feature_entry.h" |
| 22 #include "components/flags_ui/flags_storage.h" | 23 #include "components/flags_ui/flags_storage.h" |
| 23 #include "components/flags_ui/flags_ui_switches.h" | 24 #include "components/flags_ui/flags_ui_switches.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 if (enabled_entries.count(entry.NameForOption(i)) > 0) | 169 if (enabled_entries.count(entry.NameForOption(i)) > 0) |
| 169 return false; | 170 return false; |
| 170 } | 171 } |
| 171 return true; | 172 return true; |
| 172 } | 173 } |
| 173 NOTREACHED(); | 174 NOTREACHED(); |
| 174 return true; | 175 return true; |
| 175 } | 176 } |
| 176 | 177 |
| 177 // Returns the Value representing the choice data in the specified entry. | 178 // Returns the Value representing the choice data in the specified entry. |
| 178 base::Value* CreateOptionsData(const FeatureEntry& entry, | 179 std::unique_ptr<base::Value> CreateOptionsData( |
| 179 const std::set<std::string>& enabled_entries) { | 180 const FeatureEntry& entry, |
| 181 const std::set<std::string>& enabled_entries) { |
| 180 DCHECK(entry.type == FeatureEntry::MULTI_VALUE || | 182 DCHECK(entry.type == FeatureEntry::MULTI_VALUE || |
| 181 entry.type == FeatureEntry::ENABLE_DISABLE_VALUE || | 183 entry.type == FeatureEntry::ENABLE_DISABLE_VALUE || |
| 182 entry.type == FeatureEntry::FEATURE_VALUE || | 184 entry.type == FeatureEntry::FEATURE_VALUE || |
| 183 entry.type == FeatureEntry::FEATURE_WITH_PARAMS_VALUE); | 185 entry.type == FeatureEntry::FEATURE_WITH_PARAMS_VALUE); |
| 184 base::ListValue* result = new base::ListValue; | 186 auto result = base::MakeUnique<base::ListValue>(); |
| 185 for (int i = 0; i < entry.num_options; ++i) { | 187 for (int i = 0; i < entry.num_options; ++i) { |
| 186 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); | 188 auto value = base::MakeUnique<base::DictionaryValue>(); |
| 187 const std::string name = entry.NameForOption(i); | 189 const std::string name = entry.NameForOption(i); |
| 188 value->SetString("internal_name", name); | 190 value->SetString("internal_name", name); |
| 189 value->SetString("description", entry.DescriptionForOption(i)); | 191 value->SetString("description", entry.DescriptionForOption(i)); |
| 190 value->SetBoolean("selected", enabled_entries.count(name) > 0); | 192 value->SetBoolean("selected", enabled_entries.count(name) > 0); |
| 191 result->Append(std::move(value)); | 193 result->Append(std::move(value)); |
| 192 } | 194 } |
| 193 return result; | 195 return std::move(result); |
| 194 } | 196 } |
| 195 | 197 |
| 196 // Registers variation parameters specified by |feature_variation_params| for | 198 // Registers variation parameters specified by |feature_variation_params| for |
| 197 // the field trial named |feature_trial_name|, unless a group for this trial has | 199 // the field trial named |feature_trial_name|, unless a group for this trial has |
| 198 // already been created (e.g. via command-line switches that take precedence | 200 // already been created (e.g. via command-line switches that take precedence |
| 199 // over about:flags). In the trial, the function creates a new constant group | 201 // over about:flags). In the trial, the function creates a new constant group |
| 200 // called |kTrialGroupAboutFlags|. | 202 // called |kTrialGroupAboutFlags|. |
| 201 base::FieldTrial* RegisterFeatureVariationParameters( | 203 base::FieldTrial* RegisterFeatureVariationParameters( |
| 202 const std::string& feature_trial_name, | 204 const std::string& feature_trial_name, |
| 203 const std::map<std::string, std::string>& feature_variation_params) { | 205 const std::map<std::string, std::string>& feature_variation_params) { |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 const FeatureEntry& entry = feature_entries_[i]; | 510 const FeatureEntry& entry = feature_entries_[i]; |
| 509 if (skip_feature_entry.Run(entry)) | 511 if (skip_feature_entry.Run(entry)) |
| 510 continue; | 512 continue; |
| 511 | 513 |
| 512 std::unique_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 514 std::unique_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
| 513 data->SetString("internal_name", entry.internal_name); | 515 data->SetString("internal_name", entry.internal_name); |
| 514 data->SetString("name", base::StringPiece(entry.visible_name)); | 516 data->SetString("name", base::StringPiece(entry.visible_name)); |
| 515 data->SetString("description", | 517 data->SetString("description", |
| 516 base::StringPiece(entry.visible_description)); | 518 base::StringPiece(entry.visible_description)); |
| 517 | 519 |
| 518 base::ListValue* supported_platforms = new base::ListValue(); | 520 auto supported_platforms = base::MakeUnique<base::ListValue>(); |
| 519 AddOsStrings(entry.supported_platforms, supported_platforms); | 521 AddOsStrings(entry.supported_platforms, supported_platforms.get()); |
| 520 data->Set("supported_platforms", supported_platforms); | 522 data->Set("supported_platforms", std::move(supported_platforms)); |
| 521 // True if the switch is not currently passed. | 523 // True if the switch is not currently passed. |
| 522 bool is_default_value = IsDefaultValue(entry, enabled_entries); | 524 bool is_default_value = IsDefaultValue(entry, enabled_entries); |
| 523 data->SetBoolean("is_default", is_default_value); | 525 data->SetBoolean("is_default", is_default_value); |
| 524 | 526 |
| 525 switch (entry.type) { | 527 switch (entry.type) { |
| 526 case FeatureEntry::SINGLE_VALUE: | 528 case FeatureEntry::SINGLE_VALUE: |
| 527 case FeatureEntry::SINGLE_DISABLE_VALUE: | 529 case FeatureEntry::SINGLE_DISABLE_VALUE: |
| 528 data->SetBoolean( | 530 data->SetBoolean( |
| 529 "enabled", | 531 "enabled", |
| 530 (!is_default_value && entry.type == FeatureEntry::SINGLE_VALUE) || | 532 (!is_default_value && entry.type == FeatureEntry::SINGLE_VALUE) || |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 state == FeatureEntry::FeatureState::ENABLED, | 797 state == FeatureEntry::FeatureState::ENABLED, |
| 796 name_to_switch_map); | 798 name_to_switch_map); |
| 797 } | 799 } |
| 798 } | 800 } |
| 799 break; | 801 break; |
| 800 } | 802 } |
| 801 } | 803 } |
| 802 } | 804 } |
| 803 | 805 |
| 804 } // namespace flags_ui | 806 } // namespace flags_ui |
| OLD | NEW |