| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 int int_value = 0; | 76 int int_value = 0; |
| 77 switch (schema.type()) { | 77 switch (schema.type()) { |
| 78 case base::Value::Type::NONE: { | 78 case base::Value::Type::NONE: { |
| 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>(new base::Value(int_value != 0)); |
| 87 new base::FundamentalValue(int_value != 0)); | |
| 88 } | 87 } |
| 89 break; | 88 break; |
| 90 } | 89 } |
| 91 case base::Value::Type::INTEGER: { | 90 case base::Value::Type::INTEGER: { |
| 92 // Integers may be string-encoded. | 91 // Integers may be string-encoded. |
| 93 if (value.GetAsString(&string_value) && | 92 if (value.GetAsString(&string_value) && |
| 94 base::StringToInt(string_value, &int_value)) { | 93 base::StringToInt(string_value, &int_value)) { |
| 95 return std::unique_ptr<base::Value>( | 94 return std::unique_ptr<base::Value>(new base::Value(int_value)); |
| 96 new base::FundamentalValue(int_value)); | |
| 97 } | 95 } |
| 98 break; | 96 break; |
| 99 } | 97 } |
| 100 case base::Value::Type::DOUBLE: { | 98 case base::Value::Type::DOUBLE: { |
| 101 // Doubles may be string-encoded or integer-encoded. | 99 // Doubles may be string-encoded or integer-encoded. |
| 102 double double_value = 0; | 100 double double_value = 0; |
| 103 if (value.GetAsDouble(&double_value) || | 101 if (value.GetAsDouble(&double_value) || |
| 104 (value.GetAsString(&string_value) && | 102 (value.GetAsString(&string_value) && |
| 105 base::StringToDouble(string_value, &double_value))) { | 103 base::StringToDouble(string_value, &double_value))) { |
| 106 return std::unique_ptr<base::Value>( | 104 return std::unique_ptr<base::Value>(new base::Value(double_value)); |
| 107 new base::FundamentalValue(double_value)); | |
| 108 } | 105 } |
| 109 break; | 106 break; |
| 110 } | 107 } |
| 111 case base::Value::Type::LIST: { | 108 case base::Value::Type::LIST: { |
| 112 // Lists are encoded as subkeys with numbered value in the registry | 109 // Lists are encoded as subkeys with numbered value in the registry |
| 113 // (non-numerical keys are ignored). | 110 // (non-numerical keys are ignored). |
| 114 const base::DictionaryValue* dict = nullptr; | 111 const base::DictionaryValue* dict = nullptr; |
| 115 if (value.GetAsDictionary(&dict)) { | 112 if (value.GetAsDictionary(&dict)) { |
| 116 std::unique_ptr<base::ListValue> result(new base::ListValue()); | 113 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
| 117 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); | 114 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 base::UTF16ToUTF8(it.Value())))); | 264 base::UTF16ToUTF8(it.Value())))); |
| 268 continue; | 265 continue; |
| 269 case REG_DWORD_LITTLE_ENDIAN: | 266 case REG_DWORD_LITTLE_ENDIAN: |
| 270 case REG_DWORD_BIG_ENDIAN: | 267 case REG_DWORD_BIG_ENDIAN: |
| 271 if (it.ValueSize() == sizeof(DWORD)) { | 268 if (it.ValueSize() == sizeof(DWORD)) { |
| 272 DWORD dword_value = *(reinterpret_cast<const DWORD*>(it.Value())); | 269 DWORD dword_value = *(reinterpret_cast<const DWORD*>(it.Value())); |
| 273 if (it.Type() == REG_DWORD_BIG_ENDIAN) | 270 if (it.Type() == REG_DWORD_BIG_ENDIAN) |
| 274 dword_value = base::NetToHost32(dword_value); | 271 dword_value = base::NetToHost32(dword_value); |
| 275 else | 272 else |
| 276 dword_value = base::ByteSwapToLE32(dword_value); | 273 dword_value = base::ByteSwapToLE32(dword_value); |
| 277 SetValue(name, | 274 SetValue(name, std::unique_ptr<base::Value>( |
| 278 std::unique_ptr<base::Value>(new base::FundamentalValue( | 275 new base::Value(static_cast<int>(dword_value)))); |
| 279 static_cast<int>(dword_value)))); | |
| 280 continue; | 276 continue; |
| 281 } | 277 } |
| 282 case REG_NONE: | 278 case REG_NONE: |
| 283 case REG_LINK: | 279 case REG_LINK: |
| 284 case REG_MULTI_SZ: | 280 case REG_MULTI_SZ: |
| 285 case REG_RESOURCE_LIST: | 281 case REG_RESOURCE_LIST: |
| 286 case REG_FULL_RESOURCE_DESCRIPTOR: | 282 case REG_FULL_RESOURCE_DESCRIPTOR: |
| 287 case REG_RESOURCE_REQUIREMENTS_LIST: | 283 case REG_RESOURCE_REQUIREMENTS_LIST: |
| 288 case REG_QWORD_LITTLE_ENDIAN: | 284 case REG_QWORD_LITTLE_ENDIAN: |
| 289 // Unsupported type, message gets logged below. | 285 // Unsupported type, message gets logged below. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 return std::move(result); | 352 return std::move(result); |
| 357 } | 353 } |
| 358 default: | 354 default: |
| 359 LOG(WARNING) << "Can't convert registry key to schema type " << type; | 355 LOG(WARNING) << "Can't convert registry key to schema type " << type; |
| 360 } | 356 } |
| 361 | 357 |
| 362 return nullptr; | 358 return nullptr; |
| 363 } | 359 } |
| 364 #endif // #if defined(OS_WIN) | 360 #endif // #if defined(OS_WIN) |
| 365 } // namespace policy | 361 } // namespace policy |
| OLD | NEW |