cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / components / policy / core / browser / android / policy_converter.h
bloba8d2d70a3daa6d1026147ee7b5d8b5d2f0729ad5
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
8 #include <jni.h>
9 #include <string>
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"
16 namespace base {
18 class Value;
19 class ListValue;
21 } // namespace base
23 namespace policy {
25 class PolicyBundle;
26 class Schema;
28 namespace android {
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();
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,
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);
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(
74 JNIEnv* env,
75 jobjectArray array);
77 // Register native methods
78 static bool Register(JNIEnv* env);
80 private:
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
94 } // namespace policy
96 #endif // COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H