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/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/string_piece.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
20 #include "components/flags_ui/feature_entry.h" | 21 #include "components/flags_ui/feature_entry.h" |
21 #include "components/flags_ui/flags_storage.h" | 22 #include "components/flags_ui/flags_storage.h" |
22 #include "components/flags_ui/flags_ui_switches.h" | 23 #include "components/flags_ui/flags_ui_switches.h" |
23 #include "components/variations/variations_associated_data.h" | 24 #include "components/variations/variations_associated_data.h" |
24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
25 | 26 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 const auto& switch_added_values = entry.second; | 383 const auto& switch_added_values = entry.second; |
383 | 384 |
384 // The below is either a std::string or a base::string16 based on platform. | 385 // The below is either a std::string or a base::string16 based on platform. |
385 const auto& existing_value = (*switch_list)[switch_name]; | 386 const auto& existing_value = (*switch_list)[switch_name]; |
386 #if defined(OS_WIN) | 387 #if defined(OS_WIN) |
387 const std::string existing_value_utf8 = base::UTF16ToUTF8(existing_value); | 388 const std::string existing_value_utf8 = base::UTF16ToUTF8(existing_value); |
388 #else | 389 #else |
389 const std::string& existing_value_utf8 = existing_value; | 390 const std::string& existing_value_utf8 = existing_value; |
390 #endif | 391 #endif |
391 | 392 |
392 std::vector<std::string> features = | 393 std::vector<base::StringPiece> features = |
393 base::FeatureList::SplitFeatureListString(existing_value_utf8); | 394 base::FeatureList::SplitFeatureListString(existing_value_utf8); |
394 std::vector<std::string> remaining_features; | 395 std::vector<base::StringPiece> remaining_features; |
395 // For any featrue name in |features| that is not in |switch_added_values| - | 396 // For any featrue name in |features| that is not in |switch_added_values| - |
396 // i.e. it wasn't added by about_flags code, add it to |remaining_features|. | 397 // i.e. it wasn't added by about_flags code, add it to |remaining_features|. |
397 for (const std::string& feature : features) { | 398 for (const auto& feature : features) { |
398 if (!base::ContainsKey(switch_added_values, feature)) | 399 if (!base::ContainsKey(switch_added_values, feature.as_string())) |
399 remaining_features.push_back(feature); | 400 remaining_features.push_back(feature); |
400 } | 401 } |
401 | 402 |
402 // Either remove the flag entirely if |remaining_features| is empty, or set | 403 // Either remove the flag entirely if |remaining_features| is empty, or set |
403 // the new list. | 404 // the new list. |
404 if (remaining_features.empty()) { | 405 if (remaining_features.empty()) { |
405 switch_list->erase(switch_name); | 406 switch_list->erase(switch_name); |
406 } else { | 407 } else { |
407 std::string switch_value = base::JoinString(remaining_features, ","); | 408 std::string switch_value = base::JoinString(remaining_features, ","); |
408 #if defined(OS_WIN) | 409 #if defined(OS_WIN) |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 } | 677 } |
677 } | 678 } |
678 | 679 |
679 void FlagsState::MergeFeatureCommandLineSwitch( | 680 void FlagsState::MergeFeatureCommandLineSwitch( |
680 const std::map<std::string, bool>& feature_switches, | 681 const std::map<std::string, bool>& feature_switches, |
681 const char* switch_name, | 682 const char* switch_name, |
682 bool feature_state, | 683 bool feature_state, |
683 base::CommandLine* command_line) { | 684 base::CommandLine* command_line) { |
684 std::string original_switch_value = | 685 std::string original_switch_value = |
685 command_line->GetSwitchValueASCII(switch_name); | 686 command_line->GetSwitchValueASCII(switch_name); |
686 std::vector<std::string> features = | 687 std::vector<base::StringPiece> features = |
687 base::FeatureList::SplitFeatureListString(original_switch_value); | 688 base::FeatureList::SplitFeatureListString(original_switch_value); |
688 // Only add features that don't already exist in the lists. | 689 // Only add features that don't already exist in the lists. |
689 // Note: The base::ContainsValue() call results in O(n^2) performance, but in | 690 // Note: The base::ContainsValue() call results in O(n^2) performance, but in |
690 // practice n should be very small. | 691 // practice n should be very small. |
691 for (const auto& entry : feature_switches) { | 692 for (const auto& entry : feature_switches) { |
692 if (entry.second == feature_state && | 693 if (entry.second == feature_state && |
693 !base::ContainsValue(features, entry.first)) { | 694 !base::ContainsValue(features, entry.first)) { |
694 features.push_back(entry.first); | 695 features.push_back(entry.first); |
695 appended_switches_[switch_name].insert(entry.first); | 696 appended_switches_[switch_name].insert(entry.first); |
696 } | 697 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 state == FeatureEntry::FeatureState::ENABLED, | 795 state == FeatureEntry::FeatureState::ENABLED, |
795 name_to_switch_map); | 796 name_to_switch_map); |
796 } | 797 } |
797 } | 798 } |
798 break; | 799 break; |
799 } | 800 } |
800 } | 801 } |
801 } | 802 } |
802 | 803 |
803 } // namespace flags_ui | 804 } // namespace flags_ui |
OLD | NEW |