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

Side by Side Diff: components/flags_ui/flags_state.cc

Issue 2231753002: components: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: One more call site 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 unified diff | Download patch
OLDNEW
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"
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 #else 397 #else
398 const std::string& existing_value_utf8 = existing_value; 398 const std::string& existing_value_utf8 = existing_value;
399 #endif 399 #endif
400 400
401 std::vector<std::string> features = 401 std::vector<std::string> features =
402 base::FeatureList::SplitFeatureListString(existing_value_utf8); 402 base::FeatureList::SplitFeatureListString(existing_value_utf8);
403 std::vector<std::string> remaining_features; 403 std::vector<std::string> remaining_features;
404 // For any featrue name in |features| that is not in |switch_added_values| - 404 // For any featrue name in |features| that is not in |switch_added_values| -
405 // i.e. it wasn't added by about_flags code, add it to |remaining_features|. 405 // i.e. it wasn't added by about_flags code, add it to |remaining_features|.
406 for (const std::string& feature : features) { 406 for (const std::string& feature : features) {
407 if (!ContainsKey(switch_added_values, feature)) 407 if (!base::ContainsKey(switch_added_values, feature))
408 remaining_features.push_back(feature); 408 remaining_features.push_back(feature);
409 } 409 }
410 410
411 // Either remove the flag entirely if |remaining_features| is empty, or set 411 // Either remove the flag entirely if |remaining_features| is empty, or set
412 // the new list. 412 // the new list.
413 if (remaining_features.empty()) { 413 if (remaining_features.empty()) {
414 switch_list->erase(switch_name); 414 switch_list->erase(switch_name);
415 } else { 415 } else {
416 std::string switch_value = base::JoinString(remaining_features, ","); 416 std::string switch_value = base::JoinString(remaining_features, ",");
417 #if defined(OS_WIN) 417 #if defined(OS_WIN)
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 } 585 }
586 586
587 return result; 587 return result;
588 } 588 }
589 589
590 void FlagsState::AddSwitchMapping( 590 void FlagsState::AddSwitchMapping(
591 const std::string& key, 591 const std::string& key,
592 const std::string& switch_name, 592 const std::string& switch_name,
593 const std::string& switch_value, 593 const std::string& switch_value,
594 std::map<std::string, SwitchEntry>* name_to_switch_map) { 594 std::map<std::string, SwitchEntry>* name_to_switch_map) {
595 DCHECK(!ContainsKey(*name_to_switch_map, key)); 595 DCHECK(!base::ContainsKey(*name_to_switch_map, key));
596 596
597 SwitchEntry* entry = &(*name_to_switch_map)[key]; 597 SwitchEntry* entry = &(*name_to_switch_map)[key];
598 entry->switch_name = switch_name; 598 entry->switch_name = switch_name;
599 entry->switch_value = switch_value; 599 entry->switch_value = switch_value;
600 } 600 }
601 601
602 void FlagsState::AddFeatureMapping( 602 void FlagsState::AddFeatureMapping(
603 const std::string& key, 603 const std::string& key,
604 const std::string& feature_name, 604 const std::string& feature_name,
605 bool feature_state, 605 bool feature_state,
606 std::map<std::string, SwitchEntry>* name_to_switch_map) { 606 std::map<std::string, SwitchEntry>* name_to_switch_map) {
607 DCHECK(!ContainsKey(*name_to_switch_map, key)); 607 DCHECK(!base::ContainsKey(*name_to_switch_map, key));
608 608
609 SwitchEntry* entry = &(*name_to_switch_map)[key]; 609 SwitchEntry* entry = &(*name_to_switch_map)[key];
610 entry->feature_name = feature_name; 610 entry->feature_name = feature_name;
611 entry->feature_state = feature_state; 611 entry->feature_state = feature_state;
612 } 612 }
613 613
614 void FlagsState::AddSwitchesToCommandLine( 614 void FlagsState::AddSwitchesToCommandLine(
615 const std::set<std::string>& enabled_entries, 615 const std::set<std::string>& enabled_entries,
616 const std::map<std::string, SwitchEntry>& name_to_switch_map, 616 const std::map<std::string, SwitchEntry>& name_to_switch_map,
617 SentinelsMode sentinels, 617 SentinelsMode sentinels,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 void FlagsState::MergeFeatureCommandLineSwitch( 658 void FlagsState::MergeFeatureCommandLineSwitch(
659 const std::map<std::string, bool>& feature_switches, 659 const std::map<std::string, bool>& feature_switches,
660 const char* switch_name, 660 const char* switch_name,
661 bool feature_state, 661 bool feature_state,
662 base::CommandLine* command_line) { 662 base::CommandLine* command_line) {
663 std::string original_switch_value = 663 std::string original_switch_value =
664 command_line->GetSwitchValueASCII(switch_name); 664 command_line->GetSwitchValueASCII(switch_name);
665 std::vector<std::string> features = 665 std::vector<std::string> features =
666 base::FeatureList::SplitFeatureListString(original_switch_value); 666 base::FeatureList::SplitFeatureListString(original_switch_value);
667 // Only add features that don't already exist in the lists. 667 // Only add features that don't already exist in the lists.
668 // Note: The ContainsValue() call results in O(n^2) performance, but in 668 // Note: The base::ContainsValue() call results in O(n^2) performance, but in
669 // practice n should be very small. 669 // practice n should be very small.
670 for (const auto& entry : feature_switches) { 670 for (const auto& entry : feature_switches) {
671 if (entry.second == feature_state && 671 if (entry.second == feature_state &&
672 !ContainsValue(features, entry.first)) { 672 !base::ContainsValue(features, entry.first)) {
673 features.push_back(entry.first); 673 features.push_back(entry.first);
674 appended_switches_[switch_name].insert(entry.first); 674 appended_switches_[switch_name].insert(entry.first);
675 } 675 }
676 } 676 }
677 // Update the switch value only if it didn't change. This avoids setting an 677 // Update the switch value only if it didn't change. This avoids setting an
678 // empty list or duplicating the same list (since AppendSwitch() adds the 678 // empty list or duplicating the same list (since AppendSwitch() adds the
679 // switch to the end but doesn't remove previous ones). 679 // switch to the end but doesn't remove previous ones).
680 std::string switch_value = base::JoinString(features, ","); 680 std::string switch_value = base::JoinString(features, ",");
681 if (switch_value != original_switch_value) 681 if (switch_value != original_switch_value)
682 command_line->AppendSwitchASCII(switch_name, switch_value); 682 command_line->AppendSwitchASCII(switch_name, switch_value);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 } 726 }
727 727
728 std::set<std::string> new_enabled_entries = 728 std::set<std::string> new_enabled_entries =
729 base::STLSetIntersection<std::set<std::string>>(platform_entries, 729 base::STLSetIntersection<std::set<std::string>>(platform_entries,
730 *result); 730 *result);
731 731
732 result->swap(new_enabled_entries); 732 result->swap(new_enabled_entries);
733 } 733 }
734 734
735 } // namespace flags_ui 735 } // namespace flags_ui
OLDNEW
« no previous file with comments | « components/feedback/feedback_uploader_unittest.cc ('k') | components/flags_ui/flags_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698