| 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/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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::NONE: |
| 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 (const auto& entry : *list) { | 125 for (const auto& entry : *list) { |
| 126 // CFArrayAppendValue() retains |cf_value|, so make sure the reference | 126 // CFArrayAppendValue() retains |cf_value|, so make sure the reference |
| 127 // created by ValueToProperty() is released. | 127 // created by ValueToProperty() is released. |
| 128 base::ScopedCFTypeRef<CFPropertyListRef> cf_value( | 128 base::ScopedCFTypeRef<CFPropertyListRef> cf_value( |
| 129 ValueToProperty(*entry)); | 129 ValueToProperty(*entry)); |
| 130 if (cf_value) | 130 if (cf_value) |
| 131 CFArrayAppendValue(array, cf_value); | 131 CFArrayAppendValue(array, cf_value); |
| 132 } | 132 } |
| 133 return array; | 133 return array; |
| 134 } | 134 } |
| 135 break; | 135 break; |
| 136 } | 136 } |
| 137 | 137 |
| 138 case base::Value::TYPE_BINARY: | 138 case base::Value::Type::BINARY: |
| 139 // 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) |
| 140 // because there's no equivalent JSON type, and policy values can only | 140 // because there's no equivalent JSON type, and policy values can only |
| 141 // take valid JSON values. | 141 // take valid JSON values. |
| 142 break; | 142 break; |
| 143 } | 143 } |
| 144 | 144 |
| 145 return NULL; | 145 return NULL; |
| 146 } | 146 } |
| 147 #endif // defined(OS_IOS) || defined(OS_MACOSX) | 147 #endif // defined(OS_IOS) || defined(OS_MACOSX) |
| 148 | 148 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 << " \"scope\": " << e.scope << "," << std::endl | 233 << " \"scope\": " << e.scope << "," << std::endl |
| 234 << " \"value\": " << value | 234 << " \"value\": " << value |
| 235 << "}"; | 235 << "}"; |
| 236 return os; | 236 return os; |
| 237 } | 237 } |
| 238 | 238 |
| 239 std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns) { | 239 std::ostream& operator<<(std::ostream& os, const policy::PolicyNamespace& ns) { |
| 240 os << ns.domain << "/" << ns.component_id; | 240 os << ns.domain << "/" << ns.component_id; |
| 241 return os; | 241 return os; |
| 242 } | 242 } |
| OLD | NEW |