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

Side by Side Diff: chrome/browser/chromeos/policy/device_policy_decoder_chromeos.cc

Issue 1870793002: Convert //chrome/browser/chromeos from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/policy/device_policy_decoder_chromeos.h" 5 #include "chrome/browser/chromeos/policy/device_policy_decoder_chromeos.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 20 matching lines...) Expand all
31 using google::protobuf::RepeatedPtrField; 31 using google::protobuf::RepeatedPtrField;
32 32
33 namespace em = enterprise_management; 33 namespace em = enterprise_management;
34 34
35 namespace policy { 35 namespace policy {
36 36
37 namespace { 37 namespace {
38 38
39 // Decodes a protobuf integer to an IntegerValue. Returns NULL in case the input 39 // Decodes a protobuf integer to an IntegerValue. Returns NULL in case the input
40 // value is out of bounds. 40 // value is out of bounds.
41 scoped_ptr<base::Value> DecodeIntegerValue(google::protobuf::int64 value) { 41 std::unique_ptr<base::Value> DecodeIntegerValue(google::protobuf::int64 value) {
42 if (value < std::numeric_limits<int>::min() || 42 if (value < std::numeric_limits<int>::min() ||
43 value > std::numeric_limits<int>::max()) { 43 value > std::numeric_limits<int>::max()) {
44 LOG(WARNING) << "Integer value " << value 44 LOG(WARNING) << "Integer value " << value
45 << " out of numeric limits, ignoring."; 45 << " out of numeric limits, ignoring.";
46 return scoped_ptr<base::Value>(); 46 return std::unique_ptr<base::Value>();
47 } 47 }
48 48
49 return scoped_ptr<base::Value>( 49 return std::unique_ptr<base::Value>(
50 new base::FundamentalValue(static_cast<int>(value))); 50 new base::FundamentalValue(static_cast<int>(value)));
51 } 51 }
52 52
53 // Decodes a JSON string to a base::Value, and drops unknown properties 53 // Decodes a JSON string to a base::Value, and drops unknown properties
54 // according to a policy schema. |policy_name| is the name of a policy schema 54 // according to a policy schema. |policy_name| is the name of a policy schema
55 // defined in policy_templates.json. Returns NULL in case the input is not a 55 // defined in policy_templates.json. Returns NULL in case the input is not a
56 // valid JSON string. 56 // valid JSON string.
57 scoped_ptr<base::Value> DecodeJsonStringAndDropUnknownBySchema( 57 std::unique_ptr<base::Value> DecodeJsonStringAndDropUnknownBySchema(
58 const std::string& json_string, 58 const std::string& json_string,
59 const std::string& policy_name) { 59 const std::string& policy_name) {
60 std::string error; 60 std::string error;
61 scoped_ptr<base::Value> root = base::JSONReader::ReadAndReturnError( 61 std::unique_ptr<base::Value> root = base::JSONReader::ReadAndReturnError(
62 json_string, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error); 62 json_string, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error);
63 63
64 if (!root) { 64 if (!root) {
65 LOG(WARNING) << "Invalid JSON string: " << error << ", ignoring."; 65 LOG(WARNING) << "Invalid JSON string: " << error << ", ignoring.";
66 return scoped_ptr<base::Value>(); 66 return std::unique_ptr<base::Value>();
67 } 67 }
68 68
69 const Schema& schema = g_browser_process 69 const Schema& schema = g_browser_process
70 ->browser_policy_connector() 70 ->browser_policy_connector()
71 ->GetChromeSchema() 71 ->GetChromeSchema()
72 .GetKnownProperty(policy_name); 72 .GetKnownProperty(policy_name);
73 73
74 if (schema.valid()) { 74 if (schema.valid()) {
75 std::string error_path; 75 std::string error_path;
76 bool changed = false; 76 bool changed = false;
77 77
78 if (!schema.Normalize(root.get(), SCHEMA_ALLOW_UNKNOWN, &error_path, &error, 78 if (!schema.Normalize(root.get(), SCHEMA_ALLOW_UNKNOWN, &error_path, &error,
79 &changed)) { 79 &changed)) {
80 LOG(WARNING) << "Invalid policy value for " << policy_name << ": " 80 LOG(WARNING) << "Invalid policy value for " << policy_name << ": "
81 << error << " at " << error_path << "."; 81 << error << " at " << error_path << ".";
82 return scoped_ptr<base::Value>(); 82 return std::unique_ptr<base::Value>();
83 } 83 }
84 84
85 if (changed) { 85 if (changed) {
86 LOG(WARNING) << "Some properties in " << policy_name 86 LOG(WARNING) << "Some properties in " << policy_name
87 << " were dropped: " << error << " at " << error_path << "."; 87 << " were dropped: " << error << " at " << error_path << ".";
88 } 88 }
89 } else { 89 } else {
90 LOG(WARNING) << "Unknown or invalid policy schema for " << policy_name 90 LOG(WARNING) << "Unknown or invalid policy schema for " << policy_name
91 << "."; 91 << ".";
92 return scoped_ptr<base::Value>(); 92 return std::unique_ptr<base::Value>();
93 } 93 }
94 94
95 return root; 95 return root;
96 } 96 }
97 97
98 base::Value* DecodeConnectionType(int value) { 98 base::Value* DecodeConnectionType(int value) {
99 static const char* const kConnectionTypes[] = { 99 static const char* const kConnectionTypes[] = {
100 shill::kTypeEthernet, 100 shill::kTypeEthernet,
101 shill::kTypeWifi, 101 shill::kTypeWifi,
102 shill::kTypeWimax, 102 shill::kTypeWimax,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 container.ephemeral_users_enabled()), 191 container.ephemeral_users_enabled()),
192 NULL); 192 NULL);
193 } 193 }
194 } 194 }
195 195
196 if (policy.has_device_local_accounts()) { 196 if (policy.has_device_local_accounts()) {
197 const em::DeviceLocalAccountsProto& container( 197 const em::DeviceLocalAccountsProto& container(
198 policy.device_local_accounts()); 198 policy.device_local_accounts());
199 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = 199 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts =
200 container.account(); 200 container.account();
201 scoped_ptr<base::ListValue> account_list(new base::ListValue()); 201 std::unique_ptr<base::ListValue> account_list(new base::ListValue());
202 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry; 202 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry;
203 for (entry = accounts.begin(); entry != accounts.end(); ++entry) { 203 for (entry = accounts.begin(); entry != accounts.end(); ++entry) {
204 scoped_ptr<base::DictionaryValue> entry_dict( 204 std::unique_ptr<base::DictionaryValue> entry_dict(
205 new base::DictionaryValue()); 205 new base::DictionaryValue());
206 if (entry->has_type()) { 206 if (entry->has_type()) {
207 if (entry->has_account_id()) { 207 if (entry->has_account_id()) {
208 entry_dict->SetStringWithoutPathExpansion( 208 entry_dict->SetStringWithoutPathExpansion(
209 chromeos::kAccountsPrefDeviceLocalAccountsKeyId, 209 chromeos::kAccountsPrefDeviceLocalAccountsKeyId,
210 entry->account_id()); 210 entry->account_id());
211 } 211 }
212 entry_dict->SetIntegerWithoutPathExpansion( 212 entry_dict->SetIntegerWithoutPathExpansion(
213 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, entry->type()); 213 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, entry->type());
214 if (entry->kiosk_app().has_app_id()) { 214 if (entry->kiosk_app().has_app_id()) {
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 policies->Set(key::kSystemTimezone, 701 policies->Set(key::kSystemTimezone,
702 POLICY_LEVEL_MANDATORY, 702 POLICY_LEVEL_MANDATORY,
703 POLICY_SCOPE_MACHINE, 703 POLICY_SCOPE_MACHINE,
704 POLICY_SOURCE_CLOUD, 704 POLICY_SOURCE_CLOUD,
705 new base::StringValue( 705 new base::StringValue(
706 policy.system_timezone().timezone()), 706 policy.system_timezone().timezone()),
707 NULL); 707 NULL);
708 } 708 }
709 709
710 if (policy.system_timezone().has_timezone_detection_type()) { 710 if (policy.system_timezone().has_timezone_detection_type()) {
711 scoped_ptr<base::Value> value(DecodeIntegerValue( 711 std::unique_ptr<base::Value> value(DecodeIntegerValue(
712 policy.system_timezone().timezone_detection_type())); 712 policy.system_timezone().timezone_detection_type()));
713 if (value) { 713 if (value) {
714 policies->Set(key::kSystemTimezoneAutomaticDetection, 714 policies->Set(key::kSystemTimezoneAutomaticDetection,
715 POLICY_LEVEL_MANDATORY, 715 POLICY_LEVEL_MANDATORY,
716 POLICY_SCOPE_MACHINE, 716 POLICY_SCOPE_MACHINE,
717 POLICY_SOURCE_CLOUD, 717 POLICY_SOURCE_CLOUD,
718 value.release(), 718 value.release(),
719 nullptr); 719 nullptr);
720 } 720 }
721 } 721 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 new base::FundamentalValue( 807 new base::FundamentalValue(
808 policy.attestation_settings().content_protection_enabled()), 808 policy.attestation_settings().content_protection_enabled()),
809 NULL); 809 NULL);
810 } 810 }
811 } 811 }
812 812
813 if (policy.has_login_screen_power_management()) { 813 if (policy.has_login_screen_power_management()) {
814 const em::LoginScreenPowerManagementProto& container( 814 const em::LoginScreenPowerManagementProto& container(
815 policy.login_screen_power_management()); 815 policy.login_screen_power_management());
816 if (container.has_login_screen_power_management()) { 816 if (container.has_login_screen_power_management()) {
817 scoped_ptr<base::Value> decoded_json; 817 std::unique_ptr<base::Value> decoded_json;
818 decoded_json = DecodeJsonStringAndDropUnknownBySchema( 818 decoded_json = DecodeJsonStringAndDropUnknownBySchema(
819 container.login_screen_power_management(), 819 container.login_screen_power_management(),
820 key::kDeviceLoginScreenPowerManagement); 820 key::kDeviceLoginScreenPowerManagement);
821 if (decoded_json) { 821 if (decoded_json) {
822 policies->Set(key::kDeviceLoginScreenPowerManagement, 822 policies->Set(key::kDeviceLoginScreenPowerManagement,
823 POLICY_LEVEL_MANDATORY, 823 POLICY_LEVEL_MANDATORY,
824 POLICY_SCOPE_MACHINE, 824 POLICY_SCOPE_MACHINE,
825 POLICY_SOURCE_CLOUD, 825 POLICY_SOURCE_CLOUD,
826 decoded_json.release(), 826 decoded_json.release(),
827 NULL); 827 NULL);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 // Decode the various groups of policies. 922 // Decode the various groups of policies.
923 DecodeLoginPolicies(policy, policies); 923 DecodeLoginPolicies(policy, policies);
924 DecodeNetworkPolicies(policy, policies); 924 DecodeNetworkPolicies(policy, policies);
925 DecodeReportingPolicies(policy, policies); 925 DecodeReportingPolicies(policy, policies);
926 DecodeAutoUpdatePolicies(policy, policies); 926 DecodeAutoUpdatePolicies(policy, policies);
927 DecodeAccessibilityPolicies(policy, policies); 927 DecodeAccessibilityPolicies(policy, policies);
928 DecodeGenericPolicies(policy, policies); 928 DecodeGenericPolicies(policy, policies);
929 } 929 }
930 930
931 } // namespace policy 931 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698