| 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 "android_webview/browser/command_line_helper.h" | 5 #include "android_webview/browser/command_line_helper.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 | 14 |
| 15 using std::string; | 15 using std::string; |
| 16 using std::vector; | 16 using std::vector; |
| 17 | 17 |
| 18 namespace { |
| 19 |
| 20 // Adds |feature_name| to the list of features in |feature_list_name|, but only |
| 21 // if the |feature_name| is absent from the list of features in both |
| 22 // |feature_list_name| and |other_feature_list_name|. |
| 23 void AddFeatureToList(base::CommandLine& command_line, |
| 24 const string& feature_name, |
| 25 const char* feature_list_name, |
| 26 const char* other_feature_list_name) { |
| 27 const string features_list = |
| 28 command_line.GetSwitchValueASCII(feature_list_name); |
| 29 const string other_features_list = |
| 30 command_line.GetSwitchValueASCII(other_feature_list_name); |
| 31 |
| 32 if (features_list.empty() && other_features_list.empty()) { |
| 33 command_line.AppendSwitchASCII(feature_list_name, feature_name); |
| 34 return; |
| 35 } |
| 36 |
| 37 vector<string> features = |
| 38 base::FeatureList::SplitFeatureListString(features_list); |
| 39 vector<string> other_features = |
| 40 base::FeatureList::SplitFeatureListString(other_features_list); |
| 41 |
| 42 if (!base::ContainsValue(features, feature_name) && |
| 43 !base::ContainsValue(other_features, feature_name)) { |
| 44 features.push_back(feature_name); |
| 45 command_line.AppendSwitchASCII(feature_list_name, |
| 46 base::JoinString(features, ",")); |
| 47 } |
| 48 } |
| 49 |
| 50 } // namespace |
| 51 |
| 18 // static | 52 // static |
| 19 void CommandLineHelper::AddEnabledFeature(base::CommandLine& command_line, | 53 void CommandLineHelper::AddEnabledFeature(base::CommandLine& command_line, |
| 20 const string& feature_name) { | 54 const string& feature_name) { |
| 21 const string enabled_features_list = | 55 AddFeatureToList(command_line, feature_name, switches::kEnableFeatures, |
| 22 command_line.GetSwitchValueASCII(switches::kEnableFeatures); | 56 switches::kDisableFeatures); |
| 23 const string disabled_features_list = | 57 } |
| 24 command_line.GetSwitchValueASCII(switches::kDisableFeatures); | |
| 25 | 58 |
| 26 if (enabled_features_list.empty() && disabled_features_list.empty()) { | 59 // static |
| 27 command_line.AppendSwitchASCII(switches::kEnableFeatures, feature_name); | 60 void CommandLineHelper::AddDisabledFeature(base::CommandLine& command_line, |
| 28 return; | 61 const string& feature_name) { |
| 29 } | 62 AddFeatureToList(command_line, feature_name, switches::kDisableFeatures, |
| 30 | 63 switches::kEnableFeatures); |
| 31 vector<string> enabled_features = | |
| 32 base::FeatureList::SplitFeatureListString(enabled_features_list); | |
| 33 vector<string> disabled_features = | |
| 34 base::FeatureList::SplitFeatureListString(disabled_features_list); | |
| 35 | |
| 36 if (!base::ContainsValue(enabled_features, feature_name) && | |
| 37 !base::ContainsValue(disabled_features, feature_name)) { | |
| 38 enabled_features.push_back(feature_name); | |
| 39 command_line.AppendSwitchASCII(switches::kEnableFeatures, | |
| 40 base::JoinString(enabled_features, ",")); | |
| 41 } | |
| 42 } | 64 } |
| OLD | NEW |