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

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

Issue 1902633006: Convert //components/policy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and use namespace alias Created 4 years, 8 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 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/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 13
14 using base::mac::CFCast; 14 using base::mac::CFCast;
15 15
16 namespace policy { 16 namespace policy {
17 17
18 namespace { 18 namespace {
19 19
20 // Callback function for CFDictionaryApplyFunction. |key| and |value| are an 20 // Callback function for CFDictionaryApplyFunction. |key| and |value| are an
21 // entry of the CFDictionary that should be converted into an equivalent entry 21 // entry of the CFDictionary that should be converted into an equivalent entry
22 // in the DictionaryValue in |context|. 22 // in the DictionaryValue in |context|.
23 void DictionaryEntryToValue(const void* key, const void* value, void* context) { 23 void DictionaryEntryToValue(const void* key, const void* value, void* context) {
24 if (CFStringRef cf_key = CFCast<CFStringRef>(key)) { 24 if (CFStringRef cf_key = CFCast<CFStringRef>(key)) {
25 scoped_ptr<base::Value> converted = 25 std::unique_ptr<base::Value> converted =
26 PropertyToValue(static_cast<CFPropertyListRef>(value)); 26 PropertyToValue(static_cast<CFPropertyListRef>(value));
27 if (converted) { 27 if (converted) {
28 const std::string string = base::SysCFStringRefToUTF8(cf_key); 28 const std::string string = base::SysCFStringRefToUTF8(cf_key);
29 static_cast<base::DictionaryValue*>(context)->Set( 29 static_cast<base::DictionaryValue*>(context)->Set(
30 string, converted.release()); 30 string, converted.release());
31 } 31 }
32 } 32 }
33 } 33 }
34 34
35 // Callback function for CFArrayApplyFunction. |value| is an entry of the 35 // Callback function for CFArrayApplyFunction. |value| is an entry of the
36 // CFArray that should be converted into an equivalent entry in the ListValue 36 // CFArray that should be converted into an equivalent entry in the ListValue
37 // in |context|. 37 // in |context|.
38 void ArrayEntryToValue(const void* value, void* context) { 38 void ArrayEntryToValue(const void* value, void* context) {
39 scoped_ptr<base::Value> converted = 39 std::unique_ptr<base::Value> converted =
40 PropertyToValue(static_cast<CFPropertyListRef>(value)); 40 PropertyToValue(static_cast<CFPropertyListRef>(value));
41 if (converted) 41 if (converted)
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 scoped_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 scoped_ptr<base::Value>(new base::FundamentalValue( 52 return std::unique_ptr<base::Value>(new base::FundamentalValue(
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 scoped_ptr<base::Value>( 62 return std::unique_ptr<base::Value>(
63 new base::FundamentalValue(double_value)); 63 new base::FundamentalValue(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 scoped_ptr<base::Value>(new base::FundamentalValue(int_value)); 68 return std::unique_ptr<base::Value>(
69 new base::FundamentalValue(int_value));
69 } 70 }
70 } 71 }
71 } 72 }
72 73
73 if (CFStringRef string = CFCast<CFStringRef>(property)) { 74 if (CFStringRef string = CFCast<CFStringRef>(property)) {
74 return scoped_ptr<base::Value>( 75 return std::unique_ptr<base::Value>(
75 new base::StringValue(base::SysCFStringRefToUTF8(string))); 76 new base::StringValue(base::SysCFStringRefToUTF8(string)));
76 } 77 }
77 78
78 if (CFDictionaryRef dict = CFCast<CFDictionaryRef>(property)) { 79 if (CFDictionaryRef dict = CFCast<CFDictionaryRef>(property)) {
79 scoped_ptr<base::DictionaryValue> dict_value(new base::DictionaryValue()); 80 std::unique_ptr<base::DictionaryValue> dict_value(
81 new base::DictionaryValue());
80 CFDictionaryApplyFunction(dict, DictionaryEntryToValue, dict_value.get()); 82 CFDictionaryApplyFunction(dict, DictionaryEntryToValue, dict_value.get());
81 return std::move(dict_value); 83 return std::move(dict_value);
82 } 84 }
83 85
84 if (CFArrayRef array = CFCast<CFArrayRef>(property)) { 86 if (CFArrayRef array = CFCast<CFArrayRef>(property)) {
85 scoped_ptr<base::ListValue> list_value(new base::ListValue()); 87 std::unique_ptr<base::ListValue> list_value(new base::ListValue());
86 CFArrayApplyFunction(array, 88 CFArrayApplyFunction(array,
87 CFRangeMake(0, CFArrayGetCount(array)), 89 CFRangeMake(0, CFArrayGetCount(array)),
88 ArrayEntryToValue, 90 ArrayEntryToValue,
89 list_value.get()); 91 list_value.get());
90 return std::move(list_value); 92 return std::move(list_value);
91 } 93 }
92 94
93 return nullptr; 95 return nullptr;
94 } 96 }
95 97
96 } // namespace policy 98 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/mac_util.h ('k') | components/policy/core/common/mac_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698