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 | |
| 20 } // namespace base | |
| 21 | |
| 22 namespace policy { | |
| 23 | |
| 24 class PolicyBundle; | |
| 25 class PolicyProviderAndroid; | |
| 26 class Schema; | |
| 27 struct PolicyNamespace; | |
| 28 | |
| 29 namespace android { | |
| 30 | |
| 31 // Populates natives policies from Java values key/value pairs. With its | |
|
Mattias Nissler (ping if slow)
2015/07/13 09:46:05
nit: remove "values"
dgn
2015/07/14 12:50:26
Done.
| |
| 32 // associated java classes, allows transforming Android |Bundle|s into | |
| 33 // |PolicyBundle|s and updating the native policies. | |
|
Mattias Nissler (ping if slow)
2015/07/13 09:46:05
nit: I don't see how this class would "update the
dgn
2015/07/14 12:50:26
I forgot to remove this after moving FlushPolicies
| |
| 34 class POLICY_EXPORT PolicyConverter { | |
| 35 public: | |
| 36 explicit PolicyConverter(const Schema* policy_schema); | |
| 37 ~PolicyConverter(); | |
| 38 | |
| 39 // Returns a policy bundle containing all policies collected since the last | |
| 40 // call to this method. The caller gains ownership of the bundle. | |
|
Mattias Nissler (ping if slow)
2015/07/13 09:46:05
nit: Ownership comment is redundant with scoped_pt
dgn
2015/07/14 12:50:26
Done.
| |
| 41 scoped_ptr<PolicyBundle> GetPolicyBundle(); | |
| 42 | |
| 43 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); | |
| 44 | |
| 45 // To be called from Java: | |
| 46 void SetPolicyBoolean(JNIEnv* env, | |
| 47 jobject obj, | |
| 48 jstring policyKey, | |
| 49 jboolean value); | |
| 50 void SetPolicyInteger(JNIEnv* env, | |
| 51 jobject obj, | |
| 52 jstring policyKey, | |
| 53 jint value); | |
| 54 void SetPolicyString(JNIEnv* env, | |
| 55 jobject obj, | |
| 56 jstring policyKey, | |
| 57 jstring value); | |
| 58 void SetPolicyStringArray(JNIEnv* env, | |
| 59 jobject obj, | |
| 60 jstring policyKey, | |
| 61 jobjectArray value); | |
| 62 | |
| 63 // Converts the passed in value to the type desired by the schema. If the | |
| 64 // value is not convertible, it is returned unchanged, so the policy system | |
| 65 // can report the error. | |
| 66 // Note that this method will only look at the type of the schema, not at any | |
| 67 // additional restrictions, or the schema for value's items or properties in | |
| 68 // the case of a list or dictionary value. | |
| 69 // This method takes ownership of the passed in value, and the caller takes | |
| 70 // ownership of the return value. | |
| 71 // Public for testing. | |
| 72 static scoped_ptr<base::Value> ConvertValueToSchema( | |
| 73 scoped_ptr<base::Value> value, | |
| 74 const Schema& schema); | |
| 75 | |
| 76 // Register native methods | |
| 77 static bool Register(JNIEnv* env); | |
| 78 | |
| 79 private: | |
| 80 const Schema* const policy_schema_; | |
| 81 | |
| 82 scoped_ptr<PolicyBundle> policy_bundle_; | |
| 83 | |
| 84 base::android::ScopedJavaGlobalRef<jobject> java_obj_; | |
| 85 | |
| 86 void SetPolicyValue(const std::string& key, base::Value* raw_value); | |
|
Mattias Nissler (ping if slow)
2015/07/13 09:46:05
Should have a comment saying that it takes ownersh
dgn
2015/07/14 12:50:26
Done.
| |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(PolicyConverter); | |
| 89 }; | |
| 90 | |
| 91 } // namespace android | |
| 92 } // namespace policy | |
| 93 | |
| 94 #endif // COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H | |
| OLD | NEW |