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

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: Removed the Delegate, reworked the relationship between classes 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
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..baf05b501203f01aaf5ddf045bd8892007471e91
--- /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")
+public class PolicyConverter {
+ private long mNativePolicyConverter = 0;
Bernhard Bauer 2015/07/09 08:53:58 You can remove the default value.
dgn 2015/07/09 10:53:41 Done.
+
+ 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);
+}

Powered by Google App Engine
This is Rietveld 408576698