OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/common/registry_dict.h" | 5 #include "components/policy/core/common/registry_dict.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 switch (schema.type()) { | 77 switch (schema.type()) { |
78 case base::Value::TYPE_NULL: { | 78 case base::Value::TYPE_NULL: { |
79 return base::Value::CreateNullValue(); | 79 return base::Value::CreateNullValue(); |
80 } | 80 } |
81 case base::Value::TYPE_BOOLEAN: { | 81 case base::Value::TYPE_BOOLEAN: { |
82 // Accept booleans encoded as either string or integer. | 82 // Accept booleans encoded as either string or integer. |
83 if (value.GetAsInteger(&int_value) || | 83 if (value.GetAsInteger(&int_value) || |
84 (value.GetAsString(&string_value) && | 84 (value.GetAsString(&string_value) && |
85 base::StringToInt(string_value, &int_value))) { | 85 base::StringToInt(string_value, &int_value))) { |
86 return std::unique_ptr<base::Value>( | 86 return std::unique_ptr<base::Value>( |
87 new base::FundamentalValue(int_value != 0)); | 87 new base::Value(int_value != 0)); |
88 } | 88 } |
89 break; | 89 break; |
90 } | 90 } |
91 case base::Value::TYPE_INTEGER: { | 91 case base::Value::TYPE_INTEGER: { |
92 // Integers may be string-encoded. | 92 // Integers may be string-encoded. |
93 if (value.GetAsString(&string_value) && | 93 if (value.GetAsString(&string_value) && |
94 base::StringToInt(string_value, &int_value)) { | 94 base::StringToInt(string_value, &int_value)) { |
95 return std::unique_ptr<base::Value>( | 95 return std::unique_ptr<base::Value>( |
96 new base::FundamentalValue(int_value)); | 96 new base::Value(int_value)); |
97 } | 97 } |
98 break; | 98 break; |
99 } | 99 } |
100 case base::Value::TYPE_DOUBLE: { | 100 case base::Value::TYPE_DOUBLE: { |
101 // Doubles may be string-encoded or integer-encoded. | 101 // Doubles may be string-encoded or integer-encoded. |
102 double double_value = 0; | 102 double double_value = 0; |
103 if (value.GetAsDouble(&double_value) || | 103 if (value.GetAsDouble(&double_value) || |
104 (value.GetAsString(&string_value) && | 104 (value.GetAsString(&string_value) && |
105 base::StringToDouble(string_value, &double_value))) { | 105 base::StringToDouble(string_value, &double_value))) { |
106 return std::unique_ptr<base::Value>( | 106 return std::unique_ptr<base::Value>( |
107 new base::FundamentalValue(double_value)); | 107 new base::Value(double_value)); |
108 } | 108 } |
109 break; | 109 break; |
110 } | 110 } |
111 case base::Value::TYPE_LIST: { | 111 case base::Value::TYPE_LIST: { |
112 // Lists are encoded as subkeys with numbered value in the registry | 112 // Lists are encoded as subkeys with numbered value in the registry |
113 // (non-numerical keys are ignored). | 113 // (non-numerical keys are ignored). |
114 const base::DictionaryValue* dict = nullptr; | 114 const base::DictionaryValue* dict = nullptr; |
115 if (value.GetAsDictionary(&dict)) { | 115 if (value.GetAsDictionary(&dict)) { |
116 std::unique_ptr<base::ListValue> result(new base::ListValue()); | 116 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
117 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); | 117 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 continue; | 268 continue; |
269 case REG_DWORD_LITTLE_ENDIAN: | 269 case REG_DWORD_LITTLE_ENDIAN: |
270 case REG_DWORD_BIG_ENDIAN: | 270 case REG_DWORD_BIG_ENDIAN: |
271 if (it.ValueSize() == sizeof(DWORD)) { | 271 if (it.ValueSize() == sizeof(DWORD)) { |
272 DWORD dword_value = *(reinterpret_cast<const DWORD*>(it.Value())); | 272 DWORD dword_value = *(reinterpret_cast<const DWORD*>(it.Value())); |
273 if (it.Type() == REG_DWORD_BIG_ENDIAN) | 273 if (it.Type() == REG_DWORD_BIG_ENDIAN) |
274 dword_value = base::NetToHost32(dword_value); | 274 dword_value = base::NetToHost32(dword_value); |
275 else | 275 else |
276 dword_value = base::ByteSwapToLE32(dword_value); | 276 dword_value = base::ByteSwapToLE32(dword_value); |
277 SetValue(name, | 277 SetValue(name, |
278 std::unique_ptr<base::Value>(new base::FundamentalValue( | 278 std::unique_ptr<base::Value>(new base::Value( |
279 static_cast<int>(dword_value)))); | 279 static_cast<int>(dword_value)))); |
280 continue; | 280 continue; |
281 } | 281 } |
282 case REG_NONE: | 282 case REG_NONE: |
283 case REG_LINK: | 283 case REG_LINK: |
284 case REG_MULTI_SZ: | 284 case REG_MULTI_SZ: |
285 case REG_RESOURCE_LIST: | 285 case REG_RESOURCE_LIST: |
286 case REG_FULL_RESOURCE_DESCRIPTOR: | 286 case REG_FULL_RESOURCE_DESCRIPTOR: |
287 case REG_RESOURCE_REQUIREMENTS_LIST: | 287 case REG_RESOURCE_REQUIREMENTS_LIST: |
288 case REG_QWORD_LITTLE_ENDIAN: | 288 case REG_QWORD_LITTLE_ENDIAN: |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 return std::move(result); | 356 return std::move(result); |
357 } | 357 } |
358 default: | 358 default: |
359 LOG(WARNING) << "Can't convert registry key to schema type " << type; | 359 LOG(WARNING) << "Can't convert registry key to schema type " << type; |
360 } | 360 } |
361 | 361 |
362 return nullptr; | 362 return nullptr; |
363 } | 363 } |
364 #endif // #if defined(OS_WIN) | 364 #endif // #if defined(OS_WIN) |
365 } // namespace policy | 365 } // namespace policy |
OLD | NEW |