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.
5 #ifndef COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H
6 #define COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H
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"
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
{
34 explicit PolicyConverter(const Schema
* policy_schema
);
37 // Returns a policy bundle containing all policies collected since the last
38 // call to this method.
39 scoped_ptr
<PolicyBundle
> GetPolicyBundle();
41 base::android::ScopedJavaLocalRef
<jobject
> GetJavaObject();
43 // To be called from Java:
44 void SetPolicyBoolean(JNIEnv
* env
,
48 void SetPolicyInteger(JNIEnv
* env
,
52 void SetPolicyString(JNIEnv
* env
,
56 void SetPolicyStringArray(JNIEnv
* env
,
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
);
72 // Public for testing.
73 static scoped_ptr
<base::ListValue
> ConvertJavaStringArrayToListValue(
77 // Register native methods
78 static bool Register(JNIEnv
* env
);
81 const Schema
* const policy_schema_
;
83 scoped_ptr
<PolicyBundle
> policy_bundle_
;
85 base::android::ScopedJavaGlobalRef
<jobject
> java_obj_
;
87 void SetPolicyValue(const std::string
& key
,
88 scoped_ptr
<base::Value
> raw_value
);
90 DISALLOW_COPY_AND_ASSIGN(PolicyConverter
);
93 } // namespace android
96 #endif // COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H