OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/test/scoped_feature_list.h" | 5 #include "base/test/scoped_feature_list.h" |
6 | 6 |
7 #include <algorithm> | |
7 #include <string> | 8 #include <string> |
9 #include <vector> | |
10 | |
11 #include "base/strings/string_split.h" | |
12 #include "base/strings/string_util.h" | |
8 | 13 |
9 namespace base { | 14 namespace base { |
10 namespace test { | 15 namespace test { |
11 | 16 |
12 namespace { | 17 namespace { |
13 | 18 |
14 static std::string GetFeatureString( | 19 static std::string GetFeatureString( |
15 const std::initializer_list<base::Feature>& features) { | 20 const std::initializer_list<base::Feature>& features) { |
16 std::string output; | 21 std::string output; |
17 for (const base::Feature& feature : features) { | 22 for (const base::Feature& feature : features) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 } | 68 } |
64 | 69 |
65 void ScopedFeatureList::InitAndEnableFeature(const base::Feature& feature) { | 70 void ScopedFeatureList::InitAndEnableFeature(const base::Feature& feature) { |
66 InitFromCommandLine(feature.name, std::string()); | 71 InitFromCommandLine(feature.name, std::string()); |
67 } | 72 } |
68 | 73 |
69 void ScopedFeatureList::InitAndDisableFeature(const base::Feature& feature) { | 74 void ScopedFeatureList::InitAndDisableFeature(const base::Feature& feature) { |
70 InitFromCommandLine(std::string(), feature.name); | 75 InitFromCommandLine(std::string(), feature.name); |
71 } | 76 } |
72 | 77 |
78 void OverrideFeature(const StringPiece& feature, | |
79 std::vector<std::string>* check_list, | |
80 std::vector<std::string>* add_to_list) { | |
81 // Start with * means use default. | |
82 if (feature.starts_with("*")) | |
83 return; | |
84 | |
85 // Remove field_trial info. | |
86 StringPiece feature_name = feature; | |
87 std::size_t index = feature.find("<"); | |
88 if (index != std::string::npos) | |
89 feature_name = feature.substr(0, index); | |
90 | |
91 if (std::any_of( | |
92 check_list->begin(), check_list->end(), | |
93 [&feature_name](std::string& s) { return feature_name == s; })) | |
94 return; | |
95 | |
96 if (std::any_of( | |
97 add_to_list->begin(), add_to_list->end(), | |
98 [&feature_name](std::string& s) { return feature_name == s; })) | |
99 return; | |
100 | |
101 add_to_list->push_back(feature_name.as_string()); | |
102 } | |
103 | |
104 void ScopedFeatureList::InitWithFeatureListAndOverrides( | |
105 base::FeatureList* feature_list, | |
106 const std::vector<std::string>& override_enabled_features, | |
107 const std::vector<std::string>& override_disabled_features) { | |
108 std::vector<std::string> merged_enabled_features(override_enabled_features); | |
109 std::vector<std::string> merged_disabled_features(override_disabled_features); | |
110 | |
111 if (feature_list) { | |
dcheng
2017/04/18 00:18:05
I still don't understand why we pass in feature_li
| |
112 std::string enabled_features; | |
113 std::string disabled_features; | |
114 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features, | |
115 &disabled_features); | |
116 | |
117 std::vector<StringPiece> enabled_features_list = SplitStringPiece( | |
118 enabled_features, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); | |
119 | |
120 std::vector<StringPiece> disabled_features_list = SplitStringPiece( | |
121 disabled_features, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); | |
122 | |
123 for (StringPiece& feature : enabled_features_list) { | |
124 OverrideFeature(feature, &merged_disabled_features, | |
125 &merged_enabled_features); | |
126 } | |
127 | |
128 for (StringPiece& feature : disabled_features_list) { | |
129 OverrideFeature(feature, &merged_enabled_features, | |
130 &merged_disabled_features); | |
131 } | |
dcheng
2017/04/18 00:18:05
I think it just feels weird that:
1. GetFeatureOve
dcheng
2017/04/18 15:54:57
I don't think this comment has been addressed.
Ba
| |
132 } | |
133 | |
134 std::string enabled = JoinString(merged_enabled_features, ","); | |
135 std::string disabled = JoinString(merged_disabled_features, ","); | |
136 InitFromCommandLine(enabled, disabled); | |
137 } | |
138 | |
73 } // namespace test | 139 } // namespace test |
74 } // namespace base | 140 } // namespace base |
OLD | NEW |