| 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_win.h" | 5 #include "components/policy/core/common/registry_dict_win.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 const base::ListValue* list = NULL; | 36 const base::ListValue* list = NULL; |
| 37 if (value.GetAsDictionary(&dict)) { | 37 if (value.GetAsDictionary(&dict)) { |
| 38 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 38 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 39 for (base::DictionaryValue::Iterator entry(*dict); !entry.IsAtEnd(); | 39 for (base::DictionaryValue::Iterator entry(*dict); !entry.IsAtEnd(); |
| 40 entry.Advance()) { | 40 entry.Advance()) { |
| 41 scoped_ptr<base::Value> converted = | 41 scoped_ptr<base::Value> converted = |
| 42 ConvertValue(entry.value(), schema.GetProperty(entry.key())); | 42 ConvertValue(entry.value(), schema.GetProperty(entry.key())); |
| 43 if (converted) | 43 if (converted) |
| 44 result->SetWithoutPathExpansion(entry.key(), converted.release()); | 44 result->SetWithoutPathExpansion(entry.key(), converted.release()); |
| 45 } | 45 } |
| 46 return result.PassAs<base::Value>(); | 46 return result.Pass(); |
| 47 } else if (value.GetAsList(&list)) { | 47 } else if (value.GetAsList(&list)) { |
| 48 scoped_ptr<base::ListValue> result(new base::ListValue()); | 48 scoped_ptr<base::ListValue> result(new base::ListValue()); |
| 49 for (base::ListValue::const_iterator entry(list->begin()); | 49 for (base::ListValue::const_iterator entry(list->begin()); |
| 50 entry != list->end(); ++entry) { | 50 entry != list->end(); ++entry) { |
| 51 scoped_ptr<base::Value> converted = | 51 scoped_ptr<base::Value> converted = |
| 52 ConvertValue(**entry, schema.GetItems()); | 52 ConvertValue(**entry, schema.GetItems()); |
| 53 if (converted) | 53 if (converted) |
| 54 result->Append(converted.release()); | 54 result->Append(converted.release()); |
| 55 } | 55 } |
| 56 return result.PassAs<base::Value>(); | 56 return result.PassAs<base::Value>(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 break; | 122 break; |
| 123 } | 123 } |
| 124 case base::Value::TYPE_STRING: | 124 case base::Value::TYPE_STRING: |
| 125 case base::Value::TYPE_BINARY: | 125 case base::Value::TYPE_BINARY: |
| 126 // No conversion possible. | 126 // No conversion possible. |
| 127 break; | 127 break; |
| 128 } | 128 } |
| 129 | 129 |
| 130 LOG(WARNING) << "Failed to convert " << value.GetType() | 130 LOG(WARNING) << "Failed to convert " << value.GetType() |
| 131 << " to " << schema.type(); | 131 << " to " << schema.type(); |
| 132 return scoped_ptr<base::Value>(); | 132 return nullptr; |
| 133 } | 133 } |
| 134 | 134 |
| 135 } // namespace | 135 } // namespace |
| 136 | 136 |
| 137 bool CaseInsensitiveStringCompare::operator()(const std::string& a, | 137 bool CaseInsensitiveStringCompare::operator()(const std::string& a, |
| 138 const std::string& b) const { | 138 const std::string& b) const { |
| 139 return base::strcasecmp(a.c_str(), b.c_str()) < 0; | 139 return base::strcasecmp(a.c_str(), b.c_str()) < 0; |
| 140 } | 140 } |
| 141 | 141 |
| 142 RegistryDict::RegistryDict() {} | 142 RegistryDict::RegistryDict() {} |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 308 } |
| 309 for (RegistryDict::KeyMap::const_iterator entry(keys_.begin()); | 309 for (RegistryDict::KeyMap::const_iterator entry(keys_.begin()); |
| 310 entry != keys_.end(); ++entry) { | 310 entry != keys_.end(); ++entry) { |
| 311 Schema subschema = | 311 Schema subschema = |
| 312 schema.valid() ? schema.GetProperty(entry->first) : Schema(); | 312 schema.valid() ? schema.GetProperty(entry->first) : Schema(); |
| 313 scoped_ptr<base::Value> converted = | 313 scoped_ptr<base::Value> converted = |
| 314 entry->second->ConvertToJSON(subschema); | 314 entry->second->ConvertToJSON(subschema); |
| 315 if (converted) | 315 if (converted) |
| 316 result->SetWithoutPathExpansion(entry->first, converted.release()); | 316 result->SetWithoutPathExpansion(entry->first, converted.release()); |
| 317 } | 317 } |
| 318 return result.PassAs<base::Value>(); | 318 return result.Pass(); |
| 319 } | 319 } |
| 320 case base::Value::TYPE_LIST: { | 320 case base::Value::TYPE_LIST: { |
| 321 scoped_ptr<base::ListValue> result(new base::ListValue()); | 321 scoped_ptr<base::ListValue> result(new base::ListValue()); |
| 322 Schema item_schema = schema.valid() ? schema.GetItems() : Schema(); | 322 Schema item_schema = schema.valid() ? schema.GetItems() : Schema(); |
| 323 for (int i = 1; ; ++i) { | 323 for (int i = 1; ; ++i) { |
| 324 const std::string name(base::IntToString(i)); | 324 const std::string name(base::IntToString(i)); |
| 325 const RegistryDict* key = GetKey(name); | 325 const RegistryDict* key = GetKey(name); |
| 326 if (key) { | 326 if (key) { |
| 327 scoped_ptr<base::Value> converted = key->ConvertToJSON(item_schema); | 327 scoped_ptr<base::Value> converted = key->ConvertToJSON(item_schema); |
| 328 if (converted) | 328 if (converted) |
| 329 result->Append(converted.release()); | 329 result->Append(converted.release()); |
| 330 continue; | 330 continue; |
| 331 } | 331 } |
| 332 const base::Value* value = GetValue(name); | 332 const base::Value* value = GetValue(name); |
| 333 if (value) { | 333 if (value) { |
| 334 scoped_ptr<base::Value> converted = ConvertValue(*value, item_schema); | 334 scoped_ptr<base::Value> converted = ConvertValue(*value, item_schema); |
| 335 if (converted) | 335 if (converted) |
| 336 result->Append(converted.release()); | 336 result->Append(converted.release()); |
| 337 continue; | 337 continue; |
| 338 } | 338 } |
| 339 break; | 339 break; |
| 340 } | 340 } |
| 341 return result.PassAs<base::Value>(); | 341 return result.Pass(); |
| 342 } | 342 } |
| 343 default: | 343 default: |
| 344 LOG(WARNING) << "Can't convert registry key to schema type " << type; | 344 LOG(WARNING) << "Can't convert registry key to schema type " << type; |
| 345 } | 345 } |
| 346 | 346 |
| 347 return scoped_ptr<base::Value>(); | 347 return nullptr; |
| 348 } | 348 } |
| 349 | 349 |
| 350 } // namespace policy | 350 } // namespace policy |
| OLD | NEW |