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

Unified Diff: base/test/scoped_feature_list.cc

Issue 2806263005: Convert the overlay scrollbar flag to use FeatureList (Closed)
Patch Set: dcheng comment addressed Created 3 years, 8 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 | « base/test/scoped_feature_list.h ('k') | base/test/scoped_feature_list_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/scoped_feature_list.cc
diff --git a/base/test/scoped_feature_list.cc b/base/test/scoped_feature_list.cc
index f0f3f4edfba1f1d333ef3188836cf14273795739..8f8535898bbfeac9b99ac9e103d62aa76542c1a7 100644
--- a/base/test/scoped_feature_list.cc
+++ b/base/test/scoped_feature_list.cc
@@ -4,7 +4,12 @@
#include "base/test/scoped_feature_list.h"
+#include <algorithm>
#include <string>
+#include <vector>
+
+#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
namespace base {
namespace test {
@@ -70,5 +75,66 @@ void ScopedFeatureList::InitAndDisableFeature(const base::Feature& feature) {
InitFromCommandLine(std::string(), feature.name);
}
+void OverrideFeature(const StringPiece& feature,
+ std::vector<std::string>* check_list,
+ std::vector<std::string>* add_to_list) {
+ // Start with * means use default.
+ if (feature.starts_with("*"))
+ return;
+
+ // Remove field_trial info.
+ StringPiece feature_name = feature;
+ std::size_t index = feature.find("<");
+ if (index != std::string::npos)
+ feature_name = feature.substr(0, index);
+
+ if (std::any_of(
+ check_list->begin(), check_list->end(),
+ [&feature_name](std::string& s) { return feature_name == s; }))
+ return;
+
+ if (std::any_of(
+ add_to_list->begin(), add_to_list->end(),
+ [&feature_name](std::string& s) { return feature_name == s; }))
+ return;
+
+ add_to_list->push_back(feature_name.as_string());
+}
+
+void ScopedFeatureList::InitWithFeatureListAndOverrides(
+ base::FeatureList* feature_list,
+ const std::vector<std::string>& override_enabled_features,
+ const std::vector<std::string>& override_disabled_features) {
+ std::vector<std::string> merged_enabled_features(override_enabled_features);
+ std::vector<std::string> merged_disabled_features(override_disabled_features);
+
+ if (feature_list) {
dcheng 2017/04/18 00:18:05 I still don't understand why we pass in feature_li
+ std::string enabled_features;
+ std::string disabled_features;
+ base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features,
+ &disabled_features);
+
+ std::vector<StringPiece> enabled_features_list = SplitStringPiece(
+ enabled_features, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY);
+
+ std::vector<StringPiece> disabled_features_list = SplitStringPiece(
+ disabled_features, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY);
+
+ for (StringPiece& feature : enabled_features_list) {
+ OverrideFeature(feature, &merged_disabled_features,
+ &merged_enabled_features);
+ }
+
+ for (StringPiece& feature : disabled_features_list) {
+ OverrideFeature(feature, &merged_enabled_features,
+ &merged_disabled_features);
+ }
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
+ }
+
+ std::string enabled = JoinString(merged_enabled_features, ",");
+ std::string disabled = JoinString(merged_disabled_features, ",");
+ InitFromCommandLine(enabled, disabled);
+}
+
} // namespace test
} // namespace base
« no previous file with comments | « base/test/scoped_feature_list.h ('k') | base/test/scoped_feature_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698