Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/user_cros_settings_provider.h" | 5 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/task.h" | 14 #include "base/task.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chromeos/cros/cros_library.h" | 17 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 18 #include "chrome/browser/chromeos/cros/login_library.h" | 18 #include "chrome/browser/chromeos/cros/login_library.h" |
| 19 #include "chrome/browser/chromeos/cros/network_library.h" | 19 #include "chrome/browser/chromeos/cros/network_library.h" |
| 20 #include "chrome/browser/chromeos/cros_settings.h" | 20 #include "chrome/browser/chromeos/cros_settings.h" |
| 21 #include "chrome/browser/chromeos/cros_settings_names.h" | 21 #include "chrome/browser/chromeos/cros_settings_names.h" |
| 22 #include "chrome/browser/chromeos/login/ownership_service.h" | 22 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 23 #include "chrome/browser/chromeos/login/ownership_status_checker.h" | 23 #include "chrome/browser/chromeos/login/ownership_status_checker.h" |
| 24 #include "chrome/browser/chromeos/login/user_manager.h" | 24 #include "chrome/browser/chromeos/login/user_manager.h" |
| 25 #include "chrome/browser/policy/browser_policy_connector.h" | |
| 26 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
| 27 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 26 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 28 #include "chrome/browser/ui/options/options_util.h" | 27 #include "chrome/browser/ui/options/options_util.h" |
| 29 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
| 30 #include "chrome/installer/util/google_update_settings.h" | 29 #include "chrome/installer/util/google_update_settings.h" |
| 31 #include "content/browser/browser_thread.h" | 30 #include "content/browser/browser_thread.h" |
| 32 | 31 |
| 33 namespace chromeos { | 32 namespace chromeos { |
| 34 | 33 |
| 35 namespace { | 34 namespace { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 local_state->RegisterStringPref(pref_path.c_str(), | 164 local_state->RegisterStringPref(pref_path.c_str(), |
| 166 "", | 165 "", |
| 167 PrefService::UNSYNCABLE_PREF); | 166 PrefService::UNSYNCABLE_PREF); |
| 168 } else { | 167 } else { |
| 169 DCHECK(IsControlledListSetting(pref_path)); | 168 DCHECK(IsControlledListSetting(pref_path)); |
| 170 local_state->RegisterListPref(pref_path.c_str(), | 169 local_state->RegisterListPref(pref_path.c_str(), |
| 171 PrefService::UNSYNCABLE_PREF); | 170 PrefService::UNSYNCABLE_PREF); |
| 172 } | 171 } |
| 173 } | 172 } |
| 174 | 173 |
| 175 // Create a settings value with "managed" and "disabled" property. | |
| 176 // "managed" property is true if the setting is managed by administrator. | |
| 177 // "disabled" property is true if the UI for the setting should be disabled. | |
| 178 Value* CreateSettingsValue(Value *value, bool managed, bool disabled) { | |
| 179 DictionaryValue* dict = new DictionaryValue; | |
| 180 dict->Set("value", value); | |
| 181 dict->Set("managed", Value::CreateBooleanValue(managed)); | |
| 182 dict->Set("disabled", Value::CreateBooleanValue(disabled)); | |
| 183 return dict; | |
| 184 } | |
| 185 | |
| 186 enum UseValue { | 174 enum UseValue { |
| 187 USE_VALUE_SUPPLIED, | 175 USE_VALUE_SUPPLIED, |
| 188 USE_VALUE_DEFAULT | 176 USE_VALUE_DEFAULT |
| 189 }; | 177 }; |
| 190 | 178 |
| 191 void UpdateCacheBool(const std::string& name, | 179 void UpdateCacheBool(const std::string& name, |
| 192 bool value, | 180 bool value, |
| 193 UseValue use_value) { | 181 UseValue use_value) { |
| 194 PrefService* prefs = g_browser_process->local_state(); | 182 PrefService* prefs = g_browser_process->local_state(); |
| 195 if (use_value == USE_VALUE_DEFAULT) | 183 if (use_value == USE_VALUE_DEFAULT) |
| 196 prefs->ClearPref(name.c_str()); | 184 prefs->ClearPref(name.c_str()); |
| 197 else | 185 else |
| 198 prefs->SetBoolean(name.c_str(), value); | 186 prefs->SetBoolean(name.c_str(), value); |
| 199 prefs->ScheduleSavePersistentPrefs(); | 187 prefs->ScheduleSavePersistentPrefs(); |
| 200 } | 188 } |
| 201 | 189 |
| 202 void UpdateCacheString(const std::string& name, | 190 void UpdateCacheString(const std::string& name, |
| 203 const std::string& value, | 191 const std::string& value, |
| 204 UseValue use_value) { | 192 UseValue use_value) { |
| 205 PrefService* prefs = g_browser_process->local_state(); | 193 PrefService* prefs = g_browser_process->local_state(); |
| 206 if (use_value == USE_VALUE_DEFAULT) | 194 if (use_value == USE_VALUE_DEFAULT) |
| 207 prefs->ClearPref(name.c_str()); | 195 prefs->ClearPref(name.c_str()); |
| 208 else | 196 else |
| 209 prefs->SetString(name.c_str(), value); | 197 prefs->SetString(name.c_str(), value); |
| 210 prefs->ScheduleSavePersistentPrefs(); | 198 prefs->ScheduleSavePersistentPrefs(); |
| 211 } | 199 } |
| 212 | 200 |
| 201 // Helper function to parse the whitelist from the policy cache into the local | |
| 202 // state. | |
| 203 // TODO(pastarmovj): This function will disappear in step two of the refactoring | |
| 204 // as per design doc. (Contact pastarmovj@chromium.org for a link to it.) | |
| 213 bool GetUserWhitelist(ListValue* user_list) { | 205 bool GetUserWhitelist(ListValue* user_list) { |
| 214 PrefService* prefs = g_browser_process->local_state(); | 206 PrefService* prefs = g_browser_process->local_state(); |
| 215 DCHECK(!prefs->IsManagedPreference(kAccountsPrefUsers)); | 207 DCHECK(!prefs->IsManagedPreference(kAccountsPrefUsers)); |
| 216 | 208 |
| 217 std::vector<std::string> whitelist; | 209 std::vector<std::string> whitelist; |
| 218 if (!SignedSettings::EnumerateWhitelist(&whitelist)) { | 210 if (!SignedSettings::EnumerateWhitelist(&whitelist)) { |
| 219 LOG(WARNING) << "Failed to retrieve user whitelist."; | 211 LOG(WARNING) << "Failed to retrieve user whitelist."; |
| 220 return false; | 212 return false; |
| 221 } | 213 } |
| 222 | 214 |
| 223 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); | 215 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); |
| 224 cached_whitelist_update->Clear(); | 216 cached_whitelist_update->Clear(); |
| 225 | 217 |
| 226 const UserManager::User& self = UserManager::Get()->logged_in_user(); | 218 for (size_t i = 0; i < whitelist.size(); ++i) |
| 227 bool is_owner = UserManager::Get()->current_user_is_owner(); | 219 cached_whitelist_update->Append(Value::CreateStringValue(whitelist[i])); |
| 228 | |
| 229 for (size_t i = 0; i < whitelist.size(); ++i) { | |
| 230 const std::string& email = whitelist[i]; | |
| 231 | |
| 232 if (user_list) { | |
| 233 DictionaryValue* user = new DictionaryValue; | |
| 234 user->SetString("email", email); | |
| 235 user->SetString("name", ""); | |
| 236 user->SetBoolean("owner", is_owner && email == self.email()); | |
| 237 user_list->Append(user); | |
| 238 } | |
| 239 | |
| 240 cached_whitelist_update->Append(Value::CreateStringValue(email)); | |
| 241 } | |
| 242 | 220 |
| 243 prefs->ScheduleSavePersistentPrefs(); | 221 prefs->ScheduleSavePersistentPrefs(); |
| 244 return true; | 222 return true; |
| 245 } | 223 } |
| 246 | 224 |
| 247 class UserCrosSettingsTrust : public SignedSettingsHelper::Callback { | 225 class UserCrosSettingsTrust : public SignedSettingsHelper::Callback { |
| 248 public: | 226 public: |
| 249 static UserCrosSettingsTrust* GetInstance() { | 227 static UserCrosSettingsTrust* GetInstance() { |
| 250 return Singleton<UserCrosSettingsTrust>::get(); | 228 return Singleton<UserCrosSettingsTrust>::get(); |
| 251 } | 229 } |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 // static | 544 // static |
| 567 void UserCrosSettingsProvider::RegisterPrefs(PrefService* local_state) { | 545 void UserCrosSettingsProvider::RegisterPrefs(PrefService* local_state) { |
| 568 for (size_t i = 0; i < arraysize(kBooleanSettings); ++i) | 546 for (size_t i = 0; i < arraysize(kBooleanSettings); ++i) |
| 569 RegisterSetting(local_state, kBooleanSettings[i]); | 547 RegisterSetting(local_state, kBooleanSettings[i]); |
| 570 for (size_t i = 0; i < arraysize(kStringSettings); ++i) | 548 for (size_t i = 0; i < arraysize(kStringSettings); ++i) |
| 571 RegisterSetting(local_state, kStringSettings[i]); | 549 RegisterSetting(local_state, kStringSettings[i]); |
| 572 for (size_t i = 0; i < arraysize(kListSettings); ++i) | 550 for (size_t i = 0; i < arraysize(kListSettings); ++i) |
| 573 RegisterSetting(local_state, kListSettings[i]); | 551 RegisterSetting(local_state, kListSettings[i]); |
| 574 } | 552 } |
| 575 | 553 |
| 576 bool UserCrosSettingsProvider::RequestTrustedAllowGuest(Task* callback) { | |
| 577 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | |
| 578 kAccountsPrefAllowGuest, callback); | |
| 579 } | |
| 580 | |
| 581 bool UserCrosSettingsProvider::RequestTrustedAllowNewUser(Task* callback) { | |
| 582 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | |
| 583 kAccountsPrefAllowNewUser, callback); | |
| 584 } | |
| 585 | |
| 586 bool UserCrosSettingsProvider::RequestTrustedShowUsersOnSignin(Task* callback) { | |
| 587 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | |
| 588 kAccountsPrefShowUserNamesOnSignIn, callback); | |
| 589 } | |
| 590 | |
| 591 bool UserCrosSettingsProvider::RequestTrustedDataRoamingEnabled( | |
| 592 Task* callback) { | |
| 593 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | |
| 594 kSignedDataRoamingEnabled, callback); | |
| 595 } | |
| 596 | |
| 597 bool UserCrosSettingsProvider::RequestTrustedOwner(Task* callback) { | |
| 598 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | |
| 599 kDeviceOwner, callback); | |
| 600 } | |
| 601 | |
| 602 bool UserCrosSettingsProvider::RequestTrustedReportingEnabled(Task* callback) { | |
| 603 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | |
| 604 kStatsReportingPref, callback); | |
| 605 } | |
| 606 | |
| 607 void UserCrosSettingsProvider::Reload() { | 554 void UserCrosSettingsProvider::Reload() { |
| 608 UserCrosSettingsTrust::GetInstance()->Reload(); | 555 UserCrosSettingsTrust::GetInstance()->Reload(); |
| 609 } | 556 } |
| 610 | 557 |
| 611 // static | |
| 612 bool UserCrosSettingsProvider::cached_allow_guest() { | |
| 613 // Trigger prefetching if singleton object still does not exist. | |
| 614 UserCrosSettingsTrust::GetInstance(); | |
| 615 return g_browser_process->local_state()->GetBoolean(kAccountsPrefAllowGuest); | |
| 616 } | |
| 617 | |
| 618 // static | |
| 619 bool UserCrosSettingsProvider::cached_allow_new_user() { | |
| 620 // Trigger prefetching if singleton object still does not exist. | |
| 621 UserCrosSettingsTrust::GetInstance(); | |
| 622 return g_browser_process->local_state()->GetBoolean( | |
| 623 kAccountsPrefAllowNewUser); | |
| 624 } | |
| 625 | |
| 626 // static | |
| 627 bool UserCrosSettingsProvider::cached_data_roaming_enabled() { | |
| 628 // Trigger prefetching if singleton object still does not exist. | |
| 629 UserCrosSettingsTrust::GetInstance(); | |
| 630 return g_browser_process->local_state()->GetBoolean( | |
| 631 kSignedDataRoamingEnabled); | |
| 632 } | |
| 633 | |
| 634 // static | |
| 635 bool UserCrosSettingsProvider::cached_show_users_on_signin() { | |
| 636 // Trigger prefetching if singleton object still does not exist. | |
| 637 UserCrosSettingsTrust::GetInstance(); | |
| 638 return g_browser_process->local_state()->GetBoolean( | |
| 639 kAccountsPrefShowUserNamesOnSignIn); | |
| 640 } | |
| 641 | |
| 642 // static | |
| 643 bool UserCrosSettingsProvider::cached_reporting_enabled() { | |
| 644 // Trigger prefetching if singleton object still does not exist. | |
| 645 UserCrosSettingsTrust::GetInstance(); | |
| 646 return g_browser_process->local_state()->GetBoolean( | |
| 647 kStatsReportingPref); | |
| 648 } | |
| 649 | |
| 650 // static | |
| 651 const ListValue* UserCrosSettingsProvider::cached_whitelist() { | |
| 652 PrefService* prefs = g_browser_process->local_state(); | |
| 653 const ListValue* cached_users = prefs->GetList(kAccountsPrefUsers); | |
| 654 if (!prefs->IsManagedPreference(kAccountsPrefUsers)) { | |
| 655 if (cached_users == NULL) { | |
| 656 // Update whitelist cache. | |
| 657 GetUserWhitelist(NULL); | |
| 658 cached_users = prefs->GetList(kAccountsPrefUsers); | |
| 659 } | |
| 660 } | |
| 661 if (cached_users == NULL) { | |
| 662 NOTREACHED(); | |
| 663 cached_users = new ListValue; | |
| 664 } | |
| 665 return cached_users; | |
| 666 } | |
| 667 | |
| 668 // static | |
| 669 std::string UserCrosSettingsProvider::cached_owner() { | |
| 670 // Trigger prefetching if singleton object still does not exist. | |
| 671 UserCrosSettingsTrust::GetInstance(); | |
| 672 if (!g_browser_process || !g_browser_process->local_state()) | |
| 673 return std::string(); | |
| 674 return g_browser_process->local_state()->GetString(kDeviceOwner); | |
| 675 } | |
| 676 | |
| 677 // static | |
| 678 bool UserCrosSettingsProvider::IsEmailInCachedWhitelist( | |
| 679 const std::string& email) { | |
| 680 const ListValue* whitelist = cached_whitelist(); | |
| 681 if (whitelist) { | |
| 682 StringValue email_value(email); | |
| 683 for (ListValue::const_iterator i(whitelist->begin()); | |
| 684 i != whitelist->end(); ++i) { | |
| 685 if ((*i)->Equals(&email_value)) | |
| 686 return true; | |
| 687 } | |
| 688 } | |
| 689 return false; | |
| 690 } | |
| 691 | |
| 692 void UserCrosSettingsProvider::DoSet(const std::string& path, | 558 void UserCrosSettingsProvider::DoSet(const std::string& path, |
| 693 Value* in_value) { | 559 Value* in_value) { |
| 694 UserCrosSettingsTrust::GetInstance()->Set(path, in_value); | 560 UserCrosSettingsTrust::GetInstance()->Set(path, in_value); |
| 695 } | 561 } |
| 696 | 562 |
| 697 bool UserCrosSettingsProvider::Get(const std::string& path, | 563 const base::Value* UserCrosSettingsProvider::Get( |
| 698 Value** out_value) const { | 564 const std::string& path) const { |
| 699 if (path == kAccountsPrefUsers) { | 565 if (HandlesSetting(path)) { |
| 700 ListValue* user_list = new ListValue; | 566 PrefService* prefs = g_browser_process->local_state(); |
| 701 GetUserWhitelist(user_list); | 567 // TODO(pastarmovj): Temporary hack until we refactor the user whitelisting |
| 702 *out_value = user_list; | 568 // handling to completely coincide with the rest of the settings. |
| 703 return true; | 569 if (path == kAccountsPrefUsers && |
| 570 prefs->GetList(kAccountsPrefUsers) == NULL) { | |
| 571 GetUserWhitelist(NULL); | |
| 572 } | |
| 573 const PrefService::Preference* pref = prefs->FindPreference(path.c_str()); | |
| 574 return pref->GetValue(); | |
| 575 } | |
| 576 return NULL; | |
| 577 } | |
| 578 | |
| 579 class TrustedEntryFetcher : public Task { | |
| 580 public: | |
| 581 explicit TrustedEntryFetcher(const base::Closure& callback) | |
| 582 : callback_(callback) { | |
| 704 } | 583 } |
| 705 | 584 |
| 706 if (IsControlledBooleanSetting(path) || IsControlledStringSetting(path)) { | 585 void Run() { |
| 707 PrefService* prefs = g_browser_process->local_state(); | 586 callback_.Run(); |
| 708 const PrefService::Preference* pref = prefs->FindPreference(path.c_str()); | |
| 709 const Value *pref_value = pref->GetValue(); | |
| 710 | |
| 711 *out_value = CreateSettingsValue( | |
| 712 pref_value->DeepCopy(), | |
| 713 g_browser_process->browser_policy_connector()->IsEnterpriseManaged(), | |
| 714 !UserManager::Get()->current_user_is_owner()); | |
| 715 return true; | |
| 716 } | 587 } |
| 717 | 588 |
| 718 return false; | 589 private: |
| 590 base::Closure callback_; | |
| 591 }; | |
| 592 | |
| 593 bool UserCrosSettingsProvider::GetTrusted(const std::string& path, | |
| 594 const base::Closure& callback) const { | |
| 595 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity( | |
| 596 path, new TrustedEntryFetcher(callback)); | |
| 719 } | 597 } |
| 720 | 598 |
| 721 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) const { | 599 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) const { |
| 722 return ::StartsWithASCII(path, "cros.accounts.", true) || | 600 return ::StartsWithASCII(path, "cros.accounts.", true) || |
| 723 ::StartsWithASCII(path, "cros.signed.", true) || | 601 ::StartsWithASCII(path, "cros.signed.", true) || |
| 724 ::StartsWithASCII(path, "cros.metrics.", true) || | 602 ::StartsWithASCII(path, "cros.metrics.", true) || |
| 603 path == kDeviceOwner || | |
| 725 path == kReleaseChannel; | 604 path == kReleaseChannel; |
| 726 } | 605 } |
| 727 | 606 |
| 607 // static | |
| 728 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { | 608 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { |
| 729 SignedSettingsHelper::Get()->StartWhitelistOp( | 609 SignedSettingsHelper::Get()->StartWhitelistOp( |
| 730 email, true, UserCrosSettingsTrust::GetInstance()); | 610 email, true, UserCrosSettingsTrust::GetInstance()); |
| 731 PrefService* prefs = g_browser_process->local_state(); | 611 PrefService* prefs = g_browser_process->local_state(); |
| 732 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); | 612 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); |
| 733 cached_whitelist_update->Append(Value::CreateStringValue(email)); | 613 cached_whitelist_update->Append(Value::CreateStringValue(email)); |
|
Chris Masone
2011/10/05 18:43:12
hm. I know you didn't add this code, but am I cor
pastarmovj
2011/10/13 11:23:02
Yes but the PolicyStoreOp will force reload of the
Chris Masone
2011/10/13 23:42:37
ok, sounds good.
| |
| 734 prefs->ScheduleSavePersistentPrefs(); | 614 prefs->ScheduleSavePersistentPrefs(); |
| 735 } | 615 } |
| 736 | 616 |
| 617 // static | |
| 737 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { | 618 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { |
| 738 SignedSettingsHelper::Get()->StartWhitelistOp( | 619 SignedSettingsHelper::Get()->StartWhitelistOp( |
| 739 email, false, UserCrosSettingsTrust::GetInstance()); | 620 email, false, UserCrosSettingsTrust::GetInstance()); |
| 740 | 621 |
| 741 PrefService* prefs = g_browser_process->local_state(); | 622 PrefService* prefs = g_browser_process->local_state(); |
| 742 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); | 623 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); |
| 743 StringValue email_value(email); | 624 StringValue email_value(email); |
| 744 if (cached_whitelist_update->Remove(email_value, NULL)) | 625 if (cached_whitelist_update->Remove(email_value, NULL)) |
| 745 prefs->ScheduleSavePersistentPrefs(); | 626 prefs->ScheduleSavePersistentPrefs(); |
| 746 } | 627 } |
| 747 | 628 |
| 748 // static | 629 // static |
| 749 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { | 630 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { |
| 750 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); | 631 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); |
| 751 } | 632 } |
| 752 | 633 |
| 753 } // namespace chromeos | 634 } // namespace chromeos |
| OLD | NEW |