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

Side by Side Diff: components/policy/core/browser/android/policy_converter.h

Issue 1902633006: Convert //components/policy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and use namespace alias Created 4 years, 8 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 unified diff | Download patch
OLDNEW
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 COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H 5 #ifndef COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H
6 #define COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H 6 #define COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H
7 7
8 #include <jni.h> 8 #include <jni.h>
9
10 #include <memory>
9 #include <string> 11 #include <string>
10 12
11 #include "base/android/scoped_java_ref.h" 13 #include "base/android/scoped_java_ref.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "components/policy/policy_export.h" 15 #include "components/policy/policy_export.h"
15 16
16 namespace base { 17 namespace base {
17 18
18 class Value; 19 class Value;
19 class ListValue; 20 class ListValue;
20 21
21 } // namespace base 22 } // namespace base
22 23
23 namespace policy { 24 namespace policy {
24 25
25 class PolicyBundle; 26 class PolicyBundle;
26 class Schema; 27 class Schema;
27 28
28 namespace android { 29 namespace android {
29 30
30 // Populates natives policies from Java key/value pairs. With its associated 31 // Populates natives policies from Java key/value pairs. With its associated
31 // java classes, allows transforming Android |Bundle|s into |PolicyBundle|s. 32 // java classes, allows transforming Android |Bundle|s into |PolicyBundle|s.
32 class POLICY_EXPORT PolicyConverter { 33 class POLICY_EXPORT PolicyConverter {
33 public: 34 public:
34 explicit PolicyConverter(const Schema* policy_schema); 35 explicit PolicyConverter(const Schema* policy_schema);
35 ~PolicyConverter(); 36 ~PolicyConverter();
36 37
37 // Returns a policy bundle containing all policies collected since the last 38 // Returns a policy bundle containing all policies collected since the last
38 // call to this method. 39 // call to this method.
39 scoped_ptr<PolicyBundle> GetPolicyBundle(); 40 std::unique_ptr<PolicyBundle> GetPolicyBundle();
40 41
41 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); 42 base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
42 43
43 // To be called from Java: 44 // To be called from Java:
44 void SetPolicyBoolean(JNIEnv* env, 45 void SetPolicyBoolean(JNIEnv* env,
45 const base::android::JavaRef<jobject>& obj, 46 const base::android::JavaRef<jobject>& obj,
46 const base::android::JavaRef<jstring>& policyKey, 47 const base::android::JavaRef<jstring>& policyKey,
47 jboolean value); 48 jboolean value);
48 void SetPolicyInteger(JNIEnv* env, 49 void SetPolicyInteger(JNIEnv* env,
49 const base::android::JavaRef<jobject>& obj, 50 const base::android::JavaRef<jobject>& obj,
50 const base::android::JavaRef<jstring>& policyKey, 51 const base::android::JavaRef<jstring>& policyKey,
51 jint value); 52 jint value);
52 void SetPolicyString(JNIEnv* env, 53 void SetPolicyString(JNIEnv* env,
53 const base::android::JavaRef<jobject>& obj, 54 const base::android::JavaRef<jobject>& obj,
54 const base::android::JavaRef<jstring>& policyKey, 55 const base::android::JavaRef<jstring>& policyKey,
55 const base::android::JavaRef<jstring>& value); 56 const base::android::JavaRef<jstring>& value);
56 void SetPolicyStringArray(JNIEnv* env, 57 void SetPolicyStringArray(JNIEnv* env,
57 const base::android::JavaRef<jobject>& obj, 58 const base::android::JavaRef<jobject>& obj,
58 const base::android::JavaRef<jstring>& policyKey, 59 const base::android::JavaRef<jstring>& policyKey,
59 const base::android::JavaRef<jobjectArray>& value); 60 const base::android::JavaRef<jobjectArray>& value);
60 61
61 // Converts the passed in value to the type desired by the schema. If the 62 // 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 // value is not convertible, it is returned unchanged, so the policy system
63 // can report the error. 64 // can report the error.
64 // Note that this method will only look at the type of the schema, not at any 65 // 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 // additional restrictions, or the schema for value's items or properties in
66 // the case of a list or dictionary value. 67 // the case of a list or dictionary value.
67 // Public for testing. 68 // Public for testing.
68 static scoped_ptr<base::Value> ConvertValueToSchema( 69 static std::unique_ptr<base::Value> ConvertValueToSchema(
69 scoped_ptr<base::Value> value, 70 std::unique_ptr<base::Value> value,
70 const Schema& schema); 71 const Schema& schema);
71 72
72 // Public for testing. 73 // Public for testing.
73 static scoped_ptr<base::ListValue> ConvertJavaStringArrayToListValue( 74 static std::unique_ptr<base::ListValue> ConvertJavaStringArrayToListValue(
74 JNIEnv* env, 75 JNIEnv* env,
75 const base::android::JavaRef<jobjectArray>& array); 76 const base::android::JavaRef<jobjectArray>& array);
76 77
77 // Register native methods 78 // Register native methods
78 static bool Register(JNIEnv* env); 79 static bool Register(JNIEnv* env);
79 80
80 private: 81 private:
81 const Schema* const policy_schema_; 82 const Schema* const policy_schema_;
82 83
83 scoped_ptr<PolicyBundle> policy_bundle_; 84 std::unique_ptr<PolicyBundle> policy_bundle_;
84 85
85 base::android::ScopedJavaGlobalRef<jobject> java_obj_; 86 base::android::ScopedJavaGlobalRef<jobject> java_obj_;
86 87
87 void SetPolicyValue(const std::string& key, 88 void SetPolicyValue(const std::string& key,
88 scoped_ptr<base::Value> raw_value); 89 std::unique_ptr<base::Value> raw_value);
89 90
90 DISALLOW_COPY_AND_ASSIGN(PolicyConverter); 91 DISALLOW_COPY_AND_ASSIGN(PolicyConverter);
91 }; 92 };
92 93
93 } // namespace android 94 } // namespace android
94 } // namespace policy 95 } // namespace policy
95 96
96 #endif // COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H 97 #endif // COMPONENTS_POLICY_CORE_BROWSER_ANDROID_POLICY_CONVERTER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698