1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <jni.h>
6
7 #include <map>
8 #include <string>
9
10 #include "base/android/jni_string.h"
11 #include "base/metrics/field_trial.h"
12 #include "base/metrics/field_trial_params.h"
13 #include "jni/FieldTrialList_jni.h"
14
15 using base::android::ConvertJavaStringToUTF8;
16 using base::android::ConvertUTF8ToJavaString;
17 using base::android::JavaParamRef;
18 using base::android::ScopedJavaLocalRef;
19
JNI_FieldTrialList_FindFullName(JNIEnv * env,const JavaParamRef<jclass> & clazz,const JavaParamRef<jstring> & jtrial_name)20 static ScopedJavaLocalRef<jstring> JNI_FieldTrialList_FindFullName(
21 JNIEnv* env,
22 const JavaParamRef<jclass>& clazz,
23 const JavaParamRef<jstring>& jtrial_name) {
24 std::string trial_name(ConvertJavaStringToUTF8(env, jtrial_name));
25 return ConvertUTF8ToJavaString(
26 env, base::FieldTrialList::FindFullName(trial_name));
27 }
28
JNI_FieldTrialList_TrialExists(JNIEnv * env,const JavaParamRef<jclass> & clazz,const JavaParamRef<jstring> & jtrial_name)29 static jboolean JNI_FieldTrialList_TrialExists(
30 JNIEnv* env,
31 const JavaParamRef<jclass>& clazz,
32 const JavaParamRef<jstring>& jtrial_name) {
33 std::string trial_name(ConvertJavaStringToUTF8(env, jtrial_name));
34 return base::FieldTrialList::TrialExists(trial_name);
35 }
36
JNI_FieldTrialList_GetVariationParameter(JNIEnv * env,const JavaParamRef<jclass> & clazz,const JavaParamRef<jstring> & jtrial_name,const JavaParamRef<jstring> & jparameter_key)37 static ScopedJavaLocalRef<jstring> JNI_FieldTrialList_GetVariationParameter(
38 JNIEnv* env,
39 const JavaParamRef<jclass>& clazz,
40 const JavaParamRef<jstring>& jtrial_name,
41 const JavaParamRef<jstring>& jparameter_key) {
42 std::map<std::string, std::string> parameters;
43 base::GetFieldTrialParams(ConvertJavaStringToUTF8(env, jtrial_name),
44 ¶meters);
45 return ConvertUTF8ToJavaString(
46 env, parameters[ConvertJavaStringToUTF8(env, jparameter_key)]);
47 }
48