| 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 CHROME_BROWSER_ANDROID_POLICY_POLICY_MANAGER_H_ | 
|   6 #define CHROME_BROWSER_ANDROID_POLICY_POLICY_MANAGER_H_ |   6 #define CHROME_BROWSER_ANDROID_POLICY_POLICY_MANAGER_H_ | 
|   7  |   7  | 
|   8 #include <jni.h> |   8 #include <jni.h> | 
|   9  |   9  | 
|  10 #include "base/android/jni_weak_ref.h" |  10 #include "base/android/jni_weak_ref.h" | 
|  11 #include "components/policy/core/common/policy_bundle.h" |  11 #include "base/macros.h" | 
 |  12 #include "base/memory/scoped_ptr.h" | 
|  12 #include "components/policy/core/common/policy_provider_android_delegate.h" |  13 #include "components/policy/core/common/policy_provider_android_delegate.h" | 
|  13  |  14  | 
|  14 namespace policy { |  15 namespace policy { | 
|  15  |  16  | 
|  16 class PolicyProviderAndroid; |  17 class PolicyProviderAndroid; | 
|  17 class Schema; |  | 
|  18  |  18  | 
 |  19 namespace android { | 
 |  20  | 
 |  21 class PolicyConverter; | 
 |  22  | 
 |  23 }  // namespace android | 
|  19 }  // namespace policy |  24 }  // namespace policy | 
|  20  |  25  | 
|  21 class PolicyManager : public policy::PolicyProviderAndroidDelegate { |  26 class PolicyManager : public policy::PolicyProviderAndroidDelegate { | 
|  22  public: |  27  public: | 
|  23   PolicyManager(JNIEnv* env, jobject obj); |  28   PolicyManager(JNIEnv* env, jobject obj); | 
|  24  |  29  | 
|  25   // Called from Java: |  | 
|  26   void SetPolicyBoolean(JNIEnv* env, |  | 
|  27                         jobject obj, |  | 
|  28                         jstring policyKey, |  | 
|  29                         jboolean value); |  | 
|  30   void SetPolicyInteger(JNIEnv* env, |  | 
|  31                         jobject obj, |  | 
|  32                         jstring policyKey, |  | 
|  33                         jint value); |  | 
|  34   void SetPolicyString(JNIEnv* env, |  | 
|  35                        jobject obj, |  | 
|  36                        jstring policyKey, |  | 
|  37                        jstring value); |  | 
|  38   void SetPolicyStringArray(JNIEnv* env, |  | 
|  39                             jobject obj, |  | 
|  40                             jstring policyKey, |  | 
|  41                             jobjectArray value); |  | 
|  42   void FlushPolicies(JNIEnv* env, jobject obj); |  30   void FlushPolicies(JNIEnv* env, jobject obj); | 
|  43  |  31  | 
|  44   void Destroy(JNIEnv* env, jobject obj); |  32   void Destroy(JNIEnv* env, jobject obj); | 
|  45  |  33  | 
|  46   // Converts the passed in value to the type desired by the schema. If the |  34   // Creates the native and java |PolicyConverter|, returns the reference to | 
|  47   // value is not convertible, it is returned unchanged, so the policy system |  35   // the java one. | 
|  48   // can report the error. |  36   base::android::ScopedJavaLocalRef<jobject> CreatePolicyConverter(JNIEnv* env, | 
|  49   // Note that this method will only look at the type of the schema, not at any |  37                                                                    jobject obj); | 
|  50   // additional restrictions, or the schema for value's items or properties in |  | 
|  51   // the case of a list or dictionary value. |  | 
|  52   // This method takes ownership of the passed in value, and the caller takes |  | 
|  53   // ownership of the return value. |  | 
|  54   // Public for testing. |  | 
|  55   static base::Value* ConvertValueToSchema(base::Value* raw_value, |  | 
|  56                                            const policy::Schema& schema); |  | 
|  57  |  38  | 
|  58   // PolicyProviderAndroidDelegate: |  39   // PolicyProviderAndroidDelegate: | 
|  59   void RefreshPolicies() override; |  40   void RefreshPolicies() override; | 
|  60   void PolicyProviderShutdown() override; |  41   void PolicyProviderShutdown() override; | 
|  61  |  42  | 
|  62  private: |  43  private: | 
|  63   ~PolicyManager() override; |  44   ~PolicyManager() override; | 
|  64  |  45  | 
|  65   JavaObjectWeakGlobalRef weak_java_policy_manager_; |  46   JavaObjectWeakGlobalRef weak_java_policy_manager_; | 
|  66  |  47  | 
|  67   scoped_ptr<policy::PolicyBundle> policy_bundle_; |  48   scoped_ptr<policy::android::PolicyConverter> policy_converter_; | 
|  68   policy::PolicyProviderAndroid* policy_provider_; |  49   policy::PolicyProviderAndroid* policy_provider_; | 
|  69  |  50  | 
|  70   void SetPolicyValue(const std::string& key, base::Value* value); |  | 
|  71  |  | 
|  72   DISALLOW_COPY_AND_ASSIGN(PolicyManager); |  51   DISALLOW_COPY_AND_ASSIGN(PolicyManager); | 
|  73 }; |  52 }; | 
|  74  |  53  | 
|  75 // Register native methods |  54 // Register native methods | 
|  76 bool RegisterPolicyManager(JNIEnv* env); |  55 bool RegisterPolicyManager(JNIEnv* env); | 
|  77  |  56  | 
|  78 #endif  // CHROME_BROWSER_ANDROID_POLICY_POLICY_MANAGER_H_ |  57 #endif  // CHROME_BROWSER_ANDROID_POLICY_POLICY_MANAGER_H_ | 
| OLD | NEW |