Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_POLICY_POLICY_MANAGER_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H |
| 6 #define CHROME_BROWSER_ANDROID_POLICY_POLICY_MANAGER_H_ | 6 #define COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <string> | |
| 9 | 10 |
| 10 #include "base/android/jni_weak_ref.h" | 11 #include "base/android/jni_weak_ref.h" |
| 11 #include "components/policy/core/common/policy_bundle.h" | 12 #include "base/android/scoped_java_ref.h" |
| 12 #include "components/policy/core/common/policy_provider_android_delegate.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "components/policy/policy_export.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class Value; | |
| 19 } | |
| 13 | 20 |
| 14 namespace policy { | 21 namespace policy { |
| 15 | 22 |
| 23 class PolicyBundle; | |
| 16 class PolicyProviderAndroid; | 24 class PolicyProviderAndroid; |
| 17 class Schema; | 25 class Schema; |
| 26 struct PolicyNamespace; | |
| 18 | 27 |
| 19 } // namespace policy | 28 // Populates natives policies from Java values key/value pairs. With its |
|
Bernhard Bauer
2015/07/09 08:53:58
I would move this into the android namespace, and
dgn
2015/07/09 10:53:41
Done. Also moved the methods around to have a cons
| |
| 29 // associated java classes, allows transforming Android |Bundle|s into | |
| 30 // |PolicyBundle|s and updating the native policies. | |
| 31 class POLICY_EXPORT PolicyConverter { | |
| 32 public: | |
| 33 PolicyConverter(const Schema* policy_schema); | |
|
Bernhard Bauer
2015/07/09 08:53:58
Single-argument constructors should be marked expl
dgn
2015/07/09 10:53:41
Done.
| |
| 34 ~PolicyConverter(); | |
| 20 | 35 |
| 21 class PolicyManager : public policy::PolicyProviderAndroidDelegate { | 36 // To be called from Java: |
| 22 public: | |
| 23 PolicyManager(JNIEnv* env, jobject obj); | |
| 24 | |
| 25 // Called from Java: | |
| 26 void SetPolicyBoolean(JNIEnv* env, | 37 void SetPolicyBoolean(JNIEnv* env, |
| 27 jobject obj, | 38 jobject obj, |
| 28 jstring policyKey, | 39 jstring policyKey, |
| 29 jboolean value); | 40 jboolean value); |
| 30 void SetPolicyInteger(JNIEnv* env, | 41 void SetPolicyInteger(JNIEnv* env, |
| 31 jobject obj, | 42 jobject obj, |
| 32 jstring policyKey, | 43 jstring policyKey, |
| 33 jint value); | 44 jint value); |
| 34 void SetPolicyString(JNIEnv* env, | 45 void SetPolicyString(JNIEnv* env, |
| 35 jobject obj, | 46 jobject obj, |
| 36 jstring policyKey, | 47 jstring policyKey, |
| 37 jstring value); | 48 jstring value); |
| 38 void SetPolicyStringArray(JNIEnv* env, | 49 void SetPolicyStringArray(JNIEnv* env, |
| 39 jobject obj, | 50 jobject obj, |
| 40 jstring policyKey, | 51 jstring policyKey, |
| 41 jobjectArray value); | 52 jobjectArray value); |
| 42 void FlushPolicies(JNIEnv* env, jobject obj); | |
| 43 | 53 |
| 44 void Destroy(JNIEnv* env, jobject obj); | 54 // Returns a policy bundle containing all policies collected since the last |
| 55 // call to this method. The caller gains ownership of the bundle. | |
| 56 scoped_ptr<PolicyBundle> GetPolicyBundle(); | |
| 57 | |
| 58 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); | |
| 45 | 59 |
| 46 // Converts the passed in value to the type desired by the schema. If the | 60 // Converts the passed in value to the type desired by the schema. If the |
| 47 // value is not convertible, it is returned unchanged, so the policy system | 61 // value is not convertible, it is returned unchanged, so the policy system |
| 48 // can report the error. | 62 // can report the error. |
| 49 // Note that this method will only look at the type of the schema, not at any | 63 // Note that this method will only look at the type of the schema, not at any |
| 50 // additional restrictions, or the schema for value's items or properties in | 64 // additional restrictions, or the schema for value's items or properties in |
| 51 // the case of a list or dictionary value. | 65 // the case of a list or dictionary value. |
| 52 // This method takes ownership of the passed in value, and the caller takes | 66 // This method takes ownership of the passed in value, and the caller takes |
| 53 // ownership of the return value. | 67 // ownership of the return value. |
| 54 // Public for testing. | 68 // Public for testing. |
| 55 static base::Value* ConvertValueToSchema(base::Value* raw_value, | 69 static scoped_ptr<base::Value> ConvertValueToSchema( |
| 56 const policy::Schema& schema); | 70 scoped_ptr<base::Value> value, |
| 57 | 71 const Schema& schema); |
| 58 // PolicyProviderAndroidDelegate: | |
| 59 void RefreshPolicies() override; | |
| 60 void PolicyProviderShutdown() override; | |
| 61 | 72 |
| 62 private: | 73 private: |
| 63 ~PolicyManager() override; | 74 const Schema* const policy_schema_; |
| 64 | 75 |
| 65 JavaObjectWeakGlobalRef weak_java_policy_manager_; | 76 scoped_ptr<PolicyBundle> policy_bundle_; |
| 66 | 77 |
| 67 scoped_ptr<policy::PolicyBundle> policy_bundle_; | 78 JavaObjectWeakGlobalRef weak_java_obj_; |
|
Bernhard Bauer
2015/07/09 08:53:58
Make this a strong reference? I'm a bit worried ab
dgn
2015/07/09 10:53:41
Done.
| |
| 68 policy::PolicyProviderAndroid* policy_provider_; | |
| 69 | 79 |
| 70 void SetPolicyValue(const std::string& key, base::Value* value); | 80 void SetPolicyValue(const std::string& key, base::Value* raw_value); |
| 71 | 81 |
| 72 DISALLOW_COPY_AND_ASSIGN(PolicyManager); | 82 DISALLOW_COPY_AND_ASSIGN(PolicyConverter); |
| 73 }; | 83 }; |
| 74 | 84 |
| 85 namespace android { | |
| 86 | |
| 75 // Register native methods | 87 // Register native methods |
| 76 bool RegisterPolicyManager(JNIEnv* env); | 88 bool RegisterPolicyConverter(JNIEnv* env); |
| 77 | 89 |
| 78 #endif // CHROME_BROWSER_ANDROID_POLICY_POLICY_MANAGER_H_ | 90 } // namespace android |
| 91 | |
| 92 } // namespace policy | |
| 93 | |
| 94 #endif // COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H | |
| OLD | NEW |