Chromium Code Reviews| Index: android_webview/browser/command_line_helper.cc |
| diff --git a/android_webview/browser/command_line_helper.cc b/android_webview/browser/command_line_helper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7dec6413a55cddf3b6ca4dbd895a9068881555bf |
| --- /dev/null |
| +++ b/android_webview/browser/command_line_helper.cc |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "android_webview/browser/command_line_helper.h" |
| + |
| +#include <algorithm> |
| +#include <vector> |
| + |
| +#include "base/command_line.h" |
| +#include "base/feature_list.h" |
| +#include "base/strings/string_util.h" |
| +#include "content/public/common/content_switches.h" |
| + |
| +using std::string; |
| +using std::vector; |
| + |
| +namespace { |
| + |
| +bool contains(const vector<string>& features, const string& feature_name) { |
|
Tobias Sargeant
2016/10/05 13:56:15
This is base::ContainsValue in base/stl_util.h
timvolodine
2016/10/06 11:58:42
yes thanks, I thought there should be something in
|
| + return std::find(features.begin(), features.end(), feature_name) != |
| + features.end(); |
| +} |
| + |
| +} // namespace |
| + |
| +// static |
| +void CommandLineHelper::AddEnabledFeature(base::CommandLine& command_line, |
| + const string& feature_name) { |
| + string enabled_features_list = |
| + command_line.GetSwitchValueASCII(switches::kEnableFeatures); |
| + string disabled_features_list = |
| + command_line.GetSwitchValueASCII(switches::kDisableFeatures); |
| + |
| + if (enabled_features_list.empty() && disabled_features_list.empty()) { |
| + command_line.AppendSwitchASCII(switches::kEnableFeatures, feature_name); |
| + return; |
| + } |
| + |
| + vector<string> enabled_features = |
| + base::FeatureList::SplitFeatureListString(enabled_features_list); |
| + vector<string> disabled_features = |
| + base::FeatureList::SplitFeatureListString(disabled_features_list); |
| + |
| + if (!contains(enabled_features, feature_name) && |
| + !contains(disabled_features, feature_name)) { |
| + enabled_features.push_back(feature_name); |
| + command_line.AppendSwitchASCII(switches::kEnableFeatures, |
| + base::JoinString(enabled_features, ",")); |
| + } |
| +} |