| 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" |
| 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 | 14 |
| 14 using base::mac::CFCast; | 15 using base::mac::CFCast; |
| 15 | 16 |
| 16 namespace policy { | 17 namespace policy { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // Callback function for CFDictionaryApplyFunction. |key| and |value| are an | 21 // Callback function for CFDictionaryApplyFunction. |key| and |value| are an |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 std::unique_ptr<base::Value> converted = | 40 std::unique_ptr<base::Value> converted = |
| 40 PropertyToValue(static_cast<CFPropertyListRef>(value)); | 41 PropertyToValue(static_cast<CFPropertyListRef>(value)); |
| 41 if (converted) | 42 if (converted) |
| 42 static_cast<base::ListValue *>(context)->Append(converted.release()); | 43 static_cast<base::ListValue *>(context)->Append(converted.release()); |
| 43 } | 44 } |
| 44 | 45 |
| 45 } // namespace | 46 } // namespace |
| 46 | 47 |
| 47 std::unique_ptr<base::Value> PropertyToValue(CFPropertyListRef property) { | 48 std::unique_ptr<base::Value> PropertyToValue(CFPropertyListRef property) { |
| 48 if (CFCast<CFNullRef>(property)) | 49 if (CFCast<CFNullRef>(property)) |
| 49 return base::Value::CreateNullValue(); | 50 return base::MakeUnique<base::Value>(); |
| 50 | 51 |
| 51 if (CFBooleanRef boolean = CFCast<CFBooleanRef>(property)) { | 52 if (CFBooleanRef boolean = CFCast<CFBooleanRef>(property)) { |
| 52 return std::unique_ptr<base::Value>( | 53 return std::unique_ptr<base::Value>( |
| 53 new base::Value(static_cast<bool>(CFBooleanGetValue(boolean)))); | 54 new base::Value(static_cast<bool>(CFBooleanGetValue(boolean)))); |
| 54 } | 55 } |
| 55 | 56 |
| 56 if (CFNumberRef number = CFCast<CFNumberRef>(property)) { | 57 if (CFNumberRef number = CFCast<CFNumberRef>(property)) { |
| 57 // CFNumberGetValue() converts values implicitly when the conversion is not | 58 // CFNumberGetValue() converts values implicitly when the conversion is not |
| 58 // lossy. Check the type before trying to convert. | 59 // lossy. Check the type before trying to convert. |
| 59 if (CFNumberIsFloatType(number)) { | 60 if (CFNumberIsFloatType(number)) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 87 CFRangeMake(0, CFArrayGetCount(array)), | 88 CFRangeMake(0, CFArrayGetCount(array)), |
| 88 ArrayEntryToValue, | 89 ArrayEntryToValue, |
| 89 list_value.get()); | 90 list_value.get()); |
| 90 return std::move(list_value); | 91 return std::move(list_value); |
| 91 } | 92 } |
| 92 | 93 |
| 93 return nullptr; | 94 return nullptr; |
| 94 } | 95 } |
| 95 | 96 |
| 96 } // namespace policy | 97 } // namespace policy |
| OLD | NEW |