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

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

Issue 2000803003: Use std::unique_ptr for base::DictionaryValue and base::ListValue's internal store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More fixes Created 4 years, 7 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
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/policy_test_utils.h" 5 #include "components/policy/core/common/policy_test_utils.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 if (!map.empty()) { 48 if (!map.empty()) {
49 base::DictionaryValue dict; 49 base::DictionaryValue dict;
50 for (PolicyMap::const_iterator it = map.begin(); it != map.end(); ++it) 50 for (PolicyMap::const_iterator it = map.begin(); it != map.end(); ++it)
51 dict.SetWithoutPathExpansion(it->first, it->second.value->DeepCopy()); 51 dict.SetWithoutPathExpansion(it->first, it->second.value->DeepCopy());
52 LOG(WARNING) << "There are pre-existing policies in this machine: " << dict; 52 LOG(WARNING) << "There are pre-existing policies in this machine: " << dict;
53 } 53 }
54 return map.empty(); 54 return map.empty();
55 } 55 }
56 56
57 #if defined(OS_IOS) || defined(OS_MACOSX) 57 #if defined(OS_IOS) || defined(OS_MACOSX)
58 CFPropertyListRef ValueToProperty(const base::Value* value) { 58 CFPropertyListRef ValueToProperty(const base::Value& value) {
59 switch (value->GetType()) { 59 switch (value.GetType()) {
60 case base::Value::TYPE_NULL: 60 case base::Value::TYPE_NULL:
61 return kCFNull; 61 return kCFNull;
62 62
63 case base::Value::TYPE_BOOLEAN: { 63 case base::Value::TYPE_BOOLEAN: {
64 bool bool_value; 64 bool bool_value;
65 if (value->GetAsBoolean(&bool_value)) 65 if (value.GetAsBoolean(&bool_value))
66 return bool_value ? kCFBooleanTrue : kCFBooleanFalse; 66 return bool_value ? kCFBooleanTrue : kCFBooleanFalse;
67 break; 67 break;
68 } 68 }
69 69
70 case base::Value::TYPE_INTEGER: { 70 case base::Value::TYPE_INTEGER: {
71 int int_value; 71 int int_value;
72 if (value->GetAsInteger(&int_value)) { 72 if (value.GetAsInteger(&int_value)) {
73 return CFNumberCreate( 73 return CFNumberCreate(
74 kCFAllocatorDefault, kCFNumberIntType, &int_value); 74 kCFAllocatorDefault, kCFNumberIntType, &int_value);
75 } 75 }
76 break; 76 break;
77 } 77 }
78 78
79 case base::Value::TYPE_DOUBLE: { 79 case base::Value::TYPE_DOUBLE: {
80 double double_value; 80 double double_value;
81 if (value->GetAsDouble(&double_value)) { 81 if (value.GetAsDouble(&double_value)) {
82 return CFNumberCreate( 82 return CFNumberCreate(
83 kCFAllocatorDefault, kCFNumberDoubleType, &double_value); 83 kCFAllocatorDefault, kCFNumberDoubleType, &double_value);
84 } 84 }
85 break; 85 break;
86 } 86 }
87 87
88 case base::Value::TYPE_STRING: { 88 case base::Value::TYPE_STRING: {
89 std::string string_value; 89 std::string string_value;
90 if (value->GetAsString(&string_value)) 90 if (value.GetAsString(&string_value))
91 return base::SysUTF8ToCFStringRef(string_value); 91 return base::SysUTF8ToCFStringRef(string_value);
92 break; 92 break;
93 } 93 }
94 94
95 case base::Value::TYPE_DICTIONARY: { 95 case base::Value::TYPE_DICTIONARY: {
96 const base::DictionaryValue* dict_value; 96 const base::DictionaryValue* dict_value;
97 if (value->GetAsDictionary(&dict_value)) { 97 if (value.GetAsDictionary(&dict_value)) {
98 // |dict| is owned by the caller. 98 // |dict| is owned by the caller.
99 CFMutableDictionaryRef dict = 99 CFMutableDictionaryRef dict =
100 CFDictionaryCreateMutable(kCFAllocatorDefault, 100 CFDictionaryCreateMutable(kCFAllocatorDefault,
101 dict_value->size(), 101 dict_value->size(),
102 &kCFTypeDictionaryKeyCallBacks, 102 &kCFTypeDictionaryKeyCallBacks,
103 &kCFTypeDictionaryValueCallBacks); 103 &kCFTypeDictionaryValueCallBacks);
104 for (base::DictionaryValue::Iterator iterator(*dict_value); 104 for (base::DictionaryValue::Iterator iterator(*dict_value);
105 !iterator.IsAtEnd(); iterator.Advance()) { 105 !iterator.IsAtEnd(); iterator.Advance()) {
106 // CFDictionaryAddValue() retains both |key| and |value|, so make sure 106 // CFDictionaryAddValue() retains both |key| and |value|, so make sure
107 // the references are balanced. 107 // the references are balanced.
108 base::ScopedCFTypeRef<CFStringRef> key( 108 base::ScopedCFTypeRef<CFStringRef> key(
109 base::SysUTF8ToCFStringRef(iterator.key())); 109 base::SysUTF8ToCFStringRef(iterator.key()));
110 base::ScopedCFTypeRef<CFPropertyListRef> cf_value( 110 base::ScopedCFTypeRef<CFPropertyListRef> cf_value(
111 ValueToProperty(&iterator.value())); 111 ValueToProperty(iterator.value()));
112 if (cf_value) 112 if (cf_value)
113 CFDictionaryAddValue(dict, key, cf_value); 113 CFDictionaryAddValue(dict, key, cf_value);
114 } 114 }
115 return dict; 115 return dict;
116 } 116 }
117 break; 117 break;
118 } 118 }
119 119
120 case base::Value::TYPE_LIST: { 120 case base::Value::TYPE_LIST: {
121 const base::ListValue* list; 121 const base::ListValue* list;
122 if (value->GetAsList(&list)) { 122 if (value.GetAsList(&list)) {
123 CFMutableArrayRef array = 123 CFMutableArrayRef array =
124 CFArrayCreateMutable(NULL, list->GetSize(), &kCFTypeArrayCallBacks); 124 CFArrayCreateMutable(NULL, list->GetSize(), &kCFTypeArrayCallBacks);
125 for (base::ListValue::const_iterator it(list->begin()); 125 for (const auto& entry : *list) {
126 it != list->end(); ++it) { 126 // CFArrayAppendValue() retains |cf_value|, so make sure the reference
127 // CFArrayAppendValue() retains |value|, so make sure the reference
128 // created by ValueToProperty() is released. 127 // created by ValueToProperty() is released.
129 base::ScopedCFTypeRef<CFPropertyListRef> cf_value( 128 base::ScopedCFTypeRef<CFPropertyListRef> cf_value(
130 ValueToProperty(*it)); 129 ValueToProperty(*entry));
131 if (cf_value) 130 if (cf_value)
132 CFArrayAppendValue(array, cf_value); 131 CFArrayAppendValue(array, cf_value);
133 } 132 }
134 return array; 133 return array;
135 } 134 }
136 break; 135 break;
137 } 136 }
138 137
139 case base::Value::TYPE_BINARY: 138 case base::Value::TYPE_BINARY:
140 // This type isn't converted (though it can be represented as CFData) 139 // This type isn't converted (though it can be represented as CFData)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 << " \"scope\": " << e.scope << "," << std::endl 229 << " \"scope\": " << e.scope << "," << std::endl
231 << " \"value\": " << value 230 << " \"value\": " << value
232 << "}"; 231 << "}";
233 return os; 232 return os;
234 } 233 }
235 234
236 std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns) { 235 std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns) {
237 os << ns.domain << "/" << ns.component_id; 236 os << ns.domain << "/" << ns.component_id;
238 return os; 237 return os;
239 } 238 }
OLDNEW
« no previous file with comments | « components/policy/core/common/policy_test_utils.h ('k') | components/signin/core/browser/account_tracker_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698