| 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 #include "components/policy/core/browser/android/policy_converter.h" | 5 #include "components/policy/core/browser/android/policy_converter.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 base::android::ScopedJavaLocalRef<jobject> PolicyConverter::GetJavaObject() { | 51 base::android::ScopedJavaLocalRef<jobject> PolicyConverter::GetJavaObject() { |
| 52 return base::android::ScopedJavaLocalRef<jobject>(java_obj_); | 52 return base::android::ScopedJavaLocalRef<jobject>(java_obj_); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void PolicyConverter::SetPolicyBoolean(JNIEnv* env, | 55 void PolicyConverter::SetPolicyBoolean(JNIEnv* env, |
| 56 const JavaRef<jobject>& obj, | 56 const JavaRef<jobject>& obj, |
| 57 const JavaRef<jstring>& policyKey, | 57 const JavaRef<jstring>& policyKey, |
| 58 jboolean value) { | 58 jboolean value) { |
| 59 SetPolicyValue( | 59 SetPolicyValue( |
| 60 ConvertJavaStringToUTF8(env, policyKey), | 60 ConvertJavaStringToUTF8(env, policyKey), |
| 61 base::MakeUnique<base::FundamentalValue>(static_cast<bool>(value))); | 61 base::MakeUnique<base::Value>(static_cast<bool>(value))); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void PolicyConverter::SetPolicyInteger(JNIEnv* env, | 64 void PolicyConverter::SetPolicyInteger(JNIEnv* env, |
| 65 const JavaRef<jobject>& obj, | 65 const JavaRef<jobject>& obj, |
| 66 const JavaRef<jstring>& policyKey, | 66 const JavaRef<jstring>& policyKey, |
| 67 jint value) { | 67 jint value) { |
| 68 SetPolicyValue( | 68 SetPolicyValue( |
| 69 ConvertJavaStringToUTF8(env, policyKey), | 69 ConvertJavaStringToUTF8(env, policyKey), |
| 70 base::MakeUnique<base::FundamentalValue>(static_cast<int>(value))); | 70 base::MakeUnique<base::Value>(static_cast<int>(value))); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void PolicyConverter::SetPolicyString(JNIEnv* env, | 73 void PolicyConverter::SetPolicyString(JNIEnv* env, |
| 74 const JavaRef<jobject>& obj, | 74 const JavaRef<jobject>& obj, |
| 75 const JavaRef<jstring>& policyKey, | 75 const JavaRef<jstring>& policyKey, |
| 76 const JavaRef<jstring>& value) { | 76 const JavaRef<jstring>& value) { |
| 77 SetPolicyValue( | 77 SetPolicyValue( |
| 78 ConvertJavaStringToUTF8(env, policyKey), | 78 ConvertJavaStringToUTF8(env, policyKey), |
| 79 base::MakeUnique<base::StringValue>(ConvertJavaStringToUTF8(env, value))); | 79 base::MakeUnique<base::StringValue>(ConvertJavaStringToUTF8(env, value))); |
| 80 } | 80 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 return value; | 114 return value; |
| 115 | 115 |
| 116 switch (schema.type()) { | 116 switch (schema.type()) { |
| 117 case base::Value::TYPE_NULL: | 117 case base::Value::TYPE_NULL: |
| 118 return base::Value::CreateNullValue(); | 118 return base::Value::CreateNullValue(); |
| 119 | 119 |
| 120 case base::Value::TYPE_BOOLEAN: { | 120 case base::Value::TYPE_BOOLEAN: { |
| 121 std::string string_value; | 121 std::string string_value; |
| 122 if (value->GetAsString(&string_value)) { | 122 if (value->GetAsString(&string_value)) { |
| 123 if (string_value.compare("true") == 0) | 123 if (string_value.compare("true") == 0) |
| 124 return base::MakeUnique<base::FundamentalValue>(true); | 124 return base::MakeUnique<base::Value>(true); |
| 125 | 125 |
| 126 if (string_value.compare("false") == 0) | 126 if (string_value.compare("false") == 0) |
| 127 return base::MakeUnique<base::FundamentalValue>(false); | 127 return base::MakeUnique<base::Value>(false); |
| 128 | 128 |
| 129 return value; | 129 return value; |
| 130 } | 130 } |
| 131 int int_value = 0; | 131 int int_value = 0; |
| 132 if (value->GetAsInteger(&int_value)) | 132 if (value->GetAsInteger(&int_value)) |
| 133 return base::MakeUnique<base::FundamentalValue>(int_value != 0); | 133 return base::MakeUnique<base::Value>(int_value != 0); |
| 134 | 134 |
| 135 return value; | 135 return value; |
| 136 } | 136 } |
| 137 | 137 |
| 138 case base::Value::TYPE_INTEGER: { | 138 case base::Value::TYPE_INTEGER: { |
| 139 std::string string_value; | 139 std::string string_value; |
| 140 if (value->GetAsString(&string_value)) { | 140 if (value->GetAsString(&string_value)) { |
| 141 int int_value = 0; | 141 int int_value = 0; |
| 142 if (base::StringToInt(string_value, &int_value)) | 142 if (base::StringToInt(string_value, &int_value)) |
| 143 return base::MakeUnique<base::FundamentalValue>(int_value); | 143 return base::MakeUnique<base::Value>(int_value); |
| 144 } | 144 } |
| 145 return value; | 145 return value; |
| 146 } | 146 } |
| 147 | 147 |
| 148 case base::Value::TYPE_DOUBLE: { | 148 case base::Value::TYPE_DOUBLE: { |
| 149 std::string string_value; | 149 std::string string_value; |
| 150 if (value->GetAsString(&string_value)) { | 150 if (value->GetAsString(&string_value)) { |
| 151 double double_value = 0; | 151 double double_value = 0; |
| 152 if (base::StringToDouble(string_value, &double_value)) | 152 if (base::StringToDouble(string_value, &double_value)) |
| 153 return base::MakeUnique<base::FundamentalValue>(double_value); | 153 return base::MakeUnique<base::Value>(double_value); |
| 154 } | 154 } |
| 155 return value; | 155 return value; |
| 156 } | 156 } |
| 157 | 157 |
| 158 // String can't be converted from other types. | 158 // String can't be converted from other types. |
| 159 case base::Value::TYPE_STRING: { | 159 case base::Value::TYPE_STRING: { |
| 160 return value; | 160 return value; |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Binary is not a valid schema type. | 163 // Binary is not a valid schema type. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 193 std::unique_ptr<base::Value> value) { | 193 std::unique_ptr<base::Value> value) { |
| 194 const Schema schema = policy_schema_->GetKnownProperty(key); | 194 const Schema schema = policy_schema_->GetKnownProperty(key); |
| 195 const PolicyNamespace ns(POLICY_DOMAIN_CHROME, std::string()); | 195 const PolicyNamespace ns(POLICY_DOMAIN_CHROME, std::string()); |
| 196 policy_bundle_->Get(ns).Set( | 196 policy_bundle_->Get(ns).Set( |
| 197 key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, POLICY_SOURCE_PLATFORM, | 197 key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, POLICY_SOURCE_PLATFORM, |
| 198 ConvertValueToSchema(std::move(value), schema), nullptr); | 198 ConvertValueToSchema(std::move(value), schema), nullptr); |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace android | 201 } // namespace android |
| 202 } // namespace policy | 202 } // namespace policy |
| OLD | NEW |