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

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

Issue 1940153002: Use std::unique_ptr to express ownership of base::Value in PolicyMap::Entry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another-fix Created 4 years, 7 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"
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
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 if (policy.has_login_video_capture_allowed_urls()) { 300 if (policy.has_login_video_capture_allowed_urls()) {
330 const em::LoginVideoCaptureAllowedUrlsProto& container( 301 const em::LoginVideoCaptureAllowedUrlsProto& container(
331 policy.login_video_capture_allowed_urls()); 302 policy.login_video_capture_allowed_urls());
332 std::unique_ptr<base::ListValue> urls(new base::ListValue()); 303 std::unique_ptr<base::ListValue> urls(new base::ListValue());
333 for (const auto& entry : container.urls()) { 304 for (const auto& entry : container.urls()) {
334 urls->Append(new base::StringValue(entry)); 305 urls->Append(new base::StringValue(entry));
335 } 306 }
336 policies->Set(key::kLoginVideoCaptureAllowedUrls, POLICY_LEVEL_MANDATORY, 307 policies->Set(key::kLoginVideoCaptureAllowedUrls, POLICY_LEVEL_MANDATORY,
337 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, urls.release(), 308 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, std::move(urls),
338 nullptr); 309 nullptr);
339 } 310 }
340 } 311 }
341 312
342 void DecodeNetworkPolicies(const em::ChromeDeviceSettingsProto& policy, 313 void DecodeNetworkPolicies(const em::ChromeDeviceSettingsProto& policy,
343 PolicyMap* policies) { 314 PolicyMap* policies) {
344 if (policy.has_data_roaming_enabled()) { 315 if (policy.has_data_roaming_enabled()) {
345 const em::DataRoamingEnabledProto& container(policy.data_roaming_enabled()); 316 const em::DataRoamingEnabledProto& container(policy.data_roaming_enabled());
346 if (container.has_data_roaming_enabled()) { 317 if (container.has_data_roaming_enabled()) {
347 policies->Set(key::kDeviceDataRoamingEnabled, 318 policies->Set(key::kDeviceDataRoamingEnabled, POLICY_LEVEL_MANDATORY,
348 POLICY_LEVEL_MANDATORY, 319 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
349 POLICY_SCOPE_MACHINE, 320 base::WrapUnique(new base::FundamentalValue(
350 POLICY_SOURCE_CLOUD, 321 container.data_roaming_enabled())),
351 new base::FundamentalValue( 322 nullptr);
352 container.data_roaming_enabled()),
353 NULL);
354 } 323 }
355 } 324 }
356 325
357 if (policy.has_open_network_configuration() && 326 if (policy.has_open_network_configuration() &&
358 policy.open_network_configuration().has_open_network_configuration()) { 327 policy.open_network_configuration().has_open_network_configuration()) {
359 std::string config( 328 std::string config(
360 policy.open_network_configuration().open_network_configuration()); 329 policy.open_network_configuration().open_network_configuration());
361 policies->Set(key::kDeviceOpenNetworkConfiguration, 330 policies->Set(key::kDeviceOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY,
362 POLICY_LEVEL_MANDATORY, 331 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
363 POLICY_SCOPE_MACHINE, 332 base::WrapUnique(new base::StringValue(config)), nullptr);
364 POLICY_SOURCE_CLOUD,
365 new base::StringValue(config),
366 NULL);
367 } 333 }
368 } 334 }
369 335
370 void DecodeReportingPolicies(const em::ChromeDeviceSettingsProto& policy, 336 void DecodeReportingPolicies(const em::ChromeDeviceSettingsProto& policy,
371 PolicyMap* policies) { 337 PolicyMap* policies) {
372 if (policy.has_device_reporting()) { 338 if (policy.has_device_reporting()) {
373 const em::DeviceReportingProto& container(policy.device_reporting()); 339 const em::DeviceReportingProto& container(policy.device_reporting());
374 if (container.has_report_version_info()) { 340 if (container.has_report_version_info()) {
375 policies->Set(key::kReportDeviceVersionInfo, 341 policies->Set(key::kReportDeviceVersionInfo, POLICY_LEVEL_MANDATORY,
376 POLICY_LEVEL_MANDATORY, 342 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
377 POLICY_SCOPE_MACHINE, 343 base::WrapUnique(new base::FundamentalValue(
378 POLICY_SOURCE_CLOUD, 344 container.report_version_info())),
379 new base::FundamentalValue( 345 nullptr);
380 container.report_version_info()),
381 NULL);
382 } 346 }
383 if (container.has_report_activity_times()) { 347 if (container.has_report_activity_times()) {
384 policies->Set(key::kReportDeviceActivityTimes, 348 policies->Set(key::kReportDeviceActivityTimes, POLICY_LEVEL_MANDATORY,
385 POLICY_LEVEL_MANDATORY, 349 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
386 POLICY_SCOPE_MACHINE, 350 base::WrapUnique(new base::FundamentalValue(
387 POLICY_SOURCE_CLOUD, 351 container.report_activity_times())),
388 new base::FundamentalValue( 352 nullptr);
389 container.report_activity_times()),
390 NULL);
391 } 353 }
392 if (container.has_report_boot_mode()) { 354 if (container.has_report_boot_mode()) {
393 policies->Set(key::kReportDeviceBootMode, 355 policies->Set(key::kReportDeviceBootMode, POLICY_LEVEL_MANDATORY,
394 POLICY_LEVEL_MANDATORY, 356 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
395 POLICY_SCOPE_MACHINE, 357 base::WrapUnique(new base::FundamentalValue(
396 POLICY_SOURCE_CLOUD, 358 container.report_boot_mode())),
397 new base::FundamentalValue( 359 nullptr);
398 container.report_boot_mode()),
399 NULL);
400 } 360 }
401 if (container.has_report_location()) { 361 if (container.has_report_location()) {
402 policies->Set(key::kReportDeviceLocation, 362 policies->Set(key::kReportDeviceLocation, POLICY_LEVEL_MANDATORY,
403 POLICY_LEVEL_MANDATORY, 363 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
404 POLICY_SCOPE_MACHINE, 364 base::WrapUnique(new base::FundamentalValue(
405 POLICY_SOURCE_CLOUD, 365 container.report_location())),
406 new base::FundamentalValue( 366 nullptr);
407 container.report_location()),
408 NULL);
409 } 367 }
410 if (container.has_report_network_interfaces()) { 368 if (container.has_report_network_interfaces()) {
411 policies->Set(key::kReportDeviceNetworkInterfaces, 369 policies->Set(key::kReportDeviceNetworkInterfaces, POLICY_LEVEL_MANDATORY,
412 POLICY_LEVEL_MANDATORY, 370 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
413 POLICY_SCOPE_MACHINE, 371 base::WrapUnique(new base::FundamentalValue(
414 POLICY_SOURCE_CLOUD, 372 container.report_network_interfaces())),
415 new base::FundamentalValue( 373 nullptr);
416 container.report_network_interfaces()),
417 NULL);
418 } 374 }
419 if (container.has_report_users()) { 375 if (container.has_report_users()) {
420 policies->Set(key::kReportDeviceUsers, 376 policies->Set(key::kReportDeviceUsers, POLICY_LEVEL_MANDATORY,
421 POLICY_LEVEL_MANDATORY, 377 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
422 POLICY_SCOPE_MACHINE, 378 base::WrapUnique(
423 POLICY_SOURCE_CLOUD, 379 new base::FundamentalValue(container.report_users())),
424 new base::FundamentalValue(container.report_users()), 380 nullptr);
425 NULL);
426 } 381 }
427 if (container.has_report_hardware_status()) { 382 if (container.has_report_hardware_status()) {
428 policies->Set(key::kReportDeviceHardwareStatus, 383 policies->Set(key::kReportDeviceHardwareStatus, POLICY_LEVEL_MANDATORY,
429 POLICY_LEVEL_MANDATORY, 384 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
430 POLICY_SCOPE_MACHINE, 385 base::WrapUnique(new base::FundamentalValue(
431 POLICY_SOURCE_CLOUD, 386 container.report_hardware_status())),
432 new base::FundamentalValue( 387 nullptr);
433 container.report_hardware_status()),
434 NULL);
435 } 388 }
436 if (container.has_report_session_status()) { 389 if (container.has_report_session_status()) {
437 policies->Set(key::kReportDeviceSessionStatus, 390 policies->Set(key::kReportDeviceSessionStatus, POLICY_LEVEL_MANDATORY,
438 POLICY_LEVEL_MANDATORY, 391 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
439 POLICY_SCOPE_MACHINE, 392 base::WrapUnique(new base::FundamentalValue(
440 POLICY_SOURCE_CLOUD, 393 container.report_session_status())),
441 new base::FundamentalValue( 394 nullptr);
442 container.report_session_status()),
443 NULL);
444 } 395 }
445 if (container.has_device_status_frequency()) { 396 if (container.has_device_status_frequency()) {
446 policies->Set(key::kReportUploadFrequency, 397 policies->Set(key::kReportUploadFrequency, POLICY_LEVEL_MANDATORY,
447 POLICY_LEVEL_MANDATORY, 398 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
448 POLICY_SCOPE_MACHINE, 399 DecodeIntegerValue(container.device_status_frequency()),
449 POLICY_SOURCE_CLOUD, 400 nullptr);
450 DecodeIntegerValue(
451 container.device_status_frequency()).release(),
452 NULL);
453 } 401 }
454 } 402 }
455 403
456 if (policy.has_device_heartbeat_settings()) { 404 if (policy.has_device_heartbeat_settings()) {
457 const em::DeviceHeartbeatSettingsProto& container( 405 const em::DeviceHeartbeatSettingsProto& container(
458 policy.device_heartbeat_settings()); 406 policy.device_heartbeat_settings());
459 if (container.has_heartbeat_enabled()) { 407 if (container.has_heartbeat_enabled()) {
460 policies->Set(key::kHeartbeatEnabled, 408 policies->Set(key::kHeartbeatEnabled, POLICY_LEVEL_MANDATORY,
461 POLICY_LEVEL_MANDATORY, 409 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
462 POLICY_SCOPE_MACHINE, 410 base::WrapUnique(new base::FundamentalValue(
463 POLICY_SOURCE_CLOUD, 411 container.heartbeat_enabled())),
464 new base::FundamentalValue( 412 nullptr);
465 container.heartbeat_enabled()),
466 NULL);
467 } 413 }
468 if (container.has_heartbeat_frequency()) { 414 if (container.has_heartbeat_frequency()) {
469 policies->Set(key::kHeartbeatFrequency, 415 policies->Set(key::kHeartbeatFrequency, POLICY_LEVEL_MANDATORY,
470 POLICY_LEVEL_MANDATORY, 416 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
471 POLICY_SCOPE_MACHINE, 417 DecodeIntegerValue(container.heartbeat_frequency()),
472 POLICY_SOURCE_CLOUD, 418 nullptr);
473 DecodeIntegerValue(
474 container.heartbeat_frequency()).release(),
475 NULL);
476 } 419 }
477 } 420 }
478 421
479 if (policy.has_device_log_upload_settings()) { 422 if (policy.has_device_log_upload_settings()) {
480 const em::DeviceLogUploadSettingsProto& container( 423 const em::DeviceLogUploadSettingsProto& container(
481 policy.device_log_upload_settings()); 424 policy.device_log_upload_settings());
482 if (container.has_system_log_upload_enabled()) { 425 if (container.has_system_log_upload_enabled()) {
483 policies->Set( 426 policies->Set(key::kLogUploadEnabled, POLICY_LEVEL_MANDATORY,
484 key::kLogUploadEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 427 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
485 POLICY_SOURCE_CLOUD, 428 base::WrapUnique(new base::FundamentalValue(
486 new base::FundamentalValue(container.system_log_upload_enabled()), 429 container.system_log_upload_enabled())),
487 NULL); 430 nullptr);
488 } 431 }
489 } 432 }
490 } 433 }
491 434
492 void DecodeAutoUpdatePolicies(const em::ChromeDeviceSettingsProto& policy, 435 void DecodeAutoUpdatePolicies(const em::ChromeDeviceSettingsProto& policy,
493 PolicyMap* policies) { 436 PolicyMap* policies) {
494 if (policy.has_release_channel()) { 437 if (policy.has_release_channel()) {
495 const em::ReleaseChannelProto& container(policy.release_channel()); 438 const em::ReleaseChannelProto& container(policy.release_channel());
496 if (container.has_release_channel()) { 439 if (container.has_release_channel()) {
497 std::string channel(container.release_channel()); 440 std::string channel(container.release_channel());
498 policies->Set(key::kChromeOsReleaseChannel, 441 policies->Set(key::kChromeOsReleaseChannel, POLICY_LEVEL_MANDATORY,
499 POLICY_LEVEL_MANDATORY, 442 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
500 POLICY_SCOPE_MACHINE, 443 base::WrapUnique(new base::StringValue(channel)), nullptr);
501 POLICY_SOURCE_CLOUD,
502 new base::StringValue(channel),
503 NULL);
504 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't 444 // TODO(dubroy): Once http://crosbug.com/17015 is implemented, we won't
505 // have to pass the channel in here, only ping the update engine to tell 445 // have to pass the channel in here, only ping the update engine to tell
506 // it to fetch the channel from the policy. 446 // it to fetch the channel from the policy.
507 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()-> 447 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()->
508 SetChannel(channel, false); 448 SetChannel(channel, false);
509 } 449 }
510 if (container.has_release_channel_delegated()) { 450 if (container.has_release_channel_delegated()) {
511 policies->Set(key::kChromeOsReleaseChannelDelegated, 451 policies->Set(key::kChromeOsReleaseChannelDelegated,
512 POLICY_LEVEL_MANDATORY, 452 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
513 POLICY_SCOPE_MACHINE,
514 POLICY_SOURCE_CLOUD, 453 POLICY_SOURCE_CLOUD,
515 new base::FundamentalValue( 454 base::WrapUnique(new base::FundamentalValue(
516 container.release_channel_delegated()), 455 container.release_channel_delegated())),
517 NULL); 456 nullptr);
518 } 457 }
519 } 458 }
520 459
521 if (policy.has_auto_update_settings()) { 460 if (policy.has_auto_update_settings()) {
522 const em::AutoUpdateSettingsProto& container(policy.auto_update_settings()); 461 const em::AutoUpdateSettingsProto& container(policy.auto_update_settings());
523 if (container.has_update_disabled()) { 462 if (container.has_update_disabled()) {
524 policies->Set(key::kDeviceAutoUpdateDisabled, 463 policies->Set(key::kDeviceAutoUpdateDisabled, POLICY_LEVEL_MANDATORY,
525 POLICY_LEVEL_MANDATORY, 464 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
526 POLICY_SCOPE_MACHINE, 465 base::WrapUnique(new base::FundamentalValue(
527 POLICY_SOURCE_CLOUD, 466 container.update_disabled())),
528 new base::FundamentalValue( 467 nullptr);
529 container.update_disabled()),
530 NULL);
531 } 468 }
532 469
533 if (container.has_target_version_prefix()) { 470 if (container.has_target_version_prefix()) {
534 policies->Set(key::kDeviceTargetVersionPrefix, 471 policies->Set(key::kDeviceTargetVersionPrefix, POLICY_LEVEL_MANDATORY,
535 POLICY_LEVEL_MANDATORY, 472 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
536 POLICY_SCOPE_MACHINE, 473 base::WrapUnique(new base::StringValue(
537 POLICY_SOURCE_CLOUD, 474 container.target_version_prefix())),
538 new base::StringValue( 475 nullptr);
539 container.target_version_prefix()),
540 NULL);
541 } 476 }
542 477
543 // target_version_display_name is not actually a policy, but a display 478 // target_version_display_name is not actually a policy, but a display
544 // string for target_version_prefix, so we ignore it. 479 // string for target_version_prefix, so we ignore it.
545 480
546 if (container.has_scatter_factor_in_seconds()) { 481 if (container.has_scatter_factor_in_seconds()) {
547 policies->Set(key::kDeviceUpdateScatterFactor, 482 // TODO(dcheng): Shouldn't this use DecodeIntegerValue?
548 POLICY_LEVEL_MANDATORY, 483 policies->Set(
549 POLICY_SCOPE_MACHINE, 484 key::kDeviceUpdateScatterFactor, POLICY_LEVEL_MANDATORY,
550 POLICY_SOURCE_CLOUD, 485 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
551 new base::FundamentalValue(static_cast<int>( 486 base::WrapUnique(new base::FundamentalValue(
552 container.scatter_factor_in_seconds())), 487 static_cast<int>(container.scatter_factor_in_seconds()))),
553 NULL); 488 nullptr);
554 } 489 }
555 490
556 if (container.allowed_connection_types_size()) { 491 if (container.allowed_connection_types_size()) {
557 base::ListValue* allowed_connection_types = new base::ListValue(); 492 std::unique_ptr<base::ListValue> allowed_connection_types(
558 RepeatedField<int>::const_iterator entry; 493 new base::ListValue);
559 for (entry = container.allowed_connection_types().begin(); 494 for (const auto& entry : container.allowed_connection_types()) {
560 entry != container.allowed_connection_types().end(); 495 std::unique_ptr<base::Value> value = DecodeConnectionType(entry);
561 ++entry) {
562 base::Value* value = DecodeConnectionType(*entry);
563 if (value) 496 if (value)
564 allowed_connection_types->Append(value); 497 allowed_connection_types->Append(std::move(value));
565 } 498 }
566 policies->Set(key::kDeviceUpdateAllowedConnectionTypes, 499 policies->Set(key::kDeviceUpdateAllowedConnectionTypes,
567 POLICY_LEVEL_MANDATORY, 500 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
568 POLICY_SCOPE_MACHINE, 501 POLICY_SOURCE_CLOUD, std::move(allowed_connection_types),
569 POLICY_SOURCE_CLOUD, 502 nullptr);
570 allowed_connection_types,
571 NULL);
572 } 503 }
573 504
574 if (container.has_http_downloads_enabled()) { 505 if (container.has_http_downloads_enabled()) {
575 policies->Set( 506 policies->Set(
576 key::kDeviceUpdateHttpDownloadsEnabled, 507 key::kDeviceUpdateHttpDownloadsEnabled, POLICY_LEVEL_MANDATORY,
577 POLICY_LEVEL_MANDATORY, 508 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
578 POLICY_SCOPE_MACHINE, 509 base::WrapUnique(
579 POLICY_SOURCE_CLOUD, 510 new base::FundamentalValue(container.http_downloads_enabled())),
580 new base::FundamentalValue(container.http_downloads_enabled()), 511 nullptr);
581 NULL);
582 } 512 }
583 513
584 if (container.has_reboot_after_update()) { 514 if (container.has_reboot_after_update()) {
585 policies->Set(key::kRebootAfterUpdate, 515 policies->Set(key::kRebootAfterUpdate, POLICY_LEVEL_MANDATORY,
586 POLICY_LEVEL_MANDATORY, 516 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
587 POLICY_SCOPE_MACHINE, 517 base::WrapUnique(new base::FundamentalValue(
588 POLICY_SOURCE_CLOUD, 518 container.reboot_after_update())),
589 new base::FundamentalValue( 519 nullptr);
590 container.reboot_after_update()),
591 NULL);
592 } 520 }
593 521
594 if (container.has_p2p_enabled()) { 522 if (container.has_p2p_enabled()) {
595 policies->Set(key::kDeviceAutoUpdateP2PEnabled, 523 policies->Set(
596 POLICY_LEVEL_MANDATORY, 524 key::kDeviceAutoUpdateP2PEnabled, POLICY_LEVEL_MANDATORY,
597 POLICY_SCOPE_MACHINE, 525 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
598 POLICY_SOURCE_CLOUD, 526 base::WrapUnique(new base::FundamentalValue(container.p2p_enabled())),
599 new base::FundamentalValue(container.p2p_enabled()), 527 nullptr);
600 NULL);
601 } 528 }
602 } 529 }
603 530
604 if (policy.has_allow_kiosk_app_control_chrome_version()) { 531 if (policy.has_allow_kiosk_app_control_chrome_version()) {
605 const em::AllowKioskAppControlChromeVersionProto& container( 532 const em::AllowKioskAppControlChromeVersionProto& container(
606 policy.allow_kiosk_app_control_chrome_version()); 533 policy.allow_kiosk_app_control_chrome_version());
607 if (container.has_allow_kiosk_app_control_chrome_version()) { 534 if (container.has_allow_kiosk_app_control_chrome_version()) {
608 policies->Set(key::kAllowKioskAppControlChromeVersion, 535 policies->Set(key::kAllowKioskAppControlChromeVersion,
609 POLICY_LEVEL_MANDATORY, 536 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
610 POLICY_SCOPE_MACHINE,
611 POLICY_SOURCE_CLOUD, 537 POLICY_SOURCE_CLOUD,
612 new base::FundamentalValue( 538 base::WrapUnique(new base::FundamentalValue(
613 container.allow_kiosk_app_control_chrome_version()), 539 container.allow_kiosk_app_control_chrome_version())),
614 NULL); 540 nullptr);
615 } 541 }
616 } 542 }
617 } 543 }
618 544
619 void DecodeAccessibilityPolicies(const em::ChromeDeviceSettingsProto& policy, 545 void DecodeAccessibilityPolicies(const em::ChromeDeviceSettingsProto& policy,
620 PolicyMap* policies) { 546 PolicyMap* policies) {
621 if (policy.has_accessibility_settings()) { 547 if (policy.has_accessibility_settings()) {
622 const em::AccessibilitySettingsProto& 548 const em::AccessibilitySettingsProto&
623 container(policy.accessibility_settings()); 549 container(policy.accessibility_settings());
624 550
625 if (container.has_login_screen_default_large_cursor_enabled()) { 551 if (container.has_login_screen_default_large_cursor_enabled()) {
626 policies->Set( 552 policies->Set(key::kDeviceLoginScreenDefaultLargeCursorEnabled,
627 key::kDeviceLoginScreenDefaultLargeCursorEnabled, 553 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
628 POLICY_LEVEL_MANDATORY, 554 POLICY_SOURCE_CLOUD,
629 POLICY_SCOPE_MACHINE, 555 base::WrapUnique(new base::FundamentalValue(
630 POLICY_SOURCE_CLOUD, 556 container.login_screen_default_large_cursor_enabled())),
631 new base::FundamentalValue( 557 nullptr);
632 container.login_screen_default_large_cursor_enabled()),
633 NULL);
634 } 558 }
635 559
636 if (container.has_login_screen_default_spoken_feedback_enabled()) { 560 if (container.has_login_screen_default_spoken_feedback_enabled()) {
637 policies->Set( 561 policies->Set(
638 key::kDeviceLoginScreenDefaultSpokenFeedbackEnabled, 562 key::kDeviceLoginScreenDefaultSpokenFeedbackEnabled,
639 POLICY_LEVEL_MANDATORY, 563 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
640 POLICY_SCOPE_MACHINE, 564 base::WrapUnique(new base::FundamentalValue(
641 POLICY_SOURCE_CLOUD, 565 container.login_screen_default_spoken_feedback_enabled())),
642 new base::FundamentalValue( 566 nullptr);
643 container.login_screen_default_spoken_feedback_enabled()),
644 NULL);
645 } 567 }
646 568
647 if (container.has_login_screen_default_high_contrast_enabled()) { 569 if (container.has_login_screen_default_high_contrast_enabled()) {
648 policies->Set( 570 policies->Set(
649 key::kDeviceLoginScreenDefaultHighContrastEnabled, 571 key::kDeviceLoginScreenDefaultHighContrastEnabled,
650 POLICY_LEVEL_MANDATORY, 572 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
651 POLICY_SCOPE_MACHINE, 573 base::WrapUnique(new base::FundamentalValue(
652 POLICY_SOURCE_CLOUD, 574 container.login_screen_default_high_contrast_enabled())),
653 new base::FundamentalValue( 575 nullptr);
654 container.login_screen_default_high_contrast_enabled()),
655 NULL);
656 } 576 }
657 577
658 if (container.has_login_screen_default_screen_magnifier_type()) { 578 if (container.has_login_screen_default_screen_magnifier_type()) {
659 policies->Set( 579 policies->Set(key::kDeviceLoginScreenDefaultScreenMagnifierType,
660 key::kDeviceLoginScreenDefaultScreenMagnifierType, 580 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
661 POLICY_LEVEL_MANDATORY, 581 POLICY_SOURCE_CLOUD,
662 POLICY_SCOPE_MACHINE, 582 DecodeIntegerValue(
663 POLICY_SOURCE_CLOUD, 583 container.login_screen_default_screen_magnifier_type()),
664 DecodeIntegerValue( 584 nullptr);
665 container.login_screen_default_screen_magnifier_type()).release(),
666 NULL);
667 } 585 }
668 586
669 if (container.has_login_screen_default_virtual_keyboard_enabled()) { 587 if (container.has_login_screen_default_virtual_keyboard_enabled()) {
670 policies->Set( 588 policies->Set(
671 key::kDeviceLoginScreenDefaultVirtualKeyboardEnabled, 589 key::kDeviceLoginScreenDefaultVirtualKeyboardEnabled,
672 POLICY_LEVEL_MANDATORY, 590 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
673 POLICY_SCOPE_MACHINE, 591 base::WrapUnique(new base::FundamentalValue(
674 POLICY_SOURCE_CLOUD, 592 container.login_screen_default_virtual_keyboard_enabled())),
675 new base::FundamentalValue( 593 nullptr);
676 container.login_screen_default_virtual_keyboard_enabled()),
677 NULL);
678 } 594 }
679 } 595 }
680 } 596 }
681 597
682 void DecodeGenericPolicies(const em::ChromeDeviceSettingsProto& policy, 598 void DecodeGenericPolicies(const em::ChromeDeviceSettingsProto& policy,
683 PolicyMap* policies) { 599 PolicyMap* policies) {
684 if (policy.has_device_policy_refresh_rate()) { 600 if (policy.has_device_policy_refresh_rate()) {
685 const em::DevicePolicyRefreshRateProto& container( 601 const em::DevicePolicyRefreshRateProto& container(
686 policy.device_policy_refresh_rate()); 602 policy.device_policy_refresh_rate());
687 if (container.has_device_policy_refresh_rate()) { 603 if (container.has_device_policy_refresh_rate()) {
688 policies->Set( 604 policies->Set(key::kDevicePolicyRefreshRate, POLICY_LEVEL_MANDATORY,
689 key::kDevicePolicyRefreshRate, 605 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
690 POLICY_LEVEL_MANDATORY, 606 DecodeIntegerValue(container.device_policy_refresh_rate()),
691 POLICY_SCOPE_MACHINE, 607 nullptr);
692 POLICY_SOURCE_CLOUD,
693 DecodeIntegerValue(container.device_policy_refresh_rate()).release(),
694 NULL);
695 } 608 }
696 } 609 }
697 610
698 if (policy.has_metrics_enabled()) { 611 if (policy.has_metrics_enabled()) {
699 const em::MetricsEnabledProto& container(policy.metrics_enabled()); 612 const em::MetricsEnabledProto& container(policy.metrics_enabled());
700 if (container.has_metrics_enabled()) { 613 if (container.has_metrics_enabled()) {
701 policies->Set(key::kDeviceMetricsReportingEnabled, 614 policies->Set(key::kDeviceMetricsReportingEnabled, POLICY_LEVEL_MANDATORY,
702 POLICY_LEVEL_MANDATORY, 615 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
703 POLICY_SCOPE_MACHINE, 616 base::WrapUnique(new base::FundamentalValue(
704 POLICY_SOURCE_CLOUD, 617 container.metrics_enabled())),
705 new base::FundamentalValue( 618 nullptr);
706 container.metrics_enabled()),
707 NULL);
708 } 619 }
709 } 620 }
710 621
711 if (policy.has_system_timezone()) { 622 if (policy.has_system_timezone()) {
712 if (policy.system_timezone().has_timezone()) { 623 if (policy.system_timezone().has_timezone()) {
713 policies->Set(key::kSystemTimezone, 624 policies->Set(key::kSystemTimezone, POLICY_LEVEL_MANDATORY,
714 POLICY_LEVEL_MANDATORY, 625 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
715 POLICY_SCOPE_MACHINE, 626 base::WrapUnique(new base::StringValue(
716 POLICY_SOURCE_CLOUD, 627 policy.system_timezone().timezone())),
717 new base::StringValue( 628 nullptr);
718 policy.system_timezone().timezone()),
719 NULL);
720 } 629 }
721 630
722 if (policy.system_timezone().has_timezone_detection_type()) { 631 if (policy.system_timezone().has_timezone_detection_type()) {
723 std::unique_ptr<base::Value> value(DecodeIntegerValue( 632 std::unique_ptr<base::Value> value(DecodeIntegerValue(
724 policy.system_timezone().timezone_detection_type())); 633 policy.system_timezone().timezone_detection_type()));
725 if (value) { 634 if (value) {
726 policies->Set(key::kSystemTimezoneAutomaticDetection, 635 policies->Set(key::kSystemTimezoneAutomaticDetection,
727 POLICY_LEVEL_MANDATORY, 636 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
728 POLICY_SCOPE_MACHINE, 637 POLICY_SOURCE_CLOUD, std::move(value), nullptr);
729 POLICY_SOURCE_CLOUD,
730 value.release(),
731 nullptr);
732 } 638 }
733 } 639 }
734 } 640 }
735 641
736 if (policy.has_use_24hour_clock()) { 642 if (policy.has_use_24hour_clock()) {
737 if (policy.use_24hour_clock().has_use_24hour_clock()) { 643 if (policy.use_24hour_clock().has_use_24hour_clock()) {
738 policies->Set(key::kSystemUse24HourClock, 644 policies->Set(key::kSystemUse24HourClock, POLICY_LEVEL_MANDATORY,
739 POLICY_LEVEL_MANDATORY, 645 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
740 POLICY_SCOPE_MACHINE, 646 base::WrapUnique(new base::FundamentalValue(
741 POLICY_SOURCE_CLOUD, 647 policy.use_24hour_clock().use_24hour_clock())),
742 new base::FundamentalValue( 648 nullptr);
743 policy.use_24hour_clock().use_24hour_clock()),
744 NULL);
745 } 649 }
746 } 650 }
747 651
748 if (policy.has_allow_redeem_offers()) { 652 if (policy.has_allow_redeem_offers()) {
749 const em::AllowRedeemChromeOsRegistrationOffersProto& container( 653 const em::AllowRedeemChromeOsRegistrationOffersProto& container(
750 policy.allow_redeem_offers()); 654 policy.allow_redeem_offers());
751 if (container.has_allow_redeem_offers()) { 655 if (container.has_allow_redeem_offers()) {
752 policies->Set(key::kDeviceAllowRedeemChromeOsRegistrationOffers, 656 policies->Set(
753 POLICY_LEVEL_MANDATORY, 657 key::kDeviceAllowRedeemChromeOsRegistrationOffers,
754 POLICY_SCOPE_MACHINE, 658 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
755 POLICY_SOURCE_CLOUD, 659 base::WrapUnique(
756 new base::FundamentalValue( 660 new base::FundamentalValue(container.allow_redeem_offers())),
757 container.allow_redeem_offers()), 661 nullptr);
758 NULL);
759 } 662 }
760 } 663 }
761 664
762 if (policy.has_uptime_limit()) { 665 if (policy.has_uptime_limit()) {
763 const em::UptimeLimitProto& container(policy.uptime_limit()); 666 const em::UptimeLimitProto& container(policy.uptime_limit());
764 if (container.has_uptime_limit()) { 667 if (container.has_uptime_limit()) {
765 policies->Set(key::kUptimeLimit, 668 policies->Set(key::kUptimeLimit, POLICY_LEVEL_MANDATORY,
766 POLICY_LEVEL_MANDATORY, 669 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
767 POLICY_SCOPE_MACHINE, 670 DecodeIntegerValue(container.uptime_limit()), nullptr);
768 POLICY_SOURCE_CLOUD,
769 DecodeIntegerValue(container.uptime_limit()).release(),
770 NULL);
771 } 671 }
772 } 672 }
773 673
774 if (policy.has_start_up_flags()) { 674 if (policy.has_start_up_flags()) {
775 const em::StartUpFlagsProto& container(policy.start_up_flags()); 675 const em::StartUpFlagsProto& container(policy.start_up_flags());
776 base::ListValue* flags = new base::ListValue(); 676 std::unique_ptr<base::ListValue> flags(new base::ListValue());
777 RepeatedPtrField<std::string>::const_iterator entry; 677 for (const auto& entry : container.flags())
778 for (entry = container.flags().begin(); 678 flags->Append(base::WrapUnique(new base::StringValue(entry)));
779 entry != container.flags().end(); 679 policies->Set(key::kDeviceStartUpFlags, POLICY_LEVEL_MANDATORY,
780 ++entry) { 680 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, std::move(flags),
781 flags->Append(new base::StringValue(*entry)); 681 nullptr);
782 }
783 policies->Set(key::kDeviceStartUpFlags,
784 POLICY_LEVEL_MANDATORY,
785 POLICY_SCOPE_MACHINE,
786 POLICY_SOURCE_CLOUD,
787 flags,
788 NULL);
789 } 682 }
790 683
791 if (policy.has_variations_parameter()) { 684 if (policy.has_variations_parameter()) {
792 if (policy.variations_parameter().has_parameter()) { 685 if (policy.variations_parameter().has_parameter()) {
793 policies->Set(key::kDeviceVariationsRestrictParameter, 686 policies->Set(
794 POLICY_LEVEL_MANDATORY, 687 key::kDeviceVariationsRestrictParameter, POLICY_LEVEL_MANDATORY,
795 POLICY_SCOPE_MACHINE, 688 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
796 POLICY_SOURCE_CLOUD, 689 base::WrapUnique(
797 new base::StringValue( 690 new base::StringValue(policy.variations_parameter().parameter())),
798 policy.variations_parameter().parameter()), 691 nullptr);
799 NULL);
800 } 692 }
801 } 693 }
802 694
803 if (policy.has_attestation_settings()) { 695 if (policy.has_attestation_settings()) {
804 if (policy.attestation_settings().has_attestation_enabled()) { 696 if (policy.attestation_settings().has_attestation_enabled()) {
805 policies->Set(key::kAttestationEnabledForDevice, 697 policies->Set(key::kAttestationEnabledForDevice, POLICY_LEVEL_MANDATORY,
806 POLICY_LEVEL_MANDATORY, 698 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
807 POLICY_SCOPE_MACHINE, 699 base::WrapUnique(new base::FundamentalValue(
808 POLICY_SOURCE_CLOUD, 700 policy.attestation_settings().attestation_enabled())),
809 new base::FundamentalValue( 701 nullptr);
810 policy.attestation_settings().attestation_enabled()),
811 NULL);
812 } 702 }
813 if (policy.attestation_settings().has_content_protection_enabled()) { 703 if (policy.attestation_settings().has_content_protection_enabled()) {
814 policies->Set( 704 policies->Set(
815 key::kAttestationForContentProtectionEnabled, 705 key::kAttestationForContentProtectionEnabled, POLICY_LEVEL_MANDATORY,
816 POLICY_LEVEL_MANDATORY, 706 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
817 POLICY_SCOPE_MACHINE, 707 base::WrapUnique(new base::FundamentalValue(
818 POLICY_SOURCE_CLOUD, 708 policy.attestation_settings().content_protection_enabled())),
819 new base::FundamentalValue( 709 nullptr);
820 policy.attestation_settings().content_protection_enabled()),
821 NULL);
822 } 710 }
823 } 711 }
824 712
825 if (policy.has_login_screen_power_management()) { 713 if (policy.has_login_screen_power_management()) {
826 const em::LoginScreenPowerManagementProto& container( 714 const em::LoginScreenPowerManagementProto& container(
827 policy.login_screen_power_management()); 715 policy.login_screen_power_management());
828 if (container.has_login_screen_power_management()) { 716 if (container.has_login_screen_power_management()) {
829 std::unique_ptr<base::Value> decoded_json; 717 std::unique_ptr<base::Value> decoded_json;
830 decoded_json = DecodeJsonStringAndDropUnknownBySchema( 718 decoded_json = DecodeJsonStringAndDropUnknownBySchema(
831 container.login_screen_power_management(), 719 container.login_screen_power_management(),
832 key::kDeviceLoginScreenPowerManagement); 720 key::kDeviceLoginScreenPowerManagement);
833 if (decoded_json) { 721 if (decoded_json) {
834 policies->Set(key::kDeviceLoginScreenPowerManagement, 722 policies->Set(key::kDeviceLoginScreenPowerManagement,
835 POLICY_LEVEL_MANDATORY, 723 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
836 POLICY_SCOPE_MACHINE, 724 POLICY_SOURCE_CLOUD, std::move(decoded_json), nullptr);
837 POLICY_SOURCE_CLOUD,
838 decoded_json.release(),
839 NULL);
840 } 725 }
841 } 726 }
842 } 727 }
843 728
844 if (policy.has_system_settings()) { 729 if (policy.has_system_settings()) {
845 const em::SystemSettingsProto& container(policy.system_settings()); 730 const em::SystemSettingsProto& container(policy.system_settings());
846 if (container.has_block_devmode()) { 731 if (container.has_block_devmode()) {
847 policies->Set( 732 policies->Set(key::kDeviceBlockDevmode, POLICY_LEVEL_MANDATORY,
848 key::kDeviceBlockDevmode, 733 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
849 POLICY_LEVEL_MANDATORY, 734 base::WrapUnique(
850 POLICY_SCOPE_MACHINE, 735 new base::FundamentalValue(container.block_devmode())),
851 POLICY_SOURCE_CLOUD, 736 nullptr);
852 new base::FundamentalValue(container.block_devmode()),
853 NULL);
854 } 737 }
855 } 738 }
856 739
857 if (policy.has_extension_cache_size()) { 740 if (policy.has_extension_cache_size()) {
858 const em::ExtensionCacheSizeProto& container(policy.extension_cache_size()); 741 const em::ExtensionCacheSizeProto& container(policy.extension_cache_size());
859 if (container.has_extension_cache_size()) { 742 if (container.has_extension_cache_size()) {
860 policies->Set( 743 policies->Set(key::kExtensionCacheSize, POLICY_LEVEL_MANDATORY,
861 key::kExtensionCacheSize, 744 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
862 POLICY_LEVEL_MANDATORY, 745 DecodeIntegerValue(container.extension_cache_size()),
863 POLICY_SCOPE_MACHINE, 746 nullptr);
864 POLICY_SOURCE_CLOUD,
865 DecodeIntegerValue(container.extension_cache_size()).release(),
866 nullptr);
867 } 747 }
868 } 748 }
869 749
870 if (policy.has_login_screen_domain_auto_complete()) { 750 if (policy.has_login_screen_domain_auto_complete()) {
871 const em::LoginScreenDomainAutoCompleteProto& container( 751 const em::LoginScreenDomainAutoCompleteProto& container(
872 policy.login_screen_domain_auto_complete()); 752 policy.login_screen_domain_auto_complete());
873 policies->Set( 753 policies->Set(key::kDeviceLoginScreenDomainAutoComplete,
874 key::kDeviceLoginScreenDomainAutoComplete, 754 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
875 POLICY_LEVEL_MANDATORY, 755 POLICY_SOURCE_CLOUD,
876 POLICY_SCOPE_MACHINE, 756 base::WrapUnique(new base::StringValue(
877 POLICY_SOURCE_CLOUD, 757 container.login_screen_domain_auto_complete())),
878 new base::StringValue(container.login_screen_domain_auto_complete()), 758 nullptr);
879 nullptr);
880 } 759 }
881 760
882 if (policy.has_display_rotation_default()) { 761 if (policy.has_display_rotation_default()) {
883 const em::DisplayRotationDefaultProto& container( 762 const em::DisplayRotationDefaultProto& container(
884 policy.display_rotation_default()); 763 policy.display_rotation_default());
885 policies->Set( 764 policies->Set(key::kDisplayRotationDefault, POLICY_LEVEL_MANDATORY,
886 key::kDisplayRotationDefault, 765 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
887 POLICY_LEVEL_MANDATORY, 766 DecodeIntegerValue(container.display_rotation_default()),
888 POLICY_SCOPE_MACHINE, 767 nullptr);
889 POLICY_SOURCE_CLOUD,
890 DecodeIntegerValue(container.display_rotation_default()).release(),
891 nullptr);
892 } 768 }
893 769
894 if (policy.has_usb_detachable_whitelist()) { 770 if (policy.has_usb_detachable_whitelist()) {
895 const em::UsbDetachableWhitelistProto& container( 771 const em::UsbDetachableWhitelistProto& container(
896 policy.usb_detachable_whitelist()); 772 policy.usb_detachable_whitelist());
897 base::ListValue* whitelist = new base::ListValue(); 773 std::unique_ptr<base::ListValue> whitelist(new base::ListValue);
898 RepeatedPtrField<em::UsbDeviceIdProto>::const_iterator entry; 774 for (const auto& entry : container.id()) {
899 for (entry = container.id().begin(); entry != container.id().end(); 775 std::unique_ptr<base::DictionaryValue> ids(new base::DictionaryValue());
900 ++entry) { 776 if (entry.has_vendor_id()) {
901 base::DictionaryValue* ids = new base::DictionaryValue(); 777 ids->SetString("vid", base::StringPrintf("%04X", entry.vendor_id()));
902 if (entry->has_vendor_id()) {
903 ids->SetString("vid", base::StringPrintf("%04X", entry->vendor_id()));
904 } 778 }
905 if (entry->has_product_id()) { 779 if (entry.has_product_id()) {
906 ids->SetString("pid", base::StringPrintf("%04X", entry->product_id())); 780 ids->SetString("pid", base::StringPrintf("%04X", entry.product_id()));
907 } 781 }
908 whitelist->Append(ids); 782 whitelist->Append(std::move(ids));
909 } 783 }
910 policies->Set(key::kUsbDetachableWhitelist, POLICY_LEVEL_MANDATORY, 784 policies->Set(key::kUsbDetachableWhitelist, POLICY_LEVEL_MANDATORY,
911 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, whitelist, 785 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
912 nullptr); 786 std::move(whitelist), nullptr);
913 } 787 }
914 788
915 if (policy.has_quirks_download_enabled()) { 789 if (policy.has_quirks_download_enabled()) {
916 const em::DeviceQuirksDownloadEnabledProto& container( 790 const em::DeviceQuirksDownloadEnabledProto& container(
917 policy.quirks_download_enabled()); 791 policy.quirks_download_enabled());
918 if (container.has_quirks_download_enabled()) { 792 if (container.has_quirks_download_enabled()) {
919 policies->Set( 793 policies->Set(key::kDeviceQuirksDownloadEnabled, POLICY_LEVEL_MANDATORY,
920 key::kDeviceQuirksDownloadEnabled, 794 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
921 POLICY_LEVEL_MANDATORY, 795 base::WrapUnique(new base::FundamentalValue(
922 POLICY_SCOPE_MACHINE, 796 container.quirks_download_enabled())),
923 POLICY_SOURCE_CLOUD, 797 nullptr);
924 new base::FundamentalValue(container.quirks_download_enabled()),
925 nullptr);
926 } 798 }
927 } 799 }
928 } 800 }
929 801
930 } // namespace 802 } // namespace
931 803
932 void DecodeDevicePolicy(const em::ChromeDeviceSettingsProto& policy, 804 void DecodeDevicePolicy(const em::ChromeDeviceSettingsProto& policy,
933 PolicyMap* policies) { 805 PolicyMap* policies) {
934 // Decode the various groups of policies. 806 // Decode the various groups of policies.
935 DecodeLoginPolicies(policy, policies); 807 DecodeLoginPolicies(policy, policies);
936 DecodeNetworkPolicies(policy, policies); 808 DecodeNetworkPolicies(policy, policies);
937 DecodeReportingPolicies(policy, policies); 809 DecodeReportingPolicies(policy, policies);
938 DecodeAutoUpdatePolicies(policy, policies); 810 DecodeAutoUpdatePolicies(policy, policies);
939 DecodeAccessibilityPolicies(policy, policies); 811 DecodeAccessibilityPolicies(policy, policies);
940 DecodeGenericPolicies(policy, policies); 812 DecodeGenericPolicies(policy, policies);
941 } 813 }
942 814
943 } // namespace policy 815 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698