Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Unified Diff: components/policy/core/browser/android/policy_converter.h

Issue 1220683008: Move AppRestriction to Policy code out of //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DCHECKS to fail loudly in debug builds Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/policy/core/browser/android/policy_converter.h
diff --git a/components/policy/core/browser/android/policy_converter.h b/components/policy/core/browser/android/policy_converter.h
new file mode 100644
index 0000000000000000000000000000000000000000..a8d2d70a3daa6d1026147ee7b5d8b5d2f0729ad5
--- /dev/null
+++ b/components/policy/core/browser/android/policy_converter.h
@@ -0,0 +1,96 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H
+#define COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H
+
+#include <jni.h>
+#include <string>
+
+#include "base/android/scoped_java_ref.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "components/policy/policy_export.h"
+
+namespace base {
+
+class Value;
+class ListValue;
+
+} // namespace base
+
+namespace policy {
+
+class PolicyBundle;
+class Schema;
+
+namespace android {
+
+// Populates natives policies from Java key/value pairs. With its associated
+// java classes, allows transforming Android |Bundle|s into |PolicyBundle|s.
+class POLICY_EXPORT PolicyConverter {
+ public:
+ explicit PolicyConverter(const Schema* policy_schema);
+ ~PolicyConverter();
+
+ // Returns a policy bundle containing all policies collected since the last
+ // call to this method.
+ scoped_ptr<PolicyBundle> GetPolicyBundle();
+
+ base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
+
+ // To be called from Java:
+ void SetPolicyBoolean(JNIEnv* env,
+ jobject obj,
+ jstring policyKey,
+ jboolean value);
+ void SetPolicyInteger(JNIEnv* env,
+ jobject obj,
+ jstring policyKey,
+ jint value);
+ void SetPolicyString(JNIEnv* env,
+ jobject obj,
+ jstring policyKey,
+ jstring value);
+ void SetPolicyStringArray(JNIEnv* env,
+ jobject obj,
+ jstring policyKey,
+ jobjectArray value);
+
+ // Converts the passed in value to the type desired by the schema. If the
+ // value is not convertible, it is returned unchanged, so the policy system
+ // can report the error.
+ // Note that this method will only look at the type of the schema, not at any
+ // additional restrictions, or the schema for value's items or properties in
+ // the case of a list or dictionary value.
+ // Public for testing.
+ static scoped_ptr<base::Value> ConvertValueToSchema(
+ scoped_ptr<base::Value> value,
+ const Schema& schema);
+
+ // Public for testing.
+ static scoped_ptr<base::ListValue> ConvertJavaStringArrayToListValue(
+ JNIEnv* env,
+ jobjectArray array);
+
+ // Register native methods
+ static bool Register(JNIEnv* env);
+
+ private:
+ const Schema* const policy_schema_;
+
+ scoped_ptr<PolicyBundle> policy_bundle_;
+
+ base::android::ScopedJavaGlobalRef<jobject> java_obj_;
+
+ void SetPolicyValue(const std::string& key,
+ scoped_ptr<base::Value> raw_value);
+
+ DISALLOW_COPY_AND_ASSIGN(PolicyConverter);
+};
+
+} // namespace android
+} // namespace policy
+
+#endif // COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H

Powered by Google App Engine
This is Rietveld 408576698