Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: components/policy/core/common/registry_dict_win.cc

Issue 369303004: Pass() type followups after https://codereview.chromium.org/367403002/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bleh Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | components/policy/core/common/registry_dict_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 int int_value = 0; 63 int int_value = 0;
64 switch (schema.type()) { 64 switch (schema.type()) {
65 case base::Value::TYPE_NULL: { 65 case base::Value::TYPE_NULL: {
66 return make_scoped_ptr(base::Value::CreateNullValue()).Pass(); 66 return make_scoped_ptr(base::Value::CreateNullValue()).Pass();
67 } 67 }
68 case base::Value::TYPE_BOOLEAN: { 68 case base::Value::TYPE_BOOLEAN: {
69 // Accept booleans encoded as either string or integer. 69 // Accept booleans encoded as either string or integer.
70 if (value.GetAsInteger(&int_value) || 70 if (value.GetAsInteger(&int_value) ||
71 (value.GetAsString(&string_value) && 71 (value.GetAsString(&string_value) &&
72 base::StringToInt(string_value, &int_value))) { 72 base::StringToInt(string_value, &int_value))) {
73 return make_scoped_ptr(base::Value::CreateBooleanValue(int_value != 0)) 73 return scoped_ptr<base::Value>(
74 .PassAs<base::Value>(); 74 base::Value::CreateBooleanValue(int_value != 0));
75 } 75 }
76 break; 76 break;
77 } 77 }
78 case base::Value::TYPE_INTEGER: { 78 case base::Value::TYPE_INTEGER: {
79 // Integers may be string-encoded. 79 // Integers may be string-encoded.
80 if (value.GetAsString(&string_value) && 80 if (value.GetAsString(&string_value) &&
81 base::StringToInt(string_value, &int_value)) { 81 base::StringToInt(string_value, &int_value)) {
82 return make_scoped_ptr(base::Value::CreateIntegerValue(int_value)) 82 return scoped_ptr<base::Value>(
83 .PassAs<base::Value>(); 83 base::Value::CreateIntegerValue(int_value));
84 } 84 }
85 break; 85 break;
86 } 86 }
87 case base::Value::TYPE_DOUBLE: { 87 case base::Value::TYPE_DOUBLE: {
88 // Doubles may be string-encoded or integer-encoded. 88 // Doubles may be string-encoded or integer-encoded.
89 double double_value = 0; 89 double double_value = 0;
90 if (value.GetAsInteger(&int_value)) { 90 if (value.GetAsInteger(&int_value)) {
91 return make_scoped_ptr(base::Value::CreateDoubleValue(int_value)) 91 return scoped_ptr<base::Value>(
92 .PassAs<base::Value>(); 92 base::Value::CreateDoubleValue(int_value));
93 } else if (value.GetAsString(&string_value) && 93 } else if (value.GetAsString(&string_value) &&
94 base::StringToDouble(string_value, &double_value)) { 94 base::StringToDouble(string_value, &double_value)) {
95 return make_scoped_ptr(base::Value::CreateDoubleValue(double_value)) 95 return scoped_ptr<base::Value>(
96 .PassAs<base::Value>(); 96 base::Value::CreateDoubleValue(double_value));
97 } 97 }
98 break; 98 break;
99 } 99 }
100 case base::Value::TYPE_LIST: { 100 case base::Value::TYPE_LIST: {
101 // Lists are encoded as subkeys with numbered value in the registry. 101 // Lists are encoded as subkeys with numbered value in the registry.
102 const base::DictionaryValue* dict = NULL; 102 const base::DictionaryValue* dict = NULL;
103 if (value.GetAsDictionary(&dict)) { 103 if (value.GetAsDictionary(&dict)) {
104 scoped_ptr<base::ListValue> result(new base::ListValue()); 104 scoped_ptr<base::ListValue> result(new base::ListValue());
105 for (int i = 1; ; ++i) { 105 for (int i = 1; ; ++i) {
106 const base::Value* entry = NULL; 106 const base::Value* entry = NULL;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 ClearKeys(); 245 ClearKeys();
246 ClearValues(); 246 ClearValues();
247 247
248 // First, read all the values of the key. 248 // First, read all the values of the key.
249 for (RegistryValueIterator it(hive, root.c_str()); it.Valid(); ++it) { 249 for (RegistryValueIterator it(hive, root.c_str()); it.Valid(); ++it) {
250 const std::string name = base::UTF16ToUTF8(it.Name()); 250 const std::string name = base::UTF16ToUTF8(it.Name());
251 switch (it.Type()) { 251 switch (it.Type()) {
252 case REG_SZ: 252 case REG_SZ:
253 case REG_EXPAND_SZ: 253 case REG_EXPAND_SZ:
254 SetValue(name, 254 SetValue(name,
255 make_scoped_ptr(new base::StringValue( 255 scoped_ptr<base::Value>(
256 base::UTF16ToUTF8(it.Value()))).Pass()); 256 new base::StringValue(base::UTF16ToUTF8(it.Value()))));
257 continue; 257 continue;
258 case REG_DWORD_LITTLE_ENDIAN: 258 case REG_DWORD_LITTLE_ENDIAN:
259 case REG_DWORD_BIG_ENDIAN: 259 case REG_DWORD_BIG_ENDIAN:
260 if (it.ValueSize() == sizeof(DWORD)) { 260 if (it.ValueSize() == sizeof(DWORD)) {
261 DWORD dword_value = *(reinterpret_cast<const DWORD*>(it.Value())); 261 DWORD dword_value = *(reinterpret_cast<const DWORD*>(it.Value()));
262 if (it.Type() == REG_DWORD_BIG_ENDIAN) 262 if (it.Type() == REG_DWORD_BIG_ENDIAN)
263 dword_value = base::NetToHost32(dword_value); 263 dword_value = base::NetToHost32(dword_value);
264 else 264 else
265 dword_value = base::ByteSwapToLE32(dword_value); 265 dword_value = base::ByteSwapToLE32(dword_value);
266 SetValue(name, 266 SetValue(name,
267 make_scoped_ptr(base::Value::CreateIntegerValue(dword_value)) 267 scoped_ptr<base::Value>(
268 .PassAs<base::Value>()); 268 base::Value::CreateIntegerValue(dword_value)));
269 continue; 269 continue;
270 } 270 }
271 case REG_NONE: 271 case REG_NONE:
272 case REG_LINK: 272 case REG_LINK:
273 case REG_MULTI_SZ: 273 case REG_MULTI_SZ:
274 case REG_RESOURCE_LIST: 274 case REG_RESOURCE_LIST:
275 case REG_FULL_RESOURCE_DESCRIPTOR: 275 case REG_FULL_RESOURCE_DESCRIPTOR:
276 case REG_RESOURCE_REQUIREMENTS_LIST: 276 case REG_RESOURCE_REQUIREMENTS_LIST:
277 case REG_QWORD_LITTLE_ENDIAN: 277 case REG_QWORD_LITTLE_ENDIAN:
278 // Unsupported type, message gets logged below. 278 // Unsupported type, message gets logged below.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 return result.Pass(); 344 return result.Pass();
345 } 345 }
346 default: 346 default:
347 LOG(WARNING) << "Can't convert registry key to schema type " << type; 347 LOG(WARNING) << "Can't convert registry key to schema type " << type;
348 } 348 }
349 349
350 return scoped_ptr<base::Value>(); 350 return scoped_ptr<base::Value>();
351 } 351 }
352 352
353 } // namespace policy 353 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | components/policy/core/common/registry_dict_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698