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/memory/ptr_util.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 | 14 |
15 using base::mac::CFCast; | 15 using base::mac::CFCast; |
16 | 16 |
17 namespace policy { | 17 namespace policy { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Callback function for CFDictionaryApplyFunction. |key| and |value| are an | 21 // Callback function for CFDictionaryApplyFunction. |key| and |value| are an |
22 // entry of the CFDictionary that should be converted into an equivalent entry | 22 // entry of the CFDictionary that should be converted into an equivalent entry |
23 // in the DictionaryValue in |context|. | 23 // in the DictionaryValue in |context|. |
24 void DictionaryEntryToValue(const void* key, const void* value, void* context) { | 24 void DictionaryEntryToValue(const void* key, const void* value, void* context) { |
25 if (CFStringRef cf_key = CFCast<CFStringRef>(key)) { | 25 if (CFStringRef cf_key = CFCast<CFStringRef>(key)) { |
26 std::unique_ptr<base::Value> converted = | 26 std::unique_ptr<base::Value> converted = |
27 PropertyToValue(static_cast<CFPropertyListRef>(value)); | 27 PropertyToValue(static_cast<CFPropertyListRef>(value)); |
28 if (converted) { | 28 if (converted) { |
29 const std::string string = base::SysCFStringRefToUTF8(cf_key); | 29 const std::string string = base::SysCFStringRefToUTF8(cf_key); |
30 static_cast<base::DictionaryValue*>(context)->Set( | 30 static_cast<base::DictionaryValue*>(context)->Set(string, |
31 string, converted.release()); | 31 std::move(converted)); |
32 } | 32 } |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 // Callback function for CFArrayApplyFunction. |value| is an entry of the | 36 // Callback function for CFArrayApplyFunction. |value| is an entry of the |
37 // CFArray that should be converted into an equivalent entry in the ListValue | 37 // CFArray that should be converted into an equivalent entry in the ListValue |
38 // in |context|. | 38 // in |context|. |
39 void ArrayEntryToValue(const void* value, void* context) { | 39 void ArrayEntryToValue(const void* value, void* context) { |
40 std::unique_ptr<base::Value> converted = | 40 std::unique_ptr<base::Value> converted = |
41 PropertyToValue(static_cast<CFPropertyListRef>(value)); | 41 PropertyToValue(static_cast<CFPropertyListRef>(value)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 CFRangeMake(0, CFArrayGetCount(array)), | 88 CFRangeMake(0, CFArrayGetCount(array)), |
89 ArrayEntryToValue, | 89 ArrayEntryToValue, |
90 list_value.get()); | 90 list_value.get()); |
91 return std::move(list_value); | 91 return std::move(list_value); |
92 } | 92 } |
93 | 93 |
94 return nullptr; | 94 return nullptr; |
95 } | 95 } |
96 | 96 |
97 } // namespace policy | 97 } // namespace policy |
OLD | NEW |