| 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 keys_.swap(other->keys_); | 236 keys_.swap(other->keys_); |
| 237 values_.swap(other->values_); | 237 values_.swap(other->values_); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void RegistryDict::ReadRegistry(HKEY hive, const base::string16& root) { | 240 void RegistryDict::ReadRegistry(HKEY hive, const base::string16& root) { |
| 241 ClearKeys(); | 241 ClearKeys(); |
| 242 ClearValues(); | 242 ClearValues(); |
| 243 | 243 |
| 244 // First, read all the values of the key. | 244 // First, read all the values of the key. |
| 245 for (RegistryValueIterator it(hive, root.c_str()); it.Valid(); ++it) { | 245 for (RegistryValueIterator it(hive, root.c_str()); it.Valid(); ++it) { |
| 246 const std::string name = UTF16ToUTF8(it.Name()); | 246 const std::string name = base::UTF16ToUTF8(it.Name()); |
| 247 switch (it.Type()) { | 247 switch (it.Type()) { |
| 248 case REG_SZ: | 248 case REG_SZ: |
| 249 case REG_EXPAND_SZ: | 249 case REG_EXPAND_SZ: |
| 250 SetValue( | 250 SetValue( |
| 251 name, | 251 name, |
| 252 make_scoped_ptr(new base::StringValue(UTF16ToUTF8(it.Value())))); | 252 make_scoped_ptr( |
| 253 new base::StringValue(base::UTF16ToUTF8(it.Value())))); |
| 253 continue; | 254 continue; |
| 254 case REG_DWORD_LITTLE_ENDIAN: | 255 case REG_DWORD_LITTLE_ENDIAN: |
| 255 case REG_DWORD_BIG_ENDIAN: | 256 case REG_DWORD_BIG_ENDIAN: |
| 256 if (it.ValueSize() == sizeof(DWORD)) { | 257 if (it.ValueSize() == sizeof(DWORD)) { |
| 257 DWORD dword_value = *(reinterpret_cast<const DWORD*>(it.Value())); | 258 DWORD dword_value = *(reinterpret_cast<const DWORD*>(it.Value())); |
| 258 if (it.Type() == REG_DWORD_BIG_ENDIAN) | 259 if (it.Type() == REG_DWORD_BIG_ENDIAN) |
| 259 dword_value = base::NetToHost32(dword_value); | 260 dword_value = base::NetToHost32(dword_value); |
| 260 else | 261 else |
| 261 dword_value = base::ByteSwapToLE32(dword_value); | 262 dword_value = base::ByteSwapToLE32(dword_value); |
| 262 SetValue( | 263 SetValue( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 275 break; | 276 break; |
| 276 } | 277 } |
| 277 | 278 |
| 278 LOG(WARNING) << "Failed to read hive " << hive << " at " | 279 LOG(WARNING) << "Failed to read hive " << hive << " at " |
| 279 << root << "\\" << name | 280 << root << "\\" << name |
| 280 << " type " << it.Type(); | 281 << " type " << it.Type(); |
| 281 } | 282 } |
| 282 | 283 |
| 283 // Recurse for all subkeys. | 284 // Recurse for all subkeys. |
| 284 for (RegistryKeyIterator it(hive, root.c_str()); it.Valid(); ++it) { | 285 for (RegistryKeyIterator it(hive, root.c_str()); it.Valid(); ++it) { |
| 285 std::string name(UTF16ToUTF8(it.Name())); | 286 std::string name(base::UTF16ToUTF8(it.Name())); |
| 286 scoped_ptr<RegistryDict> subdict(new RegistryDict()); | 287 scoped_ptr<RegistryDict> subdict(new RegistryDict()); |
| 287 subdict->ReadRegistry(hive, root + L"\\" + it.Name()); | 288 subdict->ReadRegistry(hive, root + L"\\" + it.Name()); |
| 288 SetKey(name, subdict.Pass()); | 289 SetKey(name, subdict.Pass()); |
| 289 } | 290 } |
| 290 } | 291 } |
| 291 | 292 |
| 292 scoped_ptr<base::Value> RegistryDict::ConvertToJSON( | 293 scoped_ptr<base::Value> RegistryDict::ConvertToJSON( |
| 293 const Schema& schema) const { | 294 const Schema& schema) const { |
| 294 base::Value::Type type = | 295 base::Value::Type type = |
| 295 schema.valid() ? schema.type() : base::Value::TYPE_DICTIONARY; | 296 schema.valid() ? schema.type() : base::Value::TYPE_DICTIONARY; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 return result.Pass(); | 341 return result.Pass(); |
| 341 } | 342 } |
| 342 default: | 343 default: |
| 343 LOG(WARNING) << "Can't convert registry key to schema type " << type; | 344 LOG(WARNING) << "Can't convert registry key to schema type " << type; |
| 344 } | 345 } |
| 345 | 346 |
| 346 return scoped_ptr<base::Value>(); | 347 return scoped_ptr<base::Value>(); |
| 347 } | 348 } |
| 348 | 349 |
| 349 } // namespace policy | 350 } // namespace policy |
| OLD | NEW |