OLD | NEW |
---|---|
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" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chromeos/policy/device_local_account.h" | 18 #include "chrome/browser/chromeos/policy/device_local_account.h" |
18 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 19 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
19 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
20 #include "chromeos/dbus/update_engine_client.h" | 21 #include "chromeos/dbus/update_engine_client.h" |
21 #include "chromeos/settings/cros_settings_names.h" | 22 #include "chromeos/settings/cros_settings_names.h" |
22 #include "components/policy/core/browser/browser_policy_connector.h" | 23 #include "components/policy/core/browser/browser_policy_connector.h" |
23 #include "components/policy/core/common/external_data_fetcher.h" | 24 #include "components/policy/core/common/external_data_fetcher.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 } | 89 } |
89 } else { | 90 } else { |
90 LOG(WARNING) << "Unknown or invalid policy schema for " << policy_name | 91 LOG(WARNING) << "Unknown or invalid policy schema for " << policy_name |
91 << "."; | 92 << "."; |
92 return std::unique_ptr<base::Value>(); | 93 return std::unique_ptr<base::Value>(); |
93 } | 94 } |
94 | 95 |
95 return root; | 96 return root; |
96 } | 97 } |
97 | 98 |
98 base::Value* DecodeConnectionType(int value) { | 99 std::unique_ptr<base::Value> DecodeConnectionType(int value) { |
99 static const char* const kConnectionTypes[] = { | 100 static const char* const kConnectionTypes[] = { |
100 shill::kTypeEthernet, | 101 shill::kTypeEthernet, |
101 shill::kTypeWifi, | 102 shill::kTypeWifi, |
102 shill::kTypeWimax, | 103 shill::kTypeWimax, |
103 shill::kTypeBluetooth, | 104 shill::kTypeBluetooth, |
104 shill::kTypeCellular, | 105 shill::kTypeCellular, |
105 }; | 106 }; |
106 | 107 |
107 if (value < 0 || value >= static_cast<int>(arraysize(kConnectionTypes))) | 108 if (value < 0 || value >= static_cast<int>(arraysize(kConnectionTypes))) |
108 return NULL; | 109 return nullptr; |
109 | 110 |
110 return new base::StringValue(kConnectionTypes[value]); | 111 return base::WrapUnique(new base::StringValue(kConnectionTypes[value])); |
111 } | 112 } |
112 | 113 |
113 void DecodeLoginPolicies(const em::ChromeDeviceSettingsProto& policy, | 114 void DecodeLoginPolicies(const em::ChromeDeviceSettingsProto& policy, |
114 PolicyMap* policies) { | 115 PolicyMap* policies) { |
115 if (policy.has_guest_mode_enabled()) { | 116 if (policy.has_guest_mode_enabled()) { |
116 const em::GuestModeEnabledProto& container(policy.guest_mode_enabled()); | 117 const em::GuestModeEnabledProto& container(policy.guest_mode_enabled()); |
117 if (container.has_guest_mode_enabled()) { | 118 if (container.has_guest_mode_enabled()) { |
118 policies->Set(key::kDeviceGuestModeEnabled, | 119 policies->Set(key::kDeviceGuestModeEnabled, POLICY_LEVEL_MANDATORY, |
119 POLICY_LEVEL_MANDATORY, | 120 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
120 POLICY_SCOPE_MACHINE, | 121 base::WrapUnique(new base::FundamentalValue( |
121 POLICY_SOURCE_CLOUD, | 122 container.guest_mode_enabled())), |
122 new base::FundamentalValue( | 123 nullptr); |
123 container.guest_mode_enabled()), | |
124 NULL); | |
125 } | 124 } |
126 } | 125 } |
127 | 126 |
128 if (policy.has_reboot_on_shutdown()) { | 127 if (policy.has_reboot_on_shutdown()) { |
129 const em::RebootOnShutdownProto& container(policy.reboot_on_shutdown()); | 128 const em::RebootOnShutdownProto& container(policy.reboot_on_shutdown()); |
130 if (container.has_reboot_on_shutdown()) { | 129 if (container.has_reboot_on_shutdown()) { |
131 policies->Set(key::kDeviceRebootOnShutdown, POLICY_LEVEL_MANDATORY, | 130 policies->Set(key::kDeviceRebootOnShutdown, POLICY_LEVEL_MANDATORY, |
132 POLICY_SCOPE_MACHINE, | 131 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
133 POLICY_SOURCE_CLOUD, | 132 base::WrapUnique(new base::FundamentalValue( |
134 new base::FundamentalValue(container.reboot_on_shutdown()), | 133 container.reboot_on_shutdown())), |
135 NULL); | 134 nullptr); |
136 } | 135 } |
137 } | 136 } |
138 | 137 |
139 if (policy.has_show_user_names()) { | 138 if (policy.has_show_user_names()) { |
140 const em::ShowUserNamesOnSigninProto& container(policy.show_user_names()); | 139 const em::ShowUserNamesOnSigninProto& container(policy.show_user_names()); |
141 if (container.has_show_user_names()) { | 140 if (container.has_show_user_names()) { |
142 policies->Set(key::kDeviceShowUserNamesOnSignin, | 141 policies->Set(key::kDeviceShowUserNamesOnSignin, POLICY_LEVEL_MANDATORY, |
143 POLICY_LEVEL_MANDATORY, | 142 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
144 POLICY_SCOPE_MACHINE, | 143 base::WrapUnique(new base::FundamentalValue( |
145 POLICY_SOURCE_CLOUD, | 144 container.show_user_names())), |
146 new base::FundamentalValue( | 145 nullptr); |
147 container.show_user_names()), | |
148 NULL); | |
149 } | 146 } |
150 } | 147 } |
151 | 148 |
152 if (policy.has_allow_new_users()) { | 149 if (policy.has_allow_new_users()) { |
153 const em::AllowNewUsersProto& container(policy.allow_new_users()); | 150 const em::AllowNewUsersProto& container(policy.allow_new_users()); |
154 if (container.has_allow_new_users()) { | 151 if (container.has_allow_new_users()) { |
155 policies->Set(key::kDeviceAllowNewUsers, | 152 policies->Set(key::kDeviceAllowNewUsers, POLICY_LEVEL_MANDATORY, |
156 POLICY_LEVEL_MANDATORY, | 153 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
157 POLICY_SCOPE_MACHINE, | 154 base::WrapUnique(new base::FundamentalValue( |
158 POLICY_SOURCE_CLOUD, | 155 container.allow_new_users())), |
159 new base::FundamentalValue( | 156 nullptr); |
160 container.allow_new_users()), | |
161 NULL); | |
162 } | 157 } |
163 } | 158 } |
164 | 159 |
165 if (policy.has_user_whitelist()) { | 160 if (policy.has_user_whitelist()) { |
166 const em::UserWhitelistProto& container(policy.user_whitelist()); | 161 const em::UserWhitelistProto& container(policy.user_whitelist()); |
167 base::ListValue* whitelist = new base::ListValue(); | 162 std::unique_ptr<base::ListValue> whitelist(new base::ListValue); |
168 RepeatedPtrField<std::string>::const_iterator entry; | 163 for (const auto& entry : container.user_whitelist()) |
169 for (entry = container.user_whitelist().begin(); | 164 whitelist->Append(new base::StringValue(entry)); |
170 entry != container.user_whitelist().end(); | 165 policies->Set(key::kDeviceUserWhitelist, POLICY_LEVEL_MANDATORY, |
171 ++entry) { | 166 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
172 whitelist->Append(new base::StringValue(*entry)); | 167 std::move(whitelist), nullptr); |
173 } | |
174 policies->Set(key::kDeviceUserWhitelist, | |
175 POLICY_LEVEL_MANDATORY, | |
176 POLICY_SCOPE_MACHINE, | |
177 POLICY_SOURCE_CLOUD, | |
178 whitelist, | |
179 NULL); | |
180 } | 168 } |
181 | 169 |
182 if (policy.has_ephemeral_users_enabled()) { | 170 if (policy.has_ephemeral_users_enabled()) { |
183 const em::EphemeralUsersEnabledProto& container( | 171 const em::EphemeralUsersEnabledProto& container( |
184 policy.ephemeral_users_enabled()); | 172 policy.ephemeral_users_enabled()); |
185 if (container.has_ephemeral_users_enabled()) { | 173 if (container.has_ephemeral_users_enabled()) { |
186 policies->Set(key::kDeviceEphemeralUsersEnabled, | 174 policies->Set(key::kDeviceEphemeralUsersEnabled, POLICY_LEVEL_MANDATORY, |
187 POLICY_LEVEL_MANDATORY, | 175 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
188 POLICY_SCOPE_MACHINE, | 176 base::WrapUnique(new base::FundamentalValue( |
189 POLICY_SOURCE_CLOUD, | 177 container.ephemeral_users_enabled())), |
190 new base::FundamentalValue( | 178 nullptr); |
191 container.ephemeral_users_enabled()), | |
192 NULL); | |
193 } | 179 } |
194 } | 180 } |
195 | 181 |
196 if (policy.has_device_local_accounts()) { | 182 if (policy.has_device_local_accounts()) { |
197 const em::DeviceLocalAccountsProto& container( | 183 const em::DeviceLocalAccountsProto& container( |
198 policy.device_local_accounts()); | 184 policy.device_local_accounts()); |
199 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = | 185 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = |
200 container.account(); | 186 container.account(); |
201 std::unique_ptr<base::ListValue> account_list(new base::ListValue()); | 187 std::unique_ptr<base::ListValue> account_list(new base::ListValue()); |
202 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry; | 188 for (const auto& entry : accounts) { |
203 for (entry = accounts.begin(); entry != accounts.end(); ++entry) { | |
204 std::unique_ptr<base::DictionaryValue> entry_dict( | 189 std::unique_ptr<base::DictionaryValue> entry_dict( |
205 new base::DictionaryValue()); | 190 new base::DictionaryValue()); |
206 if (entry->has_type()) { | 191 if (entry.has_type()) { |
207 if (entry->has_account_id()) { | 192 if (entry.has_account_id()) { |
208 entry_dict->SetStringWithoutPathExpansion( | 193 entry_dict->SetStringWithoutPathExpansion( |
209 chromeos::kAccountsPrefDeviceLocalAccountsKeyId, | 194 chromeos::kAccountsPrefDeviceLocalAccountsKeyId, |
210 entry->account_id()); | 195 entry.account_id()); |
211 } | 196 } |
212 entry_dict->SetIntegerWithoutPathExpansion( | 197 entry_dict->SetIntegerWithoutPathExpansion( |
213 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, entry->type()); | 198 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, entry.type()); |
214 if (entry->kiosk_app().has_app_id()) { | 199 if (entry.kiosk_app().has_app_id()) { |
215 entry_dict->SetStringWithoutPathExpansion( | 200 entry_dict->SetStringWithoutPathExpansion( |
216 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId, | 201 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId, |
217 entry->kiosk_app().app_id()); | 202 entry.kiosk_app().app_id()); |
218 } | 203 } |
219 if (entry->kiosk_app().has_update_url()) { | 204 if (entry.kiosk_app().has_update_url()) { |
220 entry_dict->SetStringWithoutPathExpansion( | 205 entry_dict->SetStringWithoutPathExpansion( |
221 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL, | 206 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL, |
222 entry->kiosk_app().update_url()); | 207 entry.kiosk_app().update_url()); |
223 } | 208 } |
224 } else if (entry->has_deprecated_public_session_id()) { | 209 } else if (entry.has_deprecated_public_session_id()) { |
225 // Deprecated public session specification. | 210 // Deprecated public session specification. |
226 entry_dict->SetStringWithoutPathExpansion( | 211 entry_dict->SetStringWithoutPathExpansion( |
227 chromeos::kAccountsPrefDeviceLocalAccountsKeyId, | 212 chromeos::kAccountsPrefDeviceLocalAccountsKeyId, |
228 entry->deprecated_public_session_id()); | 213 entry.deprecated_public_session_id()); |
229 entry_dict->SetIntegerWithoutPathExpansion( | 214 entry_dict->SetIntegerWithoutPathExpansion( |
230 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, | 215 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, |
231 DeviceLocalAccount::TYPE_PUBLIC_SESSION); | 216 DeviceLocalAccount::TYPE_PUBLIC_SESSION); |
232 } | 217 } |
233 account_list->Append(entry_dict.release()); | 218 account_list->Append(std::move(entry_dict)); |
234 } | 219 } |
235 policies->Set(key::kDeviceLocalAccounts, | 220 policies->Set(key::kDeviceLocalAccounts, POLICY_LEVEL_MANDATORY, |
236 POLICY_LEVEL_MANDATORY, | 221 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
237 POLICY_SCOPE_MACHINE, | 222 std::move(account_list), nullptr); |
238 POLICY_SOURCE_CLOUD, | |
239 account_list.release(), | |
240 NULL); | |
241 if (container.has_auto_login_id()) { | 223 if (container.has_auto_login_id()) { |
242 policies->Set(key::kDeviceLocalAccountAutoLoginId, | 224 policies->Set( |
243 POLICY_LEVEL_MANDATORY, | 225 key::kDeviceLocalAccountAutoLoginId, POLICY_LEVEL_MANDATORY, |
244 POLICY_SCOPE_MACHINE, | 226 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
245 POLICY_SOURCE_CLOUD, | 227 base::WrapUnique(new base::StringValue(container.auto_login_id())), |
246 new base::StringValue(container.auto_login_id()), | 228 nullptr); |
247 NULL); | |
248 } | 229 } |
249 if (container.has_auto_login_delay()) { | 230 if (container.has_auto_login_delay()) { |
250 policies->Set(key::kDeviceLocalAccountAutoLoginDelay, | 231 policies->Set(key::kDeviceLocalAccountAutoLoginDelay, |
251 POLICY_LEVEL_MANDATORY, | 232 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
252 POLICY_SCOPE_MACHINE, | |
253 POLICY_SOURCE_CLOUD, | 233 POLICY_SOURCE_CLOUD, |
254 DecodeIntegerValue(container.auto_login_delay()).release(), | 234 DecodeIntegerValue(container.auto_login_delay()), nullptr); |
255 NULL); | |
256 } | 235 } |
257 if (container.has_enable_auto_login_bailout()) { | 236 if (container.has_enable_auto_login_bailout()) { |
258 policies->Set(key::kDeviceLocalAccountAutoLoginBailoutEnabled, | 237 policies->Set(key::kDeviceLocalAccountAutoLoginBailoutEnabled, |
259 POLICY_LEVEL_MANDATORY, | 238 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
260 POLICY_SCOPE_MACHINE, | |
261 POLICY_SOURCE_CLOUD, | 239 POLICY_SOURCE_CLOUD, |
262 new base::FundamentalValue( | 240 base::WrapUnique(new base::FundamentalValue( |
263 container.enable_auto_login_bailout()), | 241 container.enable_auto_login_bailout())), |
264 NULL); | 242 nullptr); |
265 } | 243 } |
266 if (container.has_prompt_for_network_when_offline()) { | 244 if (container.has_prompt_for_network_when_offline()) { |
267 policies->Set(key::kDeviceLocalAccountPromptForNetworkWhenOffline, | 245 policies->Set(key::kDeviceLocalAccountPromptForNetworkWhenOffline, |
268 POLICY_LEVEL_MANDATORY, | 246 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
269 POLICY_SCOPE_MACHINE, | |
270 POLICY_SOURCE_CLOUD, | 247 POLICY_SOURCE_CLOUD, |
271 new base::FundamentalValue( | 248 base::WrapUnique(new base::FundamentalValue( |
272 container.prompt_for_network_when_offline()), | 249 container.prompt_for_network_when_offline())), |
273 NULL); | 250 nullptr); |
274 } | 251 } |
275 } | 252 } |
276 | 253 |
277 if (policy.has_supervised_users_settings()) { | 254 if (policy.has_supervised_users_settings()) { |
278 const em::SupervisedUsersSettingsProto& container = | 255 const em::SupervisedUsersSettingsProto& container = |
279 policy.supervised_users_settings(); | 256 policy.supervised_users_settings(); |
280 if (container.has_supervised_users_enabled()) { | 257 if (container.has_supervised_users_enabled()) { |
281 base::Value* value = new base::FundamentalValue( | 258 policies->Set(key::kSupervisedUsersEnabled, POLICY_LEVEL_MANDATORY, |
282 container.supervised_users_enabled()); | 259 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
283 policies->Set(key::kSupervisedUsersEnabled, | 260 base::WrapUnique(new base::FundamentalValue( |
284 POLICY_LEVEL_MANDATORY, | 261 container.supervised_users_enabled())), |
285 POLICY_SCOPE_MACHINE, | 262 nullptr); |
286 POLICY_SOURCE_CLOUD, | |
287 value, | |
288 NULL); | |
289 } | 263 } |
290 } | 264 } |
291 | 265 |
292 if (policy.has_saml_settings()) { | 266 if (policy.has_saml_settings()) { |
293 const em::SAMLSettingsProto& container(policy.saml_settings()); | 267 const em::SAMLSettingsProto& container(policy.saml_settings()); |
294 if (container.has_transfer_saml_cookies()) { | 268 if (container.has_transfer_saml_cookies()) { |
295 policies->Set(key::kDeviceTransferSAMLCookies, | 269 policies->Set(key::kDeviceTransferSAMLCookies, POLICY_LEVEL_MANDATORY, |
296 POLICY_LEVEL_MANDATORY, | 270 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
297 POLICY_SCOPE_MACHINE, | 271 base::WrapUnique(new base::FundamentalValue( |
298 POLICY_SOURCE_CLOUD, | 272 container.transfer_saml_cookies())), |
299 new base::FundamentalValue( | 273 nullptr); |
300 container.transfer_saml_cookies()), | |
301 NULL); | |
302 } | 274 } |
303 } | 275 } |
304 | 276 |
305 if (policy.has_login_authentication_behavior()) { | 277 if (policy.has_login_authentication_behavior()) { |
306 const em::LoginAuthenticationBehaviorProto& container( | 278 const em::LoginAuthenticationBehaviorProto& container( |
307 policy.login_authentication_behavior()); | 279 policy.login_authentication_behavior()); |
308 if (container.has_login_authentication_behavior()) { | 280 if (container.has_login_authentication_behavior()) { |
309 policies->Set(key::kLoginAuthenticationBehavior, | 281 policies->Set( |
310 POLICY_LEVEL_MANDATORY, | 282 key::kLoginAuthenticationBehavior, POLICY_LEVEL_MANDATORY, |
311 POLICY_SCOPE_MACHINE, | 283 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
312 POLICY_SOURCE_CLOUD, | 284 DecodeIntegerValue(container.login_authentication_behavior()), |
313 DecodeIntegerValue( | 285 nullptr); |
314 container.login_authentication_behavior()).release(), | |
315 nullptr); | |
316 } | 286 } |
317 } | 287 } |
318 | 288 |
319 if (policy.has_allow_bluetooth()) { | 289 if (policy.has_allow_bluetooth()) { |
320 const em::AllowBluetoothProto& container(policy.allow_bluetooth()); | 290 const em::AllowBluetoothProto& container(policy.allow_bluetooth()); |
321 if (container.has_allow_bluetooth()) { | 291 if (container.has_allow_bluetooth()) { |
322 policies->Set(key::kDeviceAllowBluetooth, POLICY_LEVEL_MANDATORY, | 292 policies->Set(key::kDeviceAllowBluetooth, POLICY_LEVEL_MANDATORY, |
323 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, | 293 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
324 new base::FundamentalValue(container.allow_bluetooth()), | 294 base::WrapUnique(new base::FundamentalValue( |
295 container.allow_bluetooth())), | |
325 nullptr); | 296 nullptr); |
326 } | 297 } |
327 } | 298 } |
328 } | 299 } |
329 | 300 |
330 void DecodeNetworkPolicies(const em::ChromeDeviceSettingsProto& policy, | 301 void DecodeNetworkPolicies(const em::ChromeDeviceSettingsProto& policy, |
331 PolicyMap* policies) { | 302 PolicyMap* policies) { |
332 if (policy.has_data_roaming_enabled()) { | 303 if (policy.has_data_roaming_enabled()) { |
333 const em::DataRoamingEnabledProto& container(policy.data_roaming_enabled()); | 304 const em::DataRoamingEnabledProto& container(policy.data_roaming_enabled()); |
334 if (container.has_data_roaming_enabled()) { | 305 if (container.has_data_roaming_enabled()) { |
335 policies->Set(key::kDeviceDataRoamingEnabled, | 306 policies->Set(key::kDeviceDataRoamingEnabled, POLICY_LEVEL_MANDATORY, |
336 POLICY_LEVEL_MANDATORY, | 307 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
337 POLICY_SCOPE_MACHINE, | 308 base::WrapUnique(new base::FundamentalValue( |
338 POLICY_SOURCE_CLOUD, | 309 container.data_roaming_enabled())), |
339 new base::FundamentalValue( | 310 nullptr); |
340 container.data_roaming_enabled()), | |
341 NULL); | |
342 } | 311 } |
343 } | 312 } |
344 | 313 |
345 if (policy.has_open_network_configuration() && | 314 if (policy.has_open_network_configuration() && |
346 policy.open_network_configuration().has_open_network_configuration()) { | 315 policy.open_network_configuration().has_open_network_configuration()) { |
347 std::string config( | 316 std::string config( |
348 policy.open_network_configuration().open_network_configuration()); | 317 policy.open_network_configuration().open_network_configuration()); |
349 policies->Set(key::kDeviceOpenNetworkConfiguration, | 318 policies->Set(key::kDeviceOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, |
350 POLICY_LEVEL_MANDATORY, | 319 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
351 POLICY_SCOPE_MACHINE, | 320 base::WrapUnique(new base::StringValue(config)), nullptr); |
352 POLICY_SOURCE_CLOUD, | |
353 new base::StringValue(config), | |
354 NULL); | |
355 } | 321 } |
356 } | 322 } |
357 | 323 |
358 void DecodeReportingPolicies(const em::ChromeDeviceSettingsProto& policy, | 324 void DecodeReportingPolicies(const em::ChromeDeviceSettingsProto& policy, |
359 PolicyMap* policies) { | 325 PolicyMap* policies) { |
360 if (policy.has_device_reporting()) { | 326 if (policy.has_device_reporting()) { |
361 const em::DeviceReportingProto& container(policy.device_reporting()); | 327 const em::DeviceReportingProto& container(policy.device_reporting()); |
362 if (container.has_report_version_info()) { | 328 if (container.has_report_version_info()) { |
363 policies->Set(key::kReportDeviceVersionInfo, | 329 policies->Set(key::kReportDeviceVersionInfo, POLICY_LEVEL_MANDATORY, |
364 POLICY_LEVEL_MANDATORY, | 330 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
365 POLICY_SCOPE_MACHINE, | 331 base::WrapUnique(new base::FundamentalValue( |
366 POLICY_SOURCE_CLOUD, | 332 container.report_version_info())), |
367 new base::FundamentalValue( | 333 nullptr); |
368 container.report_version_info()), | |
369 NULL); | |
370 } | 334 } |
371 if (container.has_report_activity_times()) { | 335 if (container.has_report_activity_times()) { |
372 policies->Set(key::kReportDeviceActivityTimes, | 336 policies->Set(key::kReportDeviceActivityTimes, POLICY_LEVEL_MANDATORY, |
373 POLICY_LEVEL_MANDATORY, | 337 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
374 POLICY_SCOPE_MACHINE, | 338 base::WrapUnique(new base::FundamentalValue( |
375 POLICY_SOURCE_CLOUD, | 339 container.report_activity_times())), |
376 new base::FundamentalValue( | 340 nullptr); |
377 container.report_activity_times()), | |
378 NULL); | |
379 } | 341 } |
380 if (container.has_report_boot_mode()) { | 342 if (container.has_report_boot_mode()) { |
381 policies->Set(key::kReportDeviceBootMode, | 343 policies->Set(key::kReportDeviceBootMode, POLICY_LEVEL_MANDATORY, |
382 POLICY_LEVEL_MANDATORY, | 344 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
383 POLICY_SCOPE_MACHINE, | 345 base::WrapUnique(new base::FundamentalValue( |
384 POLICY_SOURCE_CLOUD, | 346 container.report_boot_mode())), |
385 new base::FundamentalValue( | 347 nullptr); |
386 container.report_boot_mode()), | |
387 NULL); | |
388 } | 348 } |
389 if (container.has_report_location()) { | 349 if (container.has_report_location()) { |
390 policies->Set(key::kReportDeviceLocation, | 350 policies->Set(key::kReportDeviceLocation, POLICY_LEVEL_MANDATORY, |
391 POLICY_LEVEL_MANDATORY, | 351 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
392 POLICY_SCOPE_MACHINE, | 352 base::WrapUnique(new base::FundamentalValue( |
393 POLICY_SOURCE_CLOUD, | 353 container.report_location())), |
394 new base::FundamentalValue( | 354 nullptr); |
395 container.report_location()), | |
396 NULL); | |
397 } | 355 } |
398 if (container.has_report_network_interfaces()) { | 356 if (container.has_report_network_interfaces()) { |
399 policies->Set(key::kReportDeviceNetworkInterfaces, | 357 policies->Set(key::kReportDeviceNetworkInterfaces, POLICY_LEVEL_MANDATORY, |
400 POLICY_LEVEL_MANDATORY, | 358 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
401 POLICY_SCOPE_MACHINE, | 359 base::WrapUnique(new base::FundamentalValue( |
402 POLICY_SOURCE_CLOUD, | 360 container.report_network_interfaces())), |
403 new base::FundamentalValue( | 361 nullptr); |
404 container.report_network_interfaces()), | |
405 NULL); | |
406 } | 362 } |
407 if (container.has_report_users()) { | 363 if (container.has_report_users()) { |
408 policies->Set(key::kReportDeviceUsers, | 364 policies->Set(key::kReportDeviceUsers, POLICY_LEVEL_MANDATORY, |
409 POLICY_LEVEL_MANDATORY, | 365 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
410 POLICY_SCOPE_MACHINE, | 366 base::WrapUnique( |
411 POLICY_SOURCE_CLOUD, | 367 new base::FundamentalValue(container.report_users())), |
412 new base::FundamentalValue(container.report_users()), | 368 nullptr); |
413 NULL); | |
414 } | 369 } |
415 if (container.has_report_hardware_status()) { | 370 if (container.has_report_hardware_status()) { |
416 policies->Set(key::kReportDeviceHardwareStatus, | 371 policies->Set(key::kReportDeviceHardwareStatus, POLICY_LEVEL_MANDATORY, |
417 POLICY_LEVEL_MANDATORY, | 372 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
418 POLICY_SCOPE_MACHINE, | 373 base::WrapUnique(new base::FundamentalValue( |
419 POLICY_SOURCE_CLOUD, | 374 container.report_hardware_status())), |
420 new base::FundamentalValue( | 375 nullptr); |
421 container.report_hardware_status()), | |
422 NULL); | |
423 } | 376 } |
424 if (container.has_report_session_status()) { | 377 if (container.has_report_session_status()) { |
425 policies->Set(key::kReportDeviceSessionStatus, | 378 policies->Set(key::kReportDeviceSessionStatus, POLICY_LEVEL_MANDATORY, |
426 POLICY_LEVEL_MANDATORY, | 379 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
427 POLICY_SCOPE_MACHINE, | 380 base::WrapUnique(new base::FundamentalValue( |
428 POLICY_SOURCE_CLOUD, | 381 container.report_session_status())), |
429 new base::FundamentalValue( | 382 nullptr); |
430 container.report_session_status()), | |
431 NULL); | |
432 } | 383 } |
433 if (container.has_device_status_frequency()) { | 384 if (container.has_device_status_frequency()) { |
434 policies->Set(key::kReportUploadFrequency, | 385 policies->Set(key::kReportUploadFrequency, POLICY_LEVEL_MANDATORY, |
435 POLICY_LEVEL_MANDATORY, | 386 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
436 POLICY_SCOPE_MACHINE, | 387 DecodeIntegerValue(container.device_status_frequency()), |
437 POLICY_SOURCE_CLOUD, | 388 nullptr); |
438 DecodeIntegerValue( | |
439 container.device_status_frequency()).release(), | |
440 NULL); | |
441 } | 389 } |
442 } | 390 } |
443 | 391 |
444 if (policy.has_device_heartbeat_settings()) { | 392 if (policy.has_device_heartbeat_settings()) { |
445 const em::DeviceHeartbeatSettingsProto& container( | 393 const em::DeviceHeartbeatSettingsProto& container( |
446 policy.device_heartbeat_settings()); | 394 policy.device_heartbeat_settings()); |
447 if (container.has_heartbeat_enabled()) { | 395 if (container.has_heartbeat_enabled()) { |
448 policies->Set(key::kHeartbeatEnabled, | 396 policies->Set(key::kHeartbeatEnabled, POLICY_LEVEL_MANDATORY, |
449 POLICY_LEVEL_MANDATORY, | 397 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
450 POLICY_SCOPE_MACHINE, | 398 base::WrapUnique(new base::FundamentalValue( |
451 POLICY_SOURCE_CLOUD, | 399 container.heartbeat_enabled())), |
452 new base::FundamentalValue( | 400 nullptr); |
453 container.heartbeat_enabled()), | |
454 NULL); | |
455 } | 401 } |
456 if (container.has_heartbeat_frequency()) { | 402 if (container.has_heartbeat_frequency()) { |
457 policies->Set(key::kHeartbeatFrequency, | 403 policies->Set(key::kHeartbeatFrequency, POLICY_LEVEL_MANDATORY, |
458 POLICY_LEVEL_MANDATORY, | 404 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
459 POLICY_SCOPE_MACHINE, | 405 DecodeIntegerValue(container.heartbeat_frequency()), |
460 POLICY_SOURCE_CLOUD, | 406 nullptr); |
461 DecodeIntegerValue( | |
462 container.heartbeat_frequency()).release(), | |
463 NULL); | |
464 } | 407 } |
465 } | 408 } |
466 | 409 |
467 if (policy.has_device_log_upload_settings()) { | 410 if (policy.has_device_log_upload_settings()) { |
468 const em::DeviceLogUploadSettingsProto& container( | 411 const em::DeviceLogUploadSettingsProto& container( |
469 policy.device_log_upload_settings()); | 412 policy.device_log_upload_settings()); |
470 if (container.has_system_log_upload_enabled()) { | 413 if (container.has_system_log_upload_enabled()) { |
471 policies->Set( | 414 policies->Set(key::kLogUploadEnabled, POLICY_LEVEL_MANDATORY, |
472 key::kLogUploadEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 415 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
473 POLICY_SOURCE_CLOUD, | 416 base::WrapUnique(new base::FundamentalValue( |
474 new base::FundamentalValue(container.system_log_upload_enabled()), | 417 container.system_log_upload_enabled())), |
475 NULL); | 418 nullptr); |
476 } | 419 } |
477 } | 420 } |
478 } | 421 } |
479 | 422 |
480 void DecodeAutoUpdatePolicies(const em::ChromeDeviceSettingsProto& policy, | 423 void DecodeAutoUpdatePolicies(const em::ChromeDeviceSettingsProto& policy, |
481 PolicyMap* policies) { | 424 PolicyMap* policies) { |
482 if (policy.has_release_channel()) { | 425 if (policy.has_release_channel()) { |
483 const em::ReleaseChannelProto& container(policy.release_channel()); | 426 const em::ReleaseChannelProto& container(policy.release_channel()); |
484 if (container.has_release_channel()) { | 427 if (container.has_release_channel()) { |
485 std::string channel(container.release_channel()); | 428 std::string channel(container.release_channel()); |
486 policies->Set(key::kChromeOsReleaseChannel, | 429 policies->Set(key::kChromeOsReleaseChannel, POLICY_LEVEL_MANDATORY, |
487 POLICY_LEVEL_MANDATORY, | 430 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
488 POLICY_SCOPE_MACHINE, | 431 base::WrapUnique(new base::StringValue(channel)), nullptr); |
489 POLICY_SOURCE_CLOUD, | |
490 new base::StringValue(channel), | |
491 NULL); | |
492 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't | 432 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't |
493 // have to pass the channel in here, only ping the update engine to tell | 433 // have to pass the channel in here, only ping the update engine to tell |
494 // it to fetch the channel from the policy. | 434 // it to fetch the channel from the policy. |
495 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()-> | 435 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()-> |
496 SetChannel(channel, false); | 436 SetChannel(channel, false); |
497 } | 437 } |
498 if (container.has_release_channel_delegated()) { | 438 if (container.has_release_channel_delegated()) { |
499 policies->Set(key::kChromeOsReleaseChannelDelegated, | 439 policies->Set(key::kChromeOsReleaseChannelDelegated, |
500 POLICY_LEVEL_MANDATORY, | 440 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
501 POLICY_SCOPE_MACHINE, | |
502 POLICY_SOURCE_CLOUD, | 441 POLICY_SOURCE_CLOUD, |
503 new base::FundamentalValue( | 442 base::WrapUnique(new base::FundamentalValue( |
504 container.release_channel_delegated()), | 443 container.release_channel_delegated())), |
505 NULL); | 444 nullptr); |
506 } | 445 } |
507 } | 446 } |
508 | 447 |
509 if (policy.has_auto_update_settings()) { | 448 if (policy.has_auto_update_settings()) { |
510 const em::AutoUpdateSettingsProto& container(policy.auto_update_settings()); | 449 const em::AutoUpdateSettingsProto& container(policy.auto_update_settings()); |
511 if (container.has_update_disabled()) { | 450 if (container.has_update_disabled()) { |
512 policies->Set(key::kDeviceAutoUpdateDisabled, | 451 policies->Set(key::kDeviceAutoUpdateDisabled, POLICY_LEVEL_MANDATORY, |
513 POLICY_LEVEL_MANDATORY, | 452 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
514 POLICY_SCOPE_MACHINE, | 453 base::WrapUnique(new base::FundamentalValue( |
515 POLICY_SOURCE_CLOUD, | 454 container.update_disabled())), |
516 new base::FundamentalValue( | 455 nullptr); |
517 container.update_disabled()), | |
518 NULL); | |
519 } | 456 } |
520 | 457 |
521 if (container.has_target_version_prefix()) { | 458 if (container.has_target_version_prefix()) { |
522 policies->Set(key::kDeviceTargetVersionPrefix, | 459 policies->Set(key::kDeviceTargetVersionPrefix, POLICY_LEVEL_MANDATORY, |
523 POLICY_LEVEL_MANDATORY, | 460 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
524 POLICY_SCOPE_MACHINE, | 461 base::WrapUnique(new base::StringValue( |
525 POLICY_SOURCE_CLOUD, | 462 container.target_version_prefix())), |
526 new base::StringValue( | 463 nullptr); |
527 container.target_version_prefix()), | |
528 NULL); | |
529 } | 464 } |
530 | 465 |
531 // target_version_display_name is not actually a policy, but a display | 466 // target_version_display_name is not actually a policy, but a display |
532 // string for target_version_prefix, so we ignore it. | 467 // string for target_version_prefix, so we ignore it. |
533 | 468 |
534 if (container.has_scatter_factor_in_seconds()) { | 469 if (container.has_scatter_factor_in_seconds()) { |
535 policies->Set(key::kDeviceUpdateScatterFactor, | 470 // TODO(dcheng): Shouldn't this use DecodeIntegerValue? |
dcheng
2016/05/03 06:46:18
This looks pretty sketchy. Can I assign this TODO
| |
536 POLICY_LEVEL_MANDATORY, | 471 policies->Set( |
537 POLICY_SCOPE_MACHINE, | 472 key::kDeviceUpdateScatterFactor, POLICY_LEVEL_MANDATORY, |
538 POLICY_SOURCE_CLOUD, | 473 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
539 new base::FundamentalValue(static_cast<int>( | 474 base::WrapUnique(new base::FundamentalValue( |
540 container.scatter_factor_in_seconds())), | 475 static_cast<int>(container.scatter_factor_in_seconds()))), |
541 NULL); | 476 nullptr); |
542 } | 477 } |
543 | 478 |
544 if (container.allowed_connection_types_size()) { | 479 if (container.allowed_connection_types_size()) { |
545 base::ListValue* allowed_connection_types = new base::ListValue(); | 480 std::unique_ptr<base::ListValue> allowed_connection_types( |
546 RepeatedField<int>::const_iterator entry; | 481 new base::ListValue); |
547 for (entry = container.allowed_connection_types().begin(); | 482 for (const auto& entry : container.allowed_connection_types()) { |
548 entry != container.allowed_connection_types().end(); | 483 std::unique_ptr<base::Value> value = DecodeConnectionType(entry); |
549 ++entry) { | |
550 base::Value* value = DecodeConnectionType(*entry); | |
551 if (value) | 484 if (value) |
552 allowed_connection_types->Append(value); | 485 allowed_connection_types->Append(std::move(value)); |
553 } | 486 } |
554 policies->Set(key::kDeviceUpdateAllowedConnectionTypes, | 487 policies->Set(key::kDeviceUpdateAllowedConnectionTypes, |
555 POLICY_LEVEL_MANDATORY, | 488 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
556 POLICY_SCOPE_MACHINE, | 489 POLICY_SOURCE_CLOUD, std::move(allowed_connection_types), |
557 POLICY_SOURCE_CLOUD, | 490 nullptr); |
558 allowed_connection_types, | |
559 NULL); | |
560 } | 491 } |
561 | 492 |
562 if (container.has_http_downloads_enabled()) { | 493 if (container.has_http_downloads_enabled()) { |
563 policies->Set( | 494 policies->Set( |
564 key::kDeviceUpdateHttpDownloadsEnabled, | 495 key::kDeviceUpdateHttpDownloadsEnabled, POLICY_LEVEL_MANDATORY, |
565 POLICY_LEVEL_MANDATORY, | 496 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
566 POLICY_SCOPE_MACHINE, | 497 base::WrapUnique( |
567 POLICY_SOURCE_CLOUD, | 498 new base::FundamentalValue(container.http_downloads_enabled())), |
568 new base::FundamentalValue(container.http_downloads_enabled()), | 499 nullptr); |
569 NULL); | |
570 } | 500 } |
571 | 501 |
572 if (container.has_reboot_after_update()) { | 502 if (container.has_reboot_after_update()) { |
573 policies->Set(key::kRebootAfterUpdate, | 503 policies->Set(key::kRebootAfterUpdate, POLICY_LEVEL_MANDATORY, |
574 POLICY_LEVEL_MANDATORY, | 504 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
575 POLICY_SCOPE_MACHINE, | 505 base::WrapUnique(new base::FundamentalValue( |
576 POLICY_SOURCE_CLOUD, | 506 container.reboot_after_update())), |
577 new base::FundamentalValue( | 507 nullptr); |
578 container.reboot_after_update()), | |
579 NULL); | |
580 } | 508 } |
581 | 509 |
582 if (container.has_p2p_enabled()) { | 510 if (container.has_p2p_enabled()) { |
583 policies->Set(key::kDeviceAutoUpdateP2PEnabled, | 511 policies->Set( |
584 POLICY_LEVEL_MANDATORY, | 512 key::kDeviceAutoUpdateP2PEnabled, POLICY_LEVEL_MANDATORY, |
585 POLICY_SCOPE_MACHINE, | 513 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
586 POLICY_SOURCE_CLOUD, | 514 base::WrapUnique(new base::FundamentalValue(container.p2p_enabled())), |
587 new base::FundamentalValue(container.p2p_enabled()), | 515 nullptr); |
588 NULL); | |
589 } | 516 } |
590 } | 517 } |
591 | 518 |
592 if (policy.has_allow_kiosk_app_control_chrome_version()) { | 519 if (policy.has_allow_kiosk_app_control_chrome_version()) { |
593 const em::AllowKioskAppControlChromeVersionProto& container( | 520 const em::AllowKioskAppControlChromeVersionProto& container( |
594 policy.allow_kiosk_app_control_chrome_version()); | 521 policy.allow_kiosk_app_control_chrome_version()); |
595 if (container.has_allow_kiosk_app_control_chrome_version()) { | 522 if (container.has_allow_kiosk_app_control_chrome_version()) { |
596 policies->Set(key::kAllowKioskAppControlChromeVersion, | 523 policies->Set(key::kAllowKioskAppControlChromeVersion, |
597 POLICY_LEVEL_MANDATORY, | 524 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
598 POLICY_SCOPE_MACHINE, | |
599 POLICY_SOURCE_CLOUD, | 525 POLICY_SOURCE_CLOUD, |
600 new base::FundamentalValue( | 526 base::WrapUnique(new base::FundamentalValue( |
601 container.allow_kiosk_app_control_chrome_version()), | 527 container.allow_kiosk_app_control_chrome_version())), |
602 NULL); | 528 nullptr); |
603 } | 529 } |
604 } | 530 } |
605 } | 531 } |
606 | 532 |
607 void DecodeAccessibilityPolicies(const em::ChromeDeviceSettingsProto& policy, | 533 void DecodeAccessibilityPolicies(const em::ChromeDeviceSettingsProto& policy, |
608 PolicyMap* policies) { | 534 PolicyMap* policies) { |
609 if (policy.has_accessibility_settings()) { | 535 if (policy.has_accessibility_settings()) { |
610 const em::AccessibilitySettingsProto& | 536 const em::AccessibilitySettingsProto& |
611 container(policy.accessibility_settings()); | 537 container(policy.accessibility_settings()); |
612 | 538 |
613 if (container.has_login_screen_default_large_cursor_enabled()) { | 539 if (container.has_login_screen_default_large_cursor_enabled()) { |
614 policies->Set( | 540 policies->Set(key::kDeviceLoginScreenDefaultLargeCursorEnabled, |
615 key::kDeviceLoginScreenDefaultLargeCursorEnabled, | 541 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
616 POLICY_LEVEL_MANDATORY, | 542 POLICY_SOURCE_CLOUD, |
617 POLICY_SCOPE_MACHINE, | 543 base::WrapUnique(new base::FundamentalValue( |
618 POLICY_SOURCE_CLOUD, | 544 container.login_screen_default_large_cursor_enabled())), |
619 new base::FundamentalValue( | 545 nullptr); |
620 container.login_screen_default_large_cursor_enabled()), | |
621 NULL); | |
622 } | 546 } |
623 | 547 |
624 if (container.has_login_screen_default_spoken_feedback_enabled()) { | 548 if (container.has_login_screen_default_spoken_feedback_enabled()) { |
625 policies->Set( | 549 policies->Set( |
626 key::kDeviceLoginScreenDefaultSpokenFeedbackEnabled, | 550 key::kDeviceLoginScreenDefaultSpokenFeedbackEnabled, |
627 POLICY_LEVEL_MANDATORY, | 551 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
628 POLICY_SCOPE_MACHINE, | 552 base::WrapUnique(new base::FundamentalValue( |
629 POLICY_SOURCE_CLOUD, | 553 container.login_screen_default_spoken_feedback_enabled())), |
630 new base::FundamentalValue( | 554 nullptr); |
631 container.login_screen_default_spoken_feedback_enabled()), | |
632 NULL); | |
633 } | 555 } |
634 | 556 |
635 if (container.has_login_screen_default_high_contrast_enabled()) { | 557 if (container.has_login_screen_default_high_contrast_enabled()) { |
636 policies->Set( | 558 policies->Set( |
637 key::kDeviceLoginScreenDefaultHighContrastEnabled, | 559 key::kDeviceLoginScreenDefaultHighContrastEnabled, |
638 POLICY_LEVEL_MANDATORY, | 560 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
639 POLICY_SCOPE_MACHINE, | 561 base::WrapUnique(new base::FundamentalValue( |
640 POLICY_SOURCE_CLOUD, | 562 container.login_screen_default_high_contrast_enabled())), |
641 new base::FundamentalValue( | 563 nullptr); |
642 container.login_screen_default_high_contrast_enabled()), | |
643 NULL); | |
644 } | 564 } |
645 | 565 |
646 if (container.has_login_screen_default_screen_magnifier_type()) { | 566 if (container.has_login_screen_default_screen_magnifier_type()) { |
647 policies->Set( | 567 policies->Set(key::kDeviceLoginScreenDefaultScreenMagnifierType, |
648 key::kDeviceLoginScreenDefaultScreenMagnifierType, | 568 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
649 POLICY_LEVEL_MANDATORY, | 569 POLICY_SOURCE_CLOUD, |
650 POLICY_SCOPE_MACHINE, | 570 DecodeIntegerValue( |
651 POLICY_SOURCE_CLOUD, | 571 container.login_screen_default_screen_magnifier_type()), |
652 DecodeIntegerValue( | 572 nullptr); |
653 container.login_screen_default_screen_magnifier_type()).release(), | |
654 NULL); | |
655 } | 573 } |
656 | 574 |
657 if (container.has_login_screen_default_virtual_keyboard_enabled()) { | 575 if (container.has_login_screen_default_virtual_keyboard_enabled()) { |
658 policies->Set( | 576 policies->Set( |
659 key::kDeviceLoginScreenDefaultVirtualKeyboardEnabled, | 577 key::kDeviceLoginScreenDefaultVirtualKeyboardEnabled, |
660 POLICY_LEVEL_MANDATORY, | 578 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
661 POLICY_SCOPE_MACHINE, | 579 base::WrapUnique(new base::FundamentalValue( |
662 POLICY_SOURCE_CLOUD, | 580 container.login_screen_default_virtual_keyboard_enabled())), |
663 new base::FundamentalValue( | 581 nullptr); |
664 container.login_screen_default_virtual_keyboard_enabled()), | |
665 NULL); | |
666 } | 582 } |
667 } | 583 } |
668 } | 584 } |
669 | 585 |
670 void DecodeGenericPolicies(const em::ChromeDeviceSettingsProto& policy, | 586 void DecodeGenericPolicies(const em::ChromeDeviceSettingsProto& policy, |
671 PolicyMap* policies) { | 587 PolicyMap* policies) { |
672 if (policy.has_device_policy_refresh_rate()) { | 588 if (policy.has_device_policy_refresh_rate()) { |
673 const em::DevicePolicyRefreshRateProto& container( | 589 const em::DevicePolicyRefreshRateProto& container( |
674 policy.device_policy_refresh_rate()); | 590 policy.device_policy_refresh_rate()); |
675 if (container.has_device_policy_refresh_rate()) { | 591 if (container.has_device_policy_refresh_rate()) { |
676 policies->Set( | 592 policies->Set(key::kDevicePolicyRefreshRate, POLICY_LEVEL_MANDATORY, |
677 key::kDevicePolicyRefreshRate, | 593 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
678 POLICY_LEVEL_MANDATORY, | 594 DecodeIntegerValue(container.device_policy_refresh_rate()), |
679 POLICY_SCOPE_MACHINE, | 595 nullptr); |
680 POLICY_SOURCE_CLOUD, | |
681 DecodeIntegerValue(container.device_policy_refresh_rate()).release(), | |
682 NULL); | |
683 } | 596 } |
684 } | 597 } |
685 | 598 |
686 if (policy.has_metrics_enabled()) { | 599 if (policy.has_metrics_enabled()) { |
687 const em::MetricsEnabledProto& container(policy.metrics_enabled()); | 600 const em::MetricsEnabledProto& container(policy.metrics_enabled()); |
688 if (container.has_metrics_enabled()) { | 601 if (container.has_metrics_enabled()) { |
689 policies->Set(key::kDeviceMetricsReportingEnabled, | 602 policies->Set(key::kDeviceMetricsReportingEnabled, POLICY_LEVEL_MANDATORY, |
690 POLICY_LEVEL_MANDATORY, | 603 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
691 POLICY_SCOPE_MACHINE, | 604 base::WrapUnique(new base::FundamentalValue( |
692 POLICY_SOURCE_CLOUD, | 605 container.metrics_enabled())), |
693 new base::FundamentalValue( | 606 nullptr); |
694 container.metrics_enabled()), | |
695 NULL); | |
696 } | 607 } |
697 } | 608 } |
698 | 609 |
699 if (policy.has_system_timezone()) { | 610 if (policy.has_system_timezone()) { |
700 if (policy.system_timezone().has_timezone()) { | 611 if (policy.system_timezone().has_timezone()) { |
701 policies->Set(key::kSystemTimezone, | 612 policies->Set(key::kSystemTimezone, POLICY_LEVEL_MANDATORY, |
702 POLICY_LEVEL_MANDATORY, | 613 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
703 POLICY_SCOPE_MACHINE, | 614 base::WrapUnique(new base::StringValue( |
704 POLICY_SOURCE_CLOUD, | 615 policy.system_timezone().timezone())), |
705 new base::StringValue( | 616 nullptr); |
706 policy.system_timezone().timezone()), | |
707 NULL); | |
708 } | 617 } |
709 | 618 |
710 if (policy.system_timezone().has_timezone_detection_type()) { | 619 if (policy.system_timezone().has_timezone_detection_type()) { |
711 std::unique_ptr<base::Value> value(DecodeIntegerValue( | 620 std::unique_ptr<base::Value> value(DecodeIntegerValue( |
712 policy.system_timezone().timezone_detection_type())); | 621 policy.system_timezone().timezone_detection_type())); |
713 if (value) { | 622 if (value) { |
714 policies->Set(key::kSystemTimezoneAutomaticDetection, | 623 policies->Set(key::kSystemTimezoneAutomaticDetection, |
715 POLICY_LEVEL_MANDATORY, | 624 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
716 POLICY_SCOPE_MACHINE, | 625 POLICY_SOURCE_CLOUD, std::move(value), nullptr); |
717 POLICY_SOURCE_CLOUD, | |
718 value.release(), | |
719 nullptr); | |
720 } | 626 } |
721 } | 627 } |
722 } | 628 } |
723 | 629 |
724 if (policy.has_use_24hour_clock()) { | 630 if (policy.has_use_24hour_clock()) { |
725 if (policy.use_24hour_clock().has_use_24hour_clock()) { | 631 if (policy.use_24hour_clock().has_use_24hour_clock()) { |
726 policies->Set(key::kSystemUse24HourClock, | 632 policies->Set(key::kSystemUse24HourClock, POLICY_LEVEL_MANDATORY, |
727 POLICY_LEVEL_MANDATORY, | 633 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
728 POLICY_SCOPE_MACHINE, | 634 base::WrapUnique(new base::FundamentalValue( |
729 POLICY_SOURCE_CLOUD, | 635 policy.use_24hour_clock().use_24hour_clock())), |
730 new base::FundamentalValue( | 636 nullptr); |
731 policy.use_24hour_clock().use_24hour_clock()), | |
732 NULL); | |
733 } | 637 } |
734 } | 638 } |
735 | 639 |
736 if (policy.has_allow_redeem_offers()) { | 640 if (policy.has_allow_redeem_offers()) { |
737 const em::AllowRedeemChromeOsRegistrationOffersProto& container( | 641 const em::AllowRedeemChromeOsRegistrationOffersProto& container( |
738 policy.allow_redeem_offers()); | 642 policy.allow_redeem_offers()); |
739 if (container.has_allow_redeem_offers()) { | 643 if (container.has_allow_redeem_offers()) { |
740 policies->Set(key::kDeviceAllowRedeemChromeOsRegistrationOffers, | 644 policies->Set( |
741 POLICY_LEVEL_MANDATORY, | 645 key::kDeviceAllowRedeemChromeOsRegistrationOffers, |
742 POLICY_SCOPE_MACHINE, | 646 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
743 POLICY_SOURCE_CLOUD, | 647 base::WrapUnique( |
744 new base::FundamentalValue( | 648 new base::FundamentalValue(container.allow_redeem_offers())), |
745 container.allow_redeem_offers()), | 649 nullptr); |
746 NULL); | |
747 } | 650 } |
748 } | 651 } |
749 | 652 |
750 if (policy.has_uptime_limit()) { | 653 if (policy.has_uptime_limit()) { |
751 const em::UptimeLimitProto& container(policy.uptime_limit()); | 654 const em::UptimeLimitProto& container(policy.uptime_limit()); |
752 if (container.has_uptime_limit()) { | 655 if (container.has_uptime_limit()) { |
753 policies->Set(key::kUptimeLimit, | 656 policies->Set(key::kUptimeLimit, POLICY_LEVEL_MANDATORY, |
754 POLICY_LEVEL_MANDATORY, | 657 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
755 POLICY_SCOPE_MACHINE, | 658 DecodeIntegerValue(container.uptime_limit()), nullptr); |
756 POLICY_SOURCE_CLOUD, | |
757 DecodeIntegerValue(container.uptime_limit()).release(), | |
758 NULL); | |
759 } | 659 } |
760 } | 660 } |
761 | 661 |
762 if (policy.has_start_up_flags()) { | 662 if (policy.has_start_up_flags()) { |
763 const em::StartUpFlagsProto& container(policy.start_up_flags()); | 663 const em::StartUpFlagsProto& container(policy.start_up_flags()); |
764 base::ListValue* flags = new base::ListValue(); | 664 std::unique_ptr<base::ListValue> flags(new base::ListValue()); |
765 RepeatedPtrField<std::string>::const_iterator entry; | 665 for (const auto& entry : container.flags()) |
766 for (entry = container.flags().begin(); | 666 flags->Append(base::WrapUnique(new base::StringValue(entry))); |
767 entry != container.flags().end(); | 667 policies->Set(key::kDeviceStartUpFlags, POLICY_LEVEL_MANDATORY, |
768 ++entry) { | 668 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, std::move(flags), |
769 flags->Append(new base::StringValue(*entry)); | 669 nullptr); |
770 } | |
771 policies->Set(key::kDeviceStartUpFlags, | |
772 POLICY_LEVEL_MANDATORY, | |
773 POLICY_SCOPE_MACHINE, | |
774 POLICY_SOURCE_CLOUD, | |
775 flags, | |
776 NULL); | |
777 } | 670 } |
778 | 671 |
779 if (policy.has_variations_parameter()) { | 672 if (policy.has_variations_parameter()) { |
780 if (policy.variations_parameter().has_parameter()) { | 673 if (policy.variations_parameter().has_parameter()) { |
781 policies->Set(key::kDeviceVariationsRestrictParameter, | 674 policies->Set( |
782 POLICY_LEVEL_MANDATORY, | 675 key::kDeviceVariationsRestrictParameter, POLICY_LEVEL_MANDATORY, |
783 POLICY_SCOPE_MACHINE, | 676 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
784 POLICY_SOURCE_CLOUD, | 677 base::WrapUnique( |
785 new base::StringValue( | 678 new base::StringValue(policy.variations_parameter().parameter())), |
786 policy.variations_parameter().parameter()), | 679 nullptr); |
787 NULL); | |
788 } | 680 } |
789 } | 681 } |
790 | 682 |
791 if (policy.has_attestation_settings()) { | 683 if (policy.has_attestation_settings()) { |
792 if (policy.attestation_settings().has_attestation_enabled()) { | 684 if (policy.attestation_settings().has_attestation_enabled()) { |
793 policies->Set(key::kAttestationEnabledForDevice, | 685 policies->Set(key::kAttestationEnabledForDevice, POLICY_LEVEL_MANDATORY, |
794 POLICY_LEVEL_MANDATORY, | 686 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
795 POLICY_SCOPE_MACHINE, | 687 base::WrapUnique(new base::FundamentalValue( |
796 POLICY_SOURCE_CLOUD, | 688 policy.attestation_settings().attestation_enabled())), |
797 new base::FundamentalValue( | 689 nullptr); |
798 policy.attestation_settings().attestation_enabled()), | |
799 NULL); | |
800 } | 690 } |
801 if (policy.attestation_settings().has_content_protection_enabled()) { | 691 if (policy.attestation_settings().has_content_protection_enabled()) { |
802 policies->Set( | 692 policies->Set( |
803 key::kAttestationForContentProtectionEnabled, | 693 key::kAttestationForContentProtectionEnabled, POLICY_LEVEL_MANDATORY, |
804 POLICY_LEVEL_MANDATORY, | 694 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
805 POLICY_SCOPE_MACHINE, | 695 base::WrapUnique(new base::FundamentalValue( |
806 POLICY_SOURCE_CLOUD, | 696 policy.attestation_settings().content_protection_enabled())), |
807 new base::FundamentalValue( | 697 nullptr); |
808 policy.attestation_settings().content_protection_enabled()), | |
809 NULL); | |
810 } | 698 } |
811 } | 699 } |
812 | 700 |
813 if (policy.has_login_screen_power_management()) { | 701 if (policy.has_login_screen_power_management()) { |
814 const em::LoginScreenPowerManagementProto& container( | 702 const em::LoginScreenPowerManagementProto& container( |
815 policy.login_screen_power_management()); | 703 policy.login_screen_power_management()); |
816 if (container.has_login_screen_power_management()) { | 704 if (container.has_login_screen_power_management()) { |
817 std::unique_ptr<base::Value> decoded_json; | 705 std::unique_ptr<base::Value> decoded_json; |
818 decoded_json = DecodeJsonStringAndDropUnknownBySchema( | 706 decoded_json = DecodeJsonStringAndDropUnknownBySchema( |
819 container.login_screen_power_management(), | 707 container.login_screen_power_management(), |
820 key::kDeviceLoginScreenPowerManagement); | 708 key::kDeviceLoginScreenPowerManagement); |
821 if (decoded_json) { | 709 if (decoded_json) { |
822 policies->Set(key::kDeviceLoginScreenPowerManagement, | 710 policies->Set(key::kDeviceLoginScreenPowerManagement, |
823 POLICY_LEVEL_MANDATORY, | 711 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
824 POLICY_SCOPE_MACHINE, | 712 POLICY_SOURCE_CLOUD, std::move(decoded_json), nullptr); |
825 POLICY_SOURCE_CLOUD, | |
826 decoded_json.release(), | |
827 NULL); | |
828 } | 713 } |
829 } | 714 } |
830 } | 715 } |
831 | 716 |
832 if (policy.has_system_settings()) { | 717 if (policy.has_system_settings()) { |
833 const em::SystemSettingsProto& container(policy.system_settings()); | 718 const em::SystemSettingsProto& container(policy.system_settings()); |
834 if (container.has_block_devmode()) { | 719 if (container.has_block_devmode()) { |
835 policies->Set( | 720 policies->Set(key::kDeviceBlockDevmode, POLICY_LEVEL_MANDATORY, |
836 key::kDeviceBlockDevmode, | 721 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
837 POLICY_LEVEL_MANDATORY, | 722 base::WrapUnique( |
838 POLICY_SCOPE_MACHINE, | 723 new base::FundamentalValue(container.block_devmode())), |
839 POLICY_SOURCE_CLOUD, | 724 nullptr); |
840 new base::FundamentalValue(container.block_devmode()), | |
841 NULL); | |
842 } | 725 } |
843 } | 726 } |
844 | 727 |
845 if (policy.has_extension_cache_size()) { | 728 if (policy.has_extension_cache_size()) { |
846 const em::ExtensionCacheSizeProto& container(policy.extension_cache_size()); | 729 const em::ExtensionCacheSizeProto& container(policy.extension_cache_size()); |
847 if (container.has_extension_cache_size()) { | 730 if (container.has_extension_cache_size()) { |
848 policies->Set( | 731 policies->Set(key::kExtensionCacheSize, POLICY_LEVEL_MANDATORY, |
849 key::kExtensionCacheSize, | 732 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
850 POLICY_LEVEL_MANDATORY, | 733 DecodeIntegerValue(container.extension_cache_size()), |
851 POLICY_SCOPE_MACHINE, | 734 nullptr); |
852 POLICY_SOURCE_CLOUD, | |
853 DecodeIntegerValue(container.extension_cache_size()).release(), | |
854 nullptr); | |
855 } | 735 } |
856 } | 736 } |
857 | 737 |
858 if (policy.has_login_screen_domain_auto_complete()) { | 738 if (policy.has_login_screen_domain_auto_complete()) { |
859 const em::LoginScreenDomainAutoCompleteProto& container( | 739 const em::LoginScreenDomainAutoCompleteProto& container( |
860 policy.login_screen_domain_auto_complete()); | 740 policy.login_screen_domain_auto_complete()); |
861 policies->Set( | 741 policies->Set(key::kDeviceLoginScreenDomainAutoComplete, |
862 key::kDeviceLoginScreenDomainAutoComplete, | 742 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
863 POLICY_LEVEL_MANDATORY, | 743 POLICY_SOURCE_CLOUD, |
864 POLICY_SCOPE_MACHINE, | 744 base::WrapUnique(new base::StringValue( |
865 POLICY_SOURCE_CLOUD, | 745 container.login_screen_domain_auto_complete())), |
866 new base::StringValue(container.login_screen_domain_auto_complete()), | 746 nullptr); |
867 nullptr); | |
868 } | 747 } |
869 | 748 |
870 if (policy.has_display_rotation_default()) { | 749 if (policy.has_display_rotation_default()) { |
871 const em::DisplayRotationDefaultProto& container( | 750 const em::DisplayRotationDefaultProto& container( |
872 policy.display_rotation_default()); | 751 policy.display_rotation_default()); |
873 policies->Set( | 752 policies->Set(key::kDisplayRotationDefault, POLICY_LEVEL_MANDATORY, |
874 key::kDisplayRotationDefault, | 753 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
875 POLICY_LEVEL_MANDATORY, | 754 DecodeIntegerValue(container.display_rotation_default()), |
876 POLICY_SCOPE_MACHINE, | 755 nullptr); |
877 POLICY_SOURCE_CLOUD, | |
878 DecodeIntegerValue(container.display_rotation_default()).release(), | |
879 nullptr); | |
880 } | 756 } |
881 | 757 |
882 if (policy.has_usb_detachable_whitelist()) { | 758 if (policy.has_usb_detachable_whitelist()) { |
883 const em::UsbDetachableWhitelistProto& container( | 759 const em::UsbDetachableWhitelistProto& container( |
884 policy.usb_detachable_whitelist()); | 760 policy.usb_detachable_whitelist()); |
885 base::ListValue* whitelist = new base::ListValue(); | 761 std::unique_ptr<base::ListValue> whitelist(new base::ListValue); |
886 RepeatedPtrField<em::UsbDeviceIdProto>::const_iterator entry; | 762 for (const auto& entry : container.id()) { |
887 for (entry = container.id().begin(); entry != container.id().end(); | 763 std::unique_ptr<base::DictionaryValue> ids(new base::DictionaryValue()); |
888 ++entry) { | 764 if (entry.has_vendor_id()) { |
889 base::DictionaryValue* ids = new base::DictionaryValue(); | 765 ids->SetString("vid", base::StringPrintf("%04X", entry.vendor_id())); |
890 if (entry->has_vendor_id()) { | |
891 ids->SetString("vid", base::StringPrintf("%04X", entry->vendor_id())); | |
892 } | 766 } |
893 if (entry->has_product_id()) { | 767 if (entry.has_product_id()) { |
894 ids->SetString("pid", base::StringPrintf("%04X", entry->product_id())); | 768 ids->SetString("pid", base::StringPrintf("%04X", entry.product_id())); |
895 } | 769 } |
896 whitelist->Append(ids); | 770 whitelist->Append(std::move(ids)); |
897 } | 771 } |
898 policies->Set(key::kUsbDetachableWhitelist, POLICY_LEVEL_MANDATORY, | 772 policies->Set(key::kUsbDetachableWhitelist, POLICY_LEVEL_MANDATORY, |
899 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, whitelist, | 773 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
900 nullptr); | 774 std::move(whitelist), nullptr); |
901 } | 775 } |
902 | 776 |
903 if (policy.has_quirks_download_enabled()) { | 777 if (policy.has_quirks_download_enabled()) { |
904 const em::DeviceQuirksDownloadEnabledProto& container( | 778 const em::DeviceQuirksDownloadEnabledProto& container( |
905 policy.quirks_download_enabled()); | 779 policy.quirks_download_enabled()); |
906 if (container.has_quirks_download_enabled()) { | 780 if (container.has_quirks_download_enabled()) { |
907 policies->Set( | 781 policies->Set(key::kDeviceQuirksDownloadEnabled, POLICY_LEVEL_MANDATORY, |
908 key::kDeviceQuirksDownloadEnabled, | 782 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, |
909 POLICY_LEVEL_MANDATORY, | 783 base::WrapUnique(new base::FundamentalValue( |
910 POLICY_SCOPE_MACHINE, | 784 container.quirks_download_enabled())), |
911 POLICY_SOURCE_CLOUD, | 785 nullptr); |
912 new base::FundamentalValue(container.quirks_download_enabled()), | |
913 nullptr); | |
914 } | 786 } |
915 } | 787 } |
916 } | 788 } |
917 | 789 |
918 } // namespace | 790 } // namespace |
919 | 791 |
920 void DecodeDevicePolicy(const em::ChromeDeviceSettingsProto& policy, | 792 void DecodeDevicePolicy(const em::ChromeDeviceSettingsProto& policy, |
921 PolicyMap* policies) { | 793 PolicyMap* policies) { |
922 // Decode the various groups of policies. | 794 // Decode the various groups of policies. |
923 DecodeLoginPolicies(policy, policies); | 795 DecodeLoginPolicies(policy, policies); |
924 DecodeNetworkPolicies(policy, policies); | 796 DecodeNetworkPolicies(policy, policies); |
925 DecodeReportingPolicies(policy, policies); | 797 DecodeReportingPolicies(policy, policies); |
926 DecodeAutoUpdatePolicies(policy, policies); | 798 DecodeAutoUpdatePolicies(policy, policies); |
927 DecodeAccessibilityPolicies(policy, policies); | 799 DecodeAccessibilityPolicies(policy, policies); |
928 DecodeGenericPolicies(policy, policies); | 800 DecodeGenericPolicies(policy, policies); |
929 } | 801 } |
930 | 802 |
931 } // namespace policy | 803 } // namespace policy |
OLD | NEW |