Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Unified Diff: components/policy/android/java/src/org/chromium/policy/PolicyConverter.java

Issue 1220683008: Move AppRestriction to Policy code out of //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/policy/android/BUILD.gn ('k') | components/policy/core/browser/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/policy/android/java/src/org/chromium/policy/PolicyConverter.java
diff --git a/components/policy/android/java/src/org/chromium/policy/PolicyConverter.java b/components/policy/android/java/src/org/chromium/policy/PolicyConverter.java
new file mode 100644
index 0000000000000000000000000000000000000000..4d4835b8324fda833156413d5a5fa8b5b788651a
--- /dev/null
+++ b/components/policy/android/java/src/org/chromium/policy/PolicyConverter.java
@@ -0,0 +1,69 @@
+// Copyright 2015 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.policy;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+
+/**
+ * Allows converting Java policies, contained as key/value pairs in {@link android.os.Bundle}s to
+ * native {@code PolicyBundle}s.
+ *
+ * This class is to be used to send key/value pairs to its native equivalent, that can then be used
+ * to retrieve the native {@code PolicyBundle}.
+ *
+ * It should be created by calling {@link #create(long)} from the native code, and sending it back
+ * to Java.
+ */
+@JNINamespace("policy::android")
+public class PolicyConverter {
+ private long mNativePolicyConverter;
+
+ private PolicyConverter(long nativePolicyConverter) {
+ mNativePolicyConverter = nativePolicyConverter;
+ }
+
+ /** Convert and send the key/value pair for a policy to the native {@code PolicyConverter}. */
+ public void setPolicy(String key, Object value) {
+ assert mNativePolicyConverter != 0;
+
+ if (value instanceof Boolean) {
+ nativeSetPolicyBoolean(mNativePolicyConverter, key, (Boolean) value);
+ return;
+ }
+ if (value instanceof String) {
+ nativeSetPolicyString(mNativePolicyConverter, key, (String) value);
+ return;
+ }
+ if (value instanceof Integer) {
+ nativeSetPolicyInteger(mNativePolicyConverter, key, (Integer) value);
+ return;
+ }
+ if (value instanceof String[]) {
+ nativeSetPolicyStringArray(mNativePolicyConverter, key, (String[]) value);
+ return;
+ }
+ assert false : "Invalid setting " + value + " for key " + key;
+ }
+
+ @CalledByNative
+ private static PolicyConverter create(long nativePolicyConverter) {
+ return new PolicyConverter(nativePolicyConverter);
+ }
+
+ @CalledByNative
+ private void onNativeDestroyed() {
+ mNativePolicyConverter = 0;
+ }
+
+ private native void nativeSetPolicyBoolean(
+ long nativePolicyConverter, String policyKey, boolean value);
+ private native void nativeSetPolicyInteger(
+ long nativePolicyConverter, String policyKey, int value);
+ private native void nativeSetPolicyString(
+ long nativePolicyConverter, String policyKey, String value);
+ private native void nativeSetPolicyStringArray(
+ long nativePolicyConverter, String policyKey, String[] value);
+}
« no previous file with comments | « components/policy/android/BUILD.gn ('k') | components/policy/core/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698