Chromium Code Reviews| 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 // Returns an empty ListValue in if there is a problem with the input array. | |
|
Bernhard Bauer
2015/07/14 13:24:14
What problem would that be? In general, it would b
dgn
2015/07/14 15:56:52
I looked at base/jni_string.h's behaviour, but fun
| |
| 74 static scoped_ptr<base::ListValue> ConvertJavaStringArrayToListValue( | |
| 75 JNIEnv* env, | |
| 76 jobjectArray array); | |
| 77 | |
| 78 // Register native methods | |
| 79 static bool Register(JNIEnv* env); | |
| 80 | |
| 81 private: | |
| 82 const Schema* const policy_schema_; | |
| 83 | |
| 84 scoped_ptr<PolicyBundle> policy_bundle_; | |
| 85 | |
| 86 base::android::ScopedJavaGlobalRef<jobject> java_obj_; | |
| 87 | |
| 88 void SetPolicyValue(const std::string& key, | |
| 89 scoped_ptr<base::Value> raw_value); | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(PolicyConverter); | |
| 92 }; | |
| 93 | |
| 94 } // namespace android | |
| 95 } // namespace policy | |
| 96 | |
| 97 #endif // COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H | |
| OLD | NEW |