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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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()); | 66 return make_scoped_ptr(base::Value::CreateNullValue()); |
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(Value::CreateBooleanValue(int_value != 0)); | 73 return make_scoped_ptr(base::Value::CreateBooleanValue(int_value != 0)); |
74 } | 74 } |
75 break; | 75 break; |
76 } | 76 } |
77 case base::Value::TYPE_INTEGER: { | 77 case base::Value::TYPE_INTEGER: { |
78 // Integers may be string-encoded. | 78 // Integers may be string-encoded. |
79 if (value.GetAsString(&string_value) && | 79 if (value.GetAsString(&string_value) && |
80 base::StringToInt(string_value, &int_value)) { | 80 base::StringToInt(string_value, &int_value)) { |
81 return make_scoped_ptr(base::Value::CreateIntegerValue(int_value)); | 81 return make_scoped_ptr(base::Value::CreateIntegerValue(int_value)); |
82 } | 82 } |
83 break; | 83 break; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 return entry != values_.end() ? entry->second : NULL; | 191 return entry != values_.end() ? entry->second : NULL; |
192 } | 192 } |
193 | 193 |
194 void RegistryDict::SetValue(const std::string& name, | 194 void RegistryDict::SetValue(const std::string& name, |
195 scoped_ptr<base::Value> dict) { | 195 scoped_ptr<base::Value> dict) { |
196 if (!dict) { | 196 if (!dict) { |
197 RemoveValue(name); | 197 RemoveValue(name); |
198 return; | 198 return; |
199 } | 199 } |
200 | 200 |
201 Value*& entry = values_[name]; | 201 base::Value*& entry = values_[name]; |
202 delete entry; | 202 delete entry; |
203 entry = dict.release(); | 203 entry = dict.release(); |
204 } | 204 } |
205 | 205 |
206 scoped_ptr<base::Value> RegistryDict::RemoveValue(const std::string& name) { | 206 scoped_ptr<base::Value> RegistryDict::RemoveValue(const std::string& name) { |
207 scoped_ptr<base::Value> result; | 207 scoped_ptr<base::Value> result; |
208 ValueMap::iterator entry = values_.find(name); | 208 ValueMap::iterator entry = values_.find(name); |
209 if (entry != values_.end()) { | 209 if (entry != values_.end()) { |
210 result.reset(entry->second); | 210 result.reset(entry->second); |
211 values_.erase(entry); | 211 values_.erase(entry); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 return result.Pass(); | 340 return result.Pass(); |
341 } | 341 } |
342 default: | 342 default: |
343 LOG(WARNING) << "Can't convert registry key to schema type " << type; | 343 LOG(WARNING) << "Can't convert registry key to schema type " << type; |
344 } | 344 } |
345 | 345 |
346 return scoped_ptr<base::Value>(); | 346 return scoped_ptr<base::Value>(); |
347 } | 347 } |
348 | 348 |
349 } // namespace policy | 349 } // namespace policy |
OLD | NEW |