diff options
Diffstat (limited to 'chromium/components/user_prefs')
5 files changed, 84 insertions, 0 deletions
diff --git a/chromium/components/user_prefs/BUILD.gn b/chromium/components/user_prefs/BUILD.gn index ed09b2dad6a..917ba89ca9b 100644 --- a/chromium/components/user_prefs/BUILD.gn +++ b/chromium/components/user_prefs/BUILD.gn @@ -15,4 +15,14 @@ component("user_prefs") { "//base", "//components/prefs", ] + + if (is_android) { + sources += [ "android/user_prefs_android.cc" ] + deps += [ + "android:jni_headers", + "//components/embedder_support/android:browser_context", + "//components/prefs", + "//content/public/browser", + ] + } } diff --git a/chromium/components/user_prefs/android/BUILD.gn b/chromium/components/user_prefs/android/BUILD.gn new file mode 100644 index 00000000000..53b9ad5c967 --- /dev/null +++ b/chromium/components/user_prefs/android/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright 2020 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. + +import("//build/config/android/rules.gni") + +generate_jni("jni_headers") { + sources = [ "java/src/org/chromium/components/user_prefs/UserPrefs.java" ] +} + +android_library("java") { + sources = [ "java/src/org/chromium/components/user_prefs/UserPrefs.java" ] + deps = [ + "//base:base_java", + "//base:jni_java", + "//components/embedder_support/android:browser_context_java", + "//components/prefs/android:java", + ] + annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ] +} diff --git a/chromium/components/user_prefs/android/DEPS b/chromium/components/user_prefs/android/DEPS new file mode 100644 index 00000000000..9cf922d572a --- /dev/null +++ b/chromium/components/user_prefs/android/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+components/embedder_support/android", + "+content/public/browser", +] diff --git a/chromium/components/user_prefs/android/java/src/org/chromium/components/user_prefs/UserPrefs.java b/chromium/components/user_prefs/android/java/src/org/chromium/components/user_prefs/UserPrefs.java new file mode 100644 index 00000000000..f92ed897a21 --- /dev/null +++ b/chromium/components/user_prefs/android/java/src/org/chromium/components/user_prefs/UserPrefs.java @@ -0,0 +1,27 @@ +// Copyright 2020 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. + +package org.chromium.components.user_prefs; + +import org.chromium.base.annotations.JNINamespace; +import org.chromium.base.annotations.NativeMethods; +import org.chromium.components.embedder_support.browser_context.BrowserContextHandle; +import org.chromium.components.prefs.PrefService; + +/** + * Helper for retrieving a {@link PrefService} from a {@link BrowserContextHandle}. + * This class is modeled after the C++ class of the same name. + */ +@JNINamespace("user_prefs") +public class UserPrefs { + /** Returns the {@link PrefService} associated with the given {@link BrowserContextHandle}. */ + public static PrefService get(BrowserContextHandle browserContextHandle) { + return UserPrefsJni.get().get(browserContextHandle); + } + + @NativeMethods + interface Natives { + PrefService get(BrowserContextHandle browserContextHandle); + } +} diff --git a/chromium/components/user_prefs/android/user_prefs_android.cc b/chromium/components/user_prefs/android/user_prefs_android.cc new file mode 100644 index 00000000000..384bd407a0a --- /dev/null +++ b/chromium/components/user_prefs/android/user_prefs_android.cc @@ -0,0 +1,23 @@ +// Copyright 2020 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 <string> + +#include "components/embedder_support/android/browser_context/browser_context_handle.h" +#include "components/prefs/pref_service.h" +#include "components/user_prefs/android/jni_headers/UserPrefs_jni.h" +#include "components/user_prefs/user_prefs.h" +#include "content/public/browser/browser_context.h" + +namespace user_prefs { + +static base::android::ScopedJavaLocalRef<jobject> JNI_UserPrefs_Get( + JNIEnv* env, + const base::android::JavaParamRef<jobject>& jbrowser_context_handle) { + return UserPrefs::Get(browser_context::BrowserContextFromJavaHandle( + jbrowser_context_handle)) + ->GetJavaObject(); +} + +} // namespace user_prefs |