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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 | 108 |
109 // static | 109 // static |
110 std::unique_ptr<base::Value> PolicyConverter::ConvertValueToSchema( | 110 std::unique_ptr<base::Value> PolicyConverter::ConvertValueToSchema( |
111 std::unique_ptr<base::Value> value, | 111 std::unique_ptr<base::Value> value, |
112 const Schema& schema) { | 112 const Schema& schema) { |
113 if (!schema.valid()) | 113 if (!schema.valid()) |
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::NONE: |
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::FundamentalValue>(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::FundamentalValue>(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::FundamentalValue>(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::FundamentalValue>(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::FundamentalValue>(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. |
164 case base::Value::TYPE_BINARY: { | 164 case base::Value::Type::BINARY: { |
165 NOTREACHED(); | 165 NOTREACHED(); |
166 return std::unique_ptr<base::Value>(); | 166 return std::unique_ptr<base::Value>(); |
167 } | 167 } |
168 | 168 |
169 // Complex types have to be deserialized from JSON. | 169 // Complex types have to be deserialized from JSON. |
170 case base::Value::TYPE_DICTIONARY: | 170 case base::Value::Type::DICTIONARY: |
171 case base::Value::TYPE_LIST: { | 171 case base::Value::Type::LIST: { |
172 std::string string_value; | 172 std::string string_value; |
173 if (value->GetAsString(&string_value)) { | 173 if (value->GetAsString(&string_value)) { |
174 std::unique_ptr<base::Value> decoded_value = | 174 std::unique_ptr<base::Value> decoded_value = |
175 base::JSONReader::Read(string_value); | 175 base::JSONReader::Read(string_value); |
176 if (decoded_value) | 176 if (decoded_value) |
177 return decoded_value; | 177 return decoded_value; |
178 } | 178 } |
179 return value; | 179 return value; |
180 } | 180 } |
181 } | 181 } |
(...skipping 11 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 |