| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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 #ifndef COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H |
| 6 #define COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H |
| 7 |
| 8 #include <jni.h> |
| 9 #include <string> |
| 10 |
| 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "components/policy/policy_export.h" |
| 15 |
| 16 namespace base { |
| 17 |
| 18 class Value; |
| 19 class ListValue; |
| 20 |
| 21 } // namespace base |
| 22 |
| 23 namespace policy { |
| 24 |
| 25 class PolicyBundle; |
| 26 class Schema; |
| 27 |
| 28 namespace android { |
| 29 |
| 30 // Populates natives policies from Java key/value pairs. With its associated |
| 31 // java classes, allows transforming Android |Bundle|s into |PolicyBundle|s. |
| 32 class POLICY_EXPORT PolicyConverter { |
| 33 public: |
| 34 explicit PolicyConverter(const Schema* policy_schema); |
| 35 ~PolicyConverter(); |
| 36 |
| 37 // Returns a policy bundle containing all policies collected since the last |
| 38 // call to this method. |
| 39 scoped_ptr<PolicyBundle> GetPolicyBundle(); |
| 40 |
| 41 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); |
| 42 |
| 43 // To be called from Java: |
| 44 void SetPolicyBoolean(JNIEnv* env, |
| 45 jobject obj, |
| 46 jstring policyKey, |
| 47 jboolean value); |
| 48 void SetPolicyInteger(JNIEnv* env, |
| 49 jobject obj, |
| 50 jstring policyKey, |
| 51 jint value); |
| 52 void SetPolicyString(JNIEnv* env, |
| 53 jobject obj, |
| 54 jstring policyKey, |
| 55 jstring value); |
| 56 void SetPolicyStringArray(JNIEnv* env, |
| 57 jobject obj, |
| 58 jstring policyKey, |
| 59 jobjectArray value); |
| 60 |
| 61 // Converts the passed in value to the type desired by the schema. If the |
| 62 // value is not convertible, it is returned unchanged, so the policy system |
| 63 // can report the error. |
| 64 // Note that this method will only look at the type of the schema, not at any |
| 65 // additional restrictions, or the schema for value's items or properties in |
| 66 // the case of a list or dictionary value. |
| 67 // Public for testing. |
| 68 static scoped_ptr<base::Value> ConvertValueToSchema( |
| 69 scoped_ptr<base::Value> value, |
| 70 const Schema& schema); |
| 71 |
| 72 // Public for testing. |
| 73 static scoped_ptr<base::ListValue> ConvertJavaStringArrayToListValue( |
| 74 JNIEnv* env, |
| 75 jobjectArray array); |
| 76 |
| 77 // Register native methods |
| 78 static bool Register(JNIEnv* env); |
| 79 |
| 80 private: |
| 81 const Schema* const policy_schema_; |
| 82 |
| 83 scoped_ptr<PolicyBundle> policy_bundle_; |
| 84 |
| 85 base::android::ScopedJavaGlobalRef<jobject> java_obj_; |
| 86 |
| 87 void SetPolicyValue(const std::string& key, |
| 88 scoped_ptr<base::Value> raw_value); |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(PolicyConverter); |
| 91 }; |
| 92 |
| 93 } // namespace android |
| 94 } // namespace policy |
| 95 |
| 96 #endif // COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H |
| OLD | NEW |