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

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_provider.cc

Issue 14306004: Put Kiosk App parameters into device settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make kiosk app ID a separate field in policy. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
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/settings/device_settings_provider.h" 5 #include "chrome/browser/chromeos/settings/device_settings_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/threading/thread_restrictions.h" 16 #include "base/threading/thread_restrictions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chromeos/cros/cros_library.h" 19 #include "chrome/browser/chromeos/cros/cros_library.h"
20 #include "chrome/browser/chromeos/cros/network_library.h" 20 #include "chrome/browser/chromeos/cros/network_library.h"
21 #include "chrome/browser/chromeos/policy/app_pack_updater.h"
22 #include "chrome/browser/chromeos/settings/cros_settings.h" 21 #include "chrome/browser/chromeos/settings/cros_settings.h"
23 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 22 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
24 #include "chrome/browser/chromeos/settings/device_settings_cache.h" 23 #include "chrome/browser/chromeos/settings/device_settings_cache.h"
25 #include "chrome/browser/policy/browser_policy_connector.h" 24 #include "chrome/browser/policy/browser_policy_connector.h"
26 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 25 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
27 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h" 26 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h"
28 #include "chrome/browser/ui/options/options_util.h" 27 #include "chrome/browser/ui/options/options_util.h"
29 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
30 #include "chrome/installer/util/google_update_settings.h" 29 #include "chrome/installer/util/google_update_settings.h"
31 30
32 using google::protobuf::RepeatedPtrField; 31 using google::protobuf::RepeatedPtrField;
33 32
34 namespace em = enterprise_management; 33 namespace em = enterprise_management;
35 34
36 namespace chromeos { 35 namespace chromeos {
37 36
38 namespace { 37 namespace {
39 38
40 // List of settings handled by the DeviceSettingsProvider. 39 // List of settings handled by the DeviceSettingsProvider.
41 const char* kKnownSettings[] = { 40 const char* kKnownSettings[] = {
42 kAccountsPrefAllowGuest, 41 kAccountsPrefAllowGuest,
43 kAccountsPrefAllowNewUser, 42 kAccountsPrefAllowNewUser,
44 kAccountsPrefDeviceLocalAccounts, 43 kAccountsPrefDeviceLocalAccounts,
44 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled,
45 kAccountsPrefDeviceLocalAccountAutoLoginDelay, 45 kAccountsPrefDeviceLocalAccountAutoLoginDelay,
46 kAccountsPrefDeviceLocalAccountAutoLoginId, 46 kAccountsPrefDeviceLocalAccountAutoLoginId,
47 kAccountsPrefEphemeralUsersEnabled, 47 kAccountsPrefEphemeralUsersEnabled,
48 kAccountsPrefShowUserNamesOnSignIn, 48 kAccountsPrefShowUserNamesOnSignIn,
49 kAccountsPrefUsers, 49 kAccountsPrefUsers,
50 kAllowRedeemChromeOsRegistrationOffers, 50 kAllowRedeemChromeOsRegistrationOffers,
51 kAppPack, 51 kAppPack,
52 kDeviceAttestationEnabled, 52 kDeviceAttestationEnabled,
53 kDeviceOwner, 53 kDeviceOwner,
54 kIdleLogoutTimeout, 54 kIdleLogoutTimeout,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 em::ShowUserNamesOnSigninProto* show = 219 em::ShowUserNamesOnSigninProto* show =
220 device_settings_.mutable_show_user_names(); 220 device_settings_.mutable_show_user_names();
221 bool show_value; 221 bool show_value;
222 if (value->GetAsBoolean(&show_value)) 222 if (value->GetAsBoolean(&show_value))
223 show->set_show_user_names(show_value); 223 show->set_show_user_names(show_value);
224 else 224 else
225 NOTREACHED(); 225 NOTREACHED();
226 } else if (prop == kAccountsPrefDeviceLocalAccounts) { 226 } else if (prop == kAccountsPrefDeviceLocalAccounts) {
227 em::DeviceLocalAccountsProto* device_local_accounts = 227 em::DeviceLocalAccountsProto* device_local_accounts =
228 device_settings_.mutable_device_local_accounts(); 228 device_settings_.mutable_device_local_accounts();
229 base::ListValue* accounts_list; 229 device_local_accounts->clear_account();
230 if (value->GetAsList(&accounts_list)) { 230 const base::DictionaryValue* accounts_dict = NULL;
231 for (base::ListValue::const_iterator entry(accounts_list->begin()); 231 if (value->GetAsDictionary(&accounts_dict)) {
232 entry != accounts_list->end(); ++entry) { 232 for (base::DictionaryValue::Iterator entry(*accounts_dict);
233 std::string id; 233 !entry.IsAtEnd(); entry.Advance()) {
234 if ((*entry)->GetAsString(&id)) 234 const base::DictionaryValue* entry_dict = NULL;
235 device_local_accounts->add_account()->set_id(id); 235 if (entry.value().GetAsDictionary(&entry_dict)) {
236 else 236 em::DeviceLocalAccountInfoProto* account =
237 device_local_accounts->add_account();
238 account->set_id(entry.key());
239 std::string kiosk_app_id;
240 if (entry_dict->GetStringWithoutPathExpansion(
241 kAccountsPrefDeviceLocalAccountsKeyKioskAppId,
242 &kiosk_app_id)) {
243 account->set_kiosk_app_id(kiosk_app_id);
244 }
245 std::string kiosk_app_update_url;
246 if (entry_dict->GetStringWithoutPathExpansion(
247 kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL,
248 &kiosk_app_update_url)) {
249 account->set_kiosk_app_update_url(kiosk_app_update_url);
250 }
251 } else {
237 NOTREACHED(); 252 NOTREACHED();
253 }
238 } 254 }
239 } else { 255 } else {
240 NOTREACHED(); 256 NOTREACHED();
241 } 257 }
242 } else if (prop == kAccountsPrefDeviceLocalAccountAutoLoginId) { 258 } else if (prop == kAccountsPrefDeviceLocalAccountAutoLoginId) {
243 em::DeviceLocalAccountsProto* device_local_accounts = 259 em::DeviceLocalAccountsProto* device_local_accounts =
244 device_settings_.mutable_device_local_accounts(); 260 device_settings_.mutable_device_local_accounts();
245 std::string id; 261 std::string id;
246 if (value->GetAsString(&id)) 262 if (value->GetAsString(&id))
247 device_local_accounts->set_auto_login_id(id); 263 device_local_accounts->set_auto_login_id(id);
248 else 264 else
249 NOTREACHED(); 265 NOTREACHED();
250 } else if (prop == kAccountsPrefDeviceLocalAccountAutoLoginDelay) { 266 } else if (prop == kAccountsPrefDeviceLocalAccountAutoLoginDelay) {
251 em::DeviceLocalAccountsProto* device_local_accounts = 267 em::DeviceLocalAccountsProto* device_local_accounts =
252 device_settings_.mutable_device_local_accounts(); 268 device_settings_.mutable_device_local_accounts();
253 int delay; 269 int delay;
254 if (value->GetAsInteger(&delay)) 270 if (value->GetAsInteger(&delay))
255 device_local_accounts->set_auto_login_delay(delay); 271 device_local_accounts->set_auto_login_delay(delay);
256 else 272 else
257 NOTREACHED(); 273 NOTREACHED();
274 } else if (prop == kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled) {
275 em::DeviceLocalAccountsProto* device_local_accounts =
276 device_settings_.mutable_device_local_accounts();
277 bool enabled;
278 if (value->GetAsBoolean(&enabled))
279 device_local_accounts->set_enable_auto_login_bailout(enabled);
280 else
281 NOTREACHED();
258 } else if (prop == kSignedDataRoamingEnabled) { 282 } else if (prop == kSignedDataRoamingEnabled) {
259 em::DataRoamingEnabledProto* roam = 283 em::DataRoamingEnabledProto* roam =
260 device_settings_.mutable_data_roaming_enabled(); 284 device_settings_.mutable_data_roaming_enabled();
261 bool roaming_value = false; 285 bool roaming_value = false;
262 if (value->GetAsBoolean(&roaming_value)) 286 if (value->GetAsBoolean(&roaming_value))
263 roam->set_data_roaming_enabled(roaming_value); 287 roam->set_data_roaming_enabled(roaming_value);
264 else 288 else
265 NOTREACHED(); 289 NOTREACHED();
266 ApplyRoamingSetting(roaming_value); 290 ApplyRoamingSetting(roaming_value);
267 } else if (prop == kSettingProxyEverywhere) { 291 } else if (prop == kSettingProxyEverywhere) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 base::ListValue* list = new base::ListValue(); 450 base::ListValue* list = new base::ListValue();
427 const em::UserWhitelistProto& whitelist_proto = policy.user_whitelist(); 451 const em::UserWhitelistProto& whitelist_proto = policy.user_whitelist();
428 const RepeatedPtrField<std::string>& whitelist = 452 const RepeatedPtrField<std::string>& whitelist =
429 whitelist_proto.user_whitelist(); 453 whitelist_proto.user_whitelist();
430 for (RepeatedPtrField<std::string>::const_iterator it = whitelist.begin(); 454 for (RepeatedPtrField<std::string>::const_iterator it = whitelist.begin();
431 it != whitelist.end(); ++it) { 455 it != whitelist.end(); ++it) {
432 list->Append(new base::StringValue(*it)); 456 list->Append(new base::StringValue(*it));
433 } 457 }
434 new_values_cache->SetValue(kAccountsPrefUsers, list); 458 new_values_cache->SetValue(kAccountsPrefUsers, list);
435 459
436 base::ListValue* account_list = new base::ListValue(); 460 base::DictionaryValue* account_dict = new base::DictionaryValue();
437 CommandLine* command_line = CommandLine::ForCurrentProcess(); 461 CommandLine* command_line = CommandLine::ForCurrentProcess();
438 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) { 462 if (!command_line->HasSwitch(switches::kDisableLocalAccounts)) {
439 const em::DeviceLocalAccountsProto device_local_accounts_proto = 463 const em::DeviceLocalAccountsProto device_local_accounts_proto =
440 policy.device_local_accounts(); 464 policy.device_local_accounts();
441 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts = 465 const RepeatedPtrField<em::DeviceLocalAccountInfoProto>& accounts =
442 device_local_accounts_proto.account(); 466 device_local_accounts_proto.account();
443 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry; 467 RepeatedPtrField<em::DeviceLocalAccountInfoProto>::const_iterator entry;
444 for (entry = accounts.begin(); entry != accounts.end(); ++entry) { 468 for (entry = accounts.begin(); entry != accounts.end(); ++entry) {
445 if (entry->has_id()) 469 if (entry->id().empty() || account_dict->HasKey(entry->id()))
bartfab (slow) 2013/04/25 11:17:28 This way, we silently skip duplicates. We should a
Mattias Nissler (ping if slow) 2013/04/26 09:10:05 Obsolete, using a list.
446 account_list->AppendString(entry->id()); 470 continue;
471
472 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue());
bartfab (slow) 2013/04/25 11:17:28 As before: Why use a scoped_ptr if you are passing
Mattias Nissler (ping if slow) 2013/04/26 09:10:05 same as before.
473 if (entry->has_kiosk_app_id()) {
474 entry_dict->SetStringWithoutPathExpansion(
475 kAccountsPrefDeviceLocalAccountsKeyKioskAppId,
476 entry->kiosk_app_id());
477 }
478 if (entry->has_kiosk_app_update_url()) {
479 entry_dict->SetStringWithoutPathExpansion(
480 kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL,
481 entry->kiosk_app_update_url());
482 }
483 account_dict->SetWithoutPathExpansion(entry->id(), entry_dict.release());
447 } 484 }
448 } 485 }
449 new_values_cache->SetValue(kAccountsPrefDeviceLocalAccounts, account_list); 486 new_values_cache->SetValue(kAccountsPrefDeviceLocalAccounts, account_dict);
450
451 if (policy.has_start_up_flags()) {
452 base::ListValue* list = new base::ListValue();
453 const em::StartUpFlagsProto& flags_proto = policy.start_up_flags();
454 const RepeatedPtrField<std::string>& flags = flags_proto.flags();
455 for (RepeatedPtrField<std::string>::const_iterator it = flags.begin();
456 it != flags.end(); ++it) {
457 list->Append(new base::StringValue(*it));
458 }
459 new_values_cache->SetValue(kStartUpFlags, list);
460 }
461 487
462 if (policy.has_device_local_accounts()) { 488 if (policy.has_device_local_accounts()) {
463 if (policy.device_local_accounts().has_auto_login_id()) { 489 if (policy.device_local_accounts().has_auto_login_id()) {
464 new_values_cache->SetString( 490 new_values_cache->SetString(
465 kAccountsPrefDeviceLocalAccountAutoLoginId, 491 kAccountsPrefDeviceLocalAccountAutoLoginId,
466 policy.device_local_accounts().auto_login_id()); 492 policy.device_local_accounts().auto_login_id());
467 } 493 }
468 if (policy.device_local_accounts().has_auto_login_delay()) { 494 if (policy.device_local_accounts().has_auto_login_delay()) {
469 new_values_cache->SetInteger( 495 new_values_cache->SetInteger(
470 kAccountsPrefDeviceLocalAccountAutoLoginDelay, 496 kAccountsPrefDeviceLocalAccountAutoLoginDelay,
471 policy.device_local_accounts().auto_login_delay()); 497 policy.device_local_accounts().auto_login_delay());
472 } 498 }
473 } 499 }
500
501 new_values_cache->SetBoolean(
502 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled,
503 policy.device_local_accounts().enable_auto_login_bailout());
504
505 if (policy.has_start_up_flags()) {
506 base::ListValue* list = new base::ListValue();
507 const em::StartUpFlagsProto& flags_proto = policy.start_up_flags();
508 const RepeatedPtrField<std::string>& flags = flags_proto.flags();
509 for (RepeatedPtrField<std::string>::const_iterator it = flags.begin();
510 it != flags.end(); ++it) {
511 list->Append(new base::StringValue(*it));
512 }
513 new_values_cache->SetValue(kStartUpFlags, list);
514 }
474 } 515 }
475 516
476 void DeviceSettingsProvider::DecodeKioskPolicies( 517 void DeviceSettingsProvider::DecodeKioskPolicies(
477 const em::ChromeDeviceSettingsProto& policy, 518 const em::ChromeDeviceSettingsProto& policy,
478 PrefValueMap* new_values_cache) const { 519 PrefValueMap* new_values_cache) const {
479 if (policy.has_forced_logout_timeouts()) { 520 if (policy.has_forced_logout_timeouts()) {
480 if (policy.forced_logout_timeouts().has_idle_logout_timeout()) { 521 if (policy.forced_logout_timeouts().has_idle_logout_timeout()) {
481 new_values_cache->SetInteger( 522 new_values_cache->SetInteger(
482 kIdleLogoutTimeout, 523 kIdleLogoutTimeout,
483 policy.forced_logout_timeouts().idle_logout_timeout()); 524 policy.forced_logout_timeouts().idle_logout_timeout());
(...skipping 21 matching lines...) Expand all
505 } 546 }
506 547
507 if (policy.has_app_pack()) { 548 if (policy.has_app_pack()) {
508 typedef RepeatedPtrField<em::AppPackEntryProto> proto_type; 549 typedef RepeatedPtrField<em::AppPackEntryProto> proto_type;
509 base::ListValue* list = new base::ListValue; 550 base::ListValue* list = new base::ListValue;
510 const proto_type& app_pack = policy.app_pack().app_pack(); 551 const proto_type& app_pack = policy.app_pack().app_pack();
511 for (proto_type::const_iterator it = app_pack.begin(); 552 for (proto_type::const_iterator it = app_pack.begin();
512 it != app_pack.end(); ++it) { 553 it != app_pack.end(); ++it) {
513 base::DictionaryValue* entry = new base::DictionaryValue; 554 base::DictionaryValue* entry = new base::DictionaryValue;
514 if (it->has_extension_id()) { 555 if (it->has_extension_id()) {
515 entry->SetString(policy::AppPackUpdater::kExtensionId, 556 entry->SetStringWithoutPathExpansion(kAppPackKeyExtensionId,
516 it->extension_id()); 557 it->extension_id());
517 } 558 }
518 if (it->has_update_url()) 559 if (it->has_update_url()) {
519 entry->SetString(policy::AppPackUpdater::kUpdateUrl, it->update_url()); 560 entry->SetStringWithoutPathExpansion(kAppPackKeyUpdateUrl,
561 it->update_url());
562 }
520 list->Append(entry); 563 list->Append(entry);
521 } 564 }
522 new_values_cache->SetValue(kAppPack, list); 565 new_values_cache->SetValue(kAppPack, list);
523 } 566 }
524 567
525 if (policy.has_start_up_urls()) { 568 if (policy.has_start_up_urls()) {
526 base::ListValue* list = new base::ListValue(); 569 base::ListValue* list = new base::ListValue();
527 const em::StartUpUrlsProto& urls_proto = policy.start_up_urls(); 570 const em::StartUpUrlsProto& urls_proto = policy.start_up_urls();
528 const RepeatedPtrField<std::string>& urls = urls_proto.start_up_urls(); 571 const RepeatedPtrField<std::string>& urls = urls_proto.start_up_urls();
529 for (RepeatedPtrField<std::string>::const_iterator it = urls.begin(); 572 for (RepeatedPtrField<std::string>::const_iterator it = urls.begin();
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 void DeviceSettingsProvider::AttemptMigration() { 915 void DeviceSettingsProvider::AttemptMigration() {
873 if (device_settings_service_->HasPrivateOwnerKey()) { 916 if (device_settings_service_->HasPrivateOwnerKey()) {
874 PrefValueMap::const_iterator i; 917 PrefValueMap::const_iterator i;
875 for (i = migration_values_.begin(); i != migration_values_.end(); ++i) 918 for (i = migration_values_.begin(); i != migration_values_.end(); ++i)
876 DoSet(i->first, *i->second); 919 DoSet(i->first, *i->second);
877 migration_values_.Clear(); 920 migration_values_.Clear();
878 } 921 }
879 } 922 }
880 923
881 } // namespace chromeos 924 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698