blob: b7d9c72a36b47d54ff09afcf42bd63743521f3af [file] [log] [blame]
// Copyright 2014 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 "chrome/browser/android/preferences/pref_service_bridge.h"
#include <jni.h>
#include <string>
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "chrome/browser/android/preferences/prefs.h"
#include "chrome/browser/preferences/jni_headers/PrefServiceBridge_jni.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "components/prefs/pref_service.h"
namespace {
PrefService* GetPrefService() {
return ProfileManager::GetActiveUserProfile()
->GetOriginalProfile()
->GetPrefs();
}
} // namespace
const char* PrefServiceBridge::GetPrefNameExposedToJava(int pref_index) {
DCHECK_GE(pref_index, 0);
DCHECK_LT(pref_index, Pref::PREF_NUM_PREFS);
return kPrefsExposedToJava[pref_index];
}
// ----------------------------------------------------------------------------
// Native JNI methods
// ----------------------------------------------------------------------------
static void JNI_PrefServiceBridge_ClearPref(JNIEnv* env,
const jint j_pref_index) {
GetPrefService()->ClearPref(
PrefServiceBridge::GetPrefNameExposedToJava(j_pref_index));
}
static jboolean JNI_PrefServiceBridge_GetBoolean(
JNIEnv* env,
const jint j_pref_index) {
return GetPrefService()->GetBoolean(
PrefServiceBridge::GetPrefNameExposedToJava(j_pref_index));
}
static void JNI_PrefServiceBridge_SetBoolean(JNIEnv* env,
const jint j_pref_index,
const jboolean j_value) {
GetPrefService()->SetBoolean(
PrefServiceBridge::GetPrefNameExposedToJava(j_pref_index), j_value);
}
static jint JNI_PrefServiceBridge_GetInteger(JNIEnv* env,
const jint j_pref_index) {
return GetPrefService()->GetInteger(
PrefServiceBridge::GetPrefNameExposedToJava(j_pref_index));
}
static void JNI_PrefServiceBridge_SetInteger(JNIEnv* env,
const jint j_pref_index,
const jint j_value) {
GetPrefService()->SetInteger(
PrefServiceBridge::GetPrefNameExposedToJava(j_pref_index), j_value);
}
static base::android::ScopedJavaLocalRef<jstring>
JNI_PrefServiceBridge_GetString(JNIEnv* env, const jint j_pref_index) {
return base::android::ConvertUTF8ToJavaString(
env, GetPrefService()->GetString(
PrefServiceBridge::GetPrefNameExposedToJava(j_pref_index)));
}
static void JNI_PrefServiceBridge_SetString(
JNIEnv* env,
const jint j_pref_index,
const base::android::JavaParamRef<jstring>& j_value) {
GetPrefService()->SetString(
PrefServiceBridge::GetPrefNameExposedToJava(j_pref_index),
base::android::ConvertJavaStringToUTF8(env, j_value));
}
static jboolean JNI_PrefServiceBridge_IsManagedPreference(
JNIEnv* env,
const jint j_pref_index) {
return GetPrefService()->IsManagedPreference(
PrefServiceBridge::GetPrefNameExposedToJava(j_pref_index));
}