| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mac_util.h" | 5 #include "components/policy/core/common/mac_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 static_cast<base::ListValue *>(context)->Append(converted.release()); | 42 static_cast<base::ListValue *>(context)->Append(converted.release()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 std::unique_ptr<base::Value> PropertyToValue(CFPropertyListRef property) { | 47 std::unique_ptr<base::Value> PropertyToValue(CFPropertyListRef property) { |
| 48 if (CFCast<CFNullRef>(property)) | 48 if (CFCast<CFNullRef>(property)) |
| 49 return base::Value::CreateNullValue(); | 49 return base::Value::CreateNullValue(); |
| 50 | 50 |
| 51 if (CFBooleanRef boolean = CFCast<CFBooleanRef>(property)) { | 51 if (CFBooleanRef boolean = CFCast<CFBooleanRef>(property)) { |
| 52 return std::unique_ptr<base::Value>(new base::FundamentalValue( | 52 return std::unique_ptr<base::Value>(new base::Value( |
| 53 static_cast<bool>(CFBooleanGetValue(boolean)))); | 53 static_cast<bool>(CFBooleanGetValue(boolean)))); |
| 54 } | 54 } |
| 55 | 55 |
| 56 if (CFNumberRef number = CFCast<CFNumberRef>(property)) { | 56 if (CFNumberRef number = CFCast<CFNumberRef>(property)) { |
| 57 // CFNumberGetValue() converts values implicitly when the conversion is not | 57 // CFNumberGetValue() converts values implicitly when the conversion is not |
| 58 // lossy. Check the type before trying to convert. | 58 // lossy. Check the type before trying to convert. |
| 59 if (CFNumberIsFloatType(number)) { | 59 if (CFNumberIsFloatType(number)) { |
| 60 double double_value = 0.0; | 60 double double_value = 0.0; |
| 61 if (CFNumberGetValue(number, kCFNumberDoubleType, &double_value)) { | 61 if (CFNumberGetValue(number, kCFNumberDoubleType, &double_value)) { |
| 62 return std::unique_ptr<base::Value>( | 62 return std::unique_ptr<base::Value>( |
| 63 new base::FundamentalValue(double_value)); | 63 new base::Value(double_value)); |
| 64 } | 64 } |
| 65 } else { | 65 } else { |
| 66 int int_value = 0; | 66 int int_value = 0; |
| 67 if (CFNumberGetValue(number, kCFNumberIntType, &int_value)) { | 67 if (CFNumberGetValue(number, kCFNumberIntType, &int_value)) { |
| 68 return std::unique_ptr<base::Value>( | 68 return std::unique_ptr<base::Value>( |
| 69 new base::FundamentalValue(int_value)); | 69 new base::Value(int_value)); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 if (CFStringRef string = CFCast<CFStringRef>(property)) { | 74 if (CFStringRef string = CFCast<CFStringRef>(property)) { |
| 75 return std::unique_ptr<base::Value>( | 75 return std::unique_ptr<base::Value>( |
| 76 new base::StringValue(base::SysCFStringRefToUTF8(string))); | 76 new base::StringValue(base::SysCFStringRefToUTF8(string))); |
| 77 } | 77 } |
| 78 | 78 |
| 79 if (CFDictionaryRef dict = CFCast<CFDictionaryRef>(property)) { | 79 if (CFDictionaryRef dict = CFCast<CFDictionaryRef>(property)) { |
| 80 std::unique_ptr<base::DictionaryValue> dict_value( | 80 std::unique_ptr<base::DictionaryValue> dict_value( |
| 81 new base::DictionaryValue()); | 81 new base::DictionaryValue()); |
| 82 CFDictionaryApplyFunction(dict, DictionaryEntryToValue, dict_value.get()); | 82 CFDictionaryApplyFunction(dict, DictionaryEntryToValue, dict_value.get()); |
| 83 return std::move(dict_value); | 83 return std::move(dict_value); |
| 84 } | 84 } |
| 85 | 85 |
| 86 if (CFArrayRef array = CFCast<CFArrayRef>(property)) { | 86 if (CFArrayRef array = CFCast<CFArrayRef>(property)) { |
| 87 std::unique_ptr<base::ListValue> list_value(new base::ListValue()); | 87 std::unique_ptr<base::ListValue> list_value(new base::ListValue()); |
| 88 CFArrayApplyFunction(array, | 88 CFArrayApplyFunction(array, |
| 89 CFRangeMake(0, CFArrayGetCount(array)), | 89 CFRangeMake(0, CFArrayGetCount(array)), |
| 90 ArrayEntryToValue, | 90 ArrayEntryToValue, |
| 91 list_value.get()); | 91 list_value.get()); |
| 92 return std::move(list_value); | 92 return std::move(list_value); |
| 93 } | 93 } |
| 94 | 94 |
| 95 return nullptr; | 95 return nullptr; |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace policy | 98 } // namespace policy |
| OLD | NEW |