Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/android/chrome_feature_list.h" | 5 #include "chrome/browser/android/chrome_feature_list.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/metrics/field_trial_params.h" | 14 #include "base/metrics/field_trial_params.h" |
| 15 #include "chrome/common/chrome_features.h" | 15 #include "chrome/common/chrome_features.h" |
| 16 #include "components/autofill/core/browser/autofill_experiments.h" | 16 #include "components/autofill/core/browser/autofill_experiments.h" |
| 17 #include "components/ntp_snippets/features.h" | 17 #include "components/ntp_snippets/features.h" |
| 18 #include "components/offline_pages/core/offline_page_feature.h" | 18 #include "components/offline_pages/core/offline_page_feature.h" |
| 19 #include "components/password_manager/core/common/password_manager_features.h" | 19 #include "components/password_manager/core/common/password_manager_features.h" |
| 20 #include "content/public/common/content_features.h" | 20 #include "content/public/common/content_features.h" |
| 21 #include "jni/ChromeFeatureList_jni.h" | 21 #include "jni/ChromeFeatureList_jni.h" |
| 22 | 22 |
| 23 using base::android::ConvertJavaStringToUTF8; | 23 using base::android::ConvertJavaStringToUTF8; |
| 24 using base::android::ConvertUTF8ToJavaString; | |
| 24 using base::android::JavaParamRef; | 25 using base::android::JavaParamRef; |
| 26 using base::android::ScopedJavaLocalRef; | |
| 25 | 27 |
| 26 namespace chrome { | 28 namespace chrome { |
| 27 namespace android { | 29 namespace android { |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 // Array of features exposed through the Java ChromeFeatureList API. Entries in | 33 // Array of features exposed through the Java ChromeFeatureList API. Entries in |
| 32 // this array may either refer to features defined in the header of this file or | 34 // this array may either refer to features defined in the header of this file or |
| 33 // in other locations in the code base (e.g. chrome/, components/, etc). | 35 // in other locations in the code base (e.g. chrome/, components/, etc). |
| 34 const base::Feature* kFeaturesExposedToJava[] = { | 36 const base::Feature* kFeaturesExposedToJava[] = { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 65 &ntp_snippets::kIncreasedVisibility, | 67 &ntp_snippets::kIncreasedVisibility, |
| 66 &ntp_snippets::kForeignSessionsSuggestionsFeature, | 68 &ntp_snippets::kForeignSessionsSuggestionsFeature, |
| 67 &ntp_snippets::kOfflineBadgeFeature, | 69 &ntp_snippets::kOfflineBadgeFeature, |
| 68 &ntp_snippets::kSaveToOfflineFeature, | 70 &ntp_snippets::kSaveToOfflineFeature, |
| 69 &offline_pages::kBackgroundLoaderForDownloadsFeature, | 71 &offline_pages::kBackgroundLoaderForDownloadsFeature, |
| 70 &offline_pages::kOfflinePagesCTFeature, // See crbug.com/620421. | 72 &offline_pages::kOfflinePagesCTFeature, // See crbug.com/620421. |
| 71 &offline_pages::kOfflinePagesSharingFeature, | 73 &offline_pages::kOfflinePagesSharingFeature, |
| 72 &password_manager::features::kViewPasswords, | 74 &password_manager::features::kViewPasswords, |
| 73 }; | 75 }; |
| 74 | 76 |
| 77 const base::Feature* FindFeatureExposedToJava(const std::string feature_name) { | |
|
Alexei Svitkine (slow)
2017/02/09 15:09:37
const std::string&
| |
| 78 for (size_t i = 0; i < arraysize(kFeaturesExposedToJava); ++i) { | |
| 79 if (kFeaturesExposedToJava[i]->name == feature_name) | |
| 80 return kFeaturesExposedToJava[i]; | |
| 81 } | |
| 82 return nullptr; | |
| 83 } | |
| 84 | |
| 75 } // namespace | 85 } // namespace |
| 76 | 86 |
| 77 // Alphabetical: | 87 // Alphabetical: |
| 78 const base::Feature kAndroidPayIntegrationV1{"AndroidPayIntegrationV1", | 88 const base::Feature kAndroidPayIntegrationV1{"AndroidPayIntegrationV1", |
| 79 base::FEATURE_ENABLED_BY_DEFAULT}; | 89 base::FEATURE_ENABLED_BY_DEFAULT}; |
| 80 | 90 |
| 81 const base::Feature kAndroidPayIntegrationV2{"AndroidPayIntegrationV2", | 91 const base::Feature kAndroidPayIntegrationV2{"AndroidPayIntegrationV2", |
| 82 base::FEATURE_DISABLED_BY_DEFAULT}; | 92 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 83 | 93 |
| 84 const base::Feature kAndroidPaymentApps{"AndroidPaymentApps", | 94 const base::Feature kAndroidPaymentApps{"AndroidPaymentApps", |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 | 154 |
| 145 const base::Feature kWebPaymentsSingleAppUiSkip{ | 155 const base::Feature kWebPaymentsSingleAppUiSkip{ |
| 146 "WebPaymentsSingleAppUiSkip", base::FEATURE_ENABLED_BY_DEFAULT}; | 156 "WebPaymentsSingleAppUiSkip", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 147 | 157 |
| 148 const base::Feature kWebVRCardboardSupport{ | 158 const base::Feature kWebVRCardboardSupport{ |
| 149 "WebVRCardboardSupport", base::FEATURE_ENABLED_BY_DEFAULT}; | 159 "WebVRCardboardSupport", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 150 | 160 |
| 151 static jboolean IsEnabled(JNIEnv* env, | 161 static jboolean IsEnabled(JNIEnv* env, |
| 152 const JavaParamRef<jclass>& clazz, | 162 const JavaParamRef<jclass>& clazz, |
| 153 const JavaParamRef<jstring>& jfeature_name) { | 163 const JavaParamRef<jstring>& jfeature_name) { |
| 154 const std::string feature_name = ConvertJavaStringToUTF8(env, jfeature_name); | 164 const base::Feature* feature = |
| 155 for (size_t i = 0; i < arraysize(kFeaturesExposedToJava); ++i) { | 165 FindFeatureExposedToJava(ConvertJavaStringToUTF8(env, jfeature_name)); |
| 156 if (kFeaturesExposedToJava[i]->name == feature_name) | 166 if (feature != nullptr) { |
|
Alexei Svitkine (slow)
2017/02/09 15:09:37
Nit: No {}
| |
| 157 return base::FeatureList::IsEnabled(*kFeaturesExposedToJava[i]); | 167 return base::FeatureList::IsEnabled(*feature); |
| 158 } | 168 } |
| 159 // Features queried via this API must be present in |kFeaturesExposedToJava|. | 169 // Features queried via this API must be present in |kFeaturesExposedToJava|. |
| 160 NOTREACHED(); | 170 NOTREACHED(); |
| 161 return false; | 171 return false; |
| 162 } | 172 } |
| 163 | 173 |
| 174 static ScopedJavaLocalRef<jstring> GetFieldTrialParamByFeature( | |
| 175 JNIEnv* env, | |
| 176 const JavaParamRef<jclass>& clazz, | |
| 177 const JavaParamRef<jstring>& jfeature_name, | |
| 178 const JavaParamRef<jstring>& jparam_name) { | |
| 179 const base::Feature* feature = | |
| 180 FindFeatureExposedToJava(ConvertJavaStringToUTF8(env, jfeature_name)); | |
| 181 if (feature != nullptr) { | |
| 182 const std::string param_name = ConvertJavaStringToUTF8(env, jparam_name); | |
| 183 std::string param_value = | |
| 184 base::GetFieldTrialParamValueByFeature(*feature, param_name); | |
| 185 return ConvertUTF8ToJavaString(env, param_value); | |
| 186 } | |
| 187 // Features queried via this API must be present in |kFeaturesExposedToJava|. | |
| 188 NOTREACHED(); | |
| 189 return ConvertUTF8ToJavaString(env, std::string()); | |
| 190 } | |
| 191 | |
| 164 static jint GetFieldTrialParamByFeatureAsInt( | 192 static jint GetFieldTrialParamByFeatureAsInt( |
| 165 JNIEnv* env, | 193 JNIEnv* env, |
| 166 const JavaParamRef<jclass>& clazz, | 194 const JavaParamRef<jclass>& clazz, |
| 167 const JavaParamRef<jstring>& jfeature_name, | 195 const JavaParamRef<jstring>& jfeature_name, |
| 168 const JavaParamRef<jstring>& jparam_name, | 196 const JavaParamRef<jstring>& jparam_name, |
| 169 const jint jdefault_value) { | 197 const jint jdefault_value) { |
| 170 const std::string feature_name = ConvertJavaStringToUTF8(env, jfeature_name); | 198 const base::Feature* feature = |
| 171 const std::string param_name = ConvertJavaStringToUTF8(env, jparam_name); | 199 FindFeatureExposedToJava(ConvertJavaStringToUTF8(env, jfeature_name)); |
| 172 int default_value = static_cast<int>(jdefault_value); | 200 if (feature != nullptr) { |
| 173 | 201 const std::string param_name = ConvertJavaStringToUTF8(env, jparam_name); |
| 174 for (size_t i = 0; i < arraysize(kFeaturesExposedToJava); ++i) { | 202 return base::GetFieldTrialParamByFeatureAsInt(*feature, param_name, |
| 175 if (kFeaturesExposedToJava[i]->name == feature_name) | 203 jdefault_value); |
| 176 return base::GetFieldTrialParamByFeatureAsInt( | |
| 177 *kFeaturesExposedToJava[i], param_name, default_value); | |
| 178 } | 204 } |
| 179 // Features queried via this API must be present in |kFeaturesExposedToJava|. | 205 // Features queried via this API must be present in |kFeaturesExposedToJava|. |
| 180 NOTREACHED(); | 206 NOTREACHED(); |
| 207 return jdefault_value; | |
| 208 } | |
| 209 | |
| 210 static jdouble GetFieldTrialParamByFeatureAsDouble( | |
| 211 JNIEnv* env, | |
| 212 const JavaParamRef<jclass>& clazz, | |
| 213 const JavaParamRef<jstring>& jfeature_name, | |
| 214 const JavaParamRef<jstring>& jparam_name, | |
| 215 const jdouble jdefault_value) { | |
| 216 const base::Feature* feature = | |
| 217 FindFeatureExposedToJava(ConvertJavaStringToUTF8(env, jfeature_name)); | |
| 218 if (feature != nullptr) { | |
| 219 const std::string param_name = ConvertJavaStringToUTF8(env, jparam_name); | |
| 220 return base::GetFieldTrialParamByFeatureAsDouble(*feature, param_name, | |
| 221 jdefault_value); | |
| 222 } | |
| 223 // Features queried via this API must be present in |kFeaturesExposedToJava|. | |
| 224 NOTREACHED(); | |
| 225 return jdefault_value; | |
| 226 } | |
| 227 | |
| 228 static jboolean GetFieldTrialParamByFeatureAsBoolean( | |
| 229 JNIEnv* env, | |
| 230 const JavaParamRef<jclass>& clazz, | |
| 231 const JavaParamRef<jstring>& jfeature_name, | |
| 232 const JavaParamRef<jstring>& jparam_name, | |
| 233 const jboolean jdefault_value) { | |
| 234 const base::Feature* feature = | |
| 235 FindFeatureExposedToJava(ConvertJavaStringToUTF8(env, jfeature_name)); | |
| 236 if (feature != nullptr) { | |
| 237 const std::string param_name = ConvertJavaStringToUTF8(env, jparam_name); | |
| 238 return base::GetFieldTrialParamByFeatureAsBool(*feature, param_name, | |
| 239 jdefault_value); | |
| 240 } | |
| 241 // Features queried via this API must be present in |kFeaturesExposedToJava|. | |
| 242 NOTREACHED(); | |
| 181 return jdefault_value; | 243 return jdefault_value; |
| 182 } | 244 } |
| 183 | 245 |
| 184 bool RegisterChromeFeatureListJni(JNIEnv* env) { | 246 bool RegisterChromeFeatureListJni(JNIEnv* env) { |
| 185 return RegisterNativesImpl(env); | 247 return RegisterNativesImpl(env); |
| 186 } | 248 } |
| 187 | 249 |
| 188 } // namespace android | 250 } // namespace android |
| 189 } // namespace chrome | 251 } // namespace chrome |
| OLD | NEW |