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

Side by Side Diff: chrome/browser/chromeos/user_cros_settings_provider.cc

Issue 7867044: PART1: Initiated the SignedSettings refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up some debug output. Created 9 years, 3 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) 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
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)
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 // static 554 // static
567 void UserCrosSettingsProvider::RegisterPrefs(PrefService* local_state) { 555 void UserCrosSettingsProvider::RegisterPrefs(PrefService* local_state) {
568 for (size_t i = 0; i < arraysize(kBooleanSettings); ++i) 556 for (size_t i = 0; i < arraysize(kBooleanSettings); ++i)
569 RegisterSetting(local_state, kBooleanSettings[i]); 557 RegisterSetting(local_state, kBooleanSettings[i]);
570 for (size_t i = 0; i < arraysize(kStringSettings); ++i) 558 for (size_t i = 0; i < arraysize(kStringSettings); ++i)
571 RegisterSetting(local_state, kStringSettings[i]); 559 RegisterSetting(local_state, kStringSettings[i]);
572 for (size_t i = 0; i < arraysize(kListSettings); ++i) 560 for (size_t i = 0; i < arraysize(kListSettings); ++i)
573 RegisterSetting(local_state, kListSettings[i]); 561 RegisterSetting(local_state, kListSettings[i]);
574 } 562 }
575 563
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() { 564 void UserCrosSettingsProvider::Reload() {
608 UserCrosSettingsTrust::GetInstance()->Reload(); 565 UserCrosSettingsTrust::GetInstance()->Reload();
609 } 566 }
610 567
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, 568 void UserCrosSettingsProvider::DoSet(const std::string& path,
693 Value* in_value) { 569 Value* in_value) {
694 UserCrosSettingsTrust::GetInstance()->Set(path, in_value); 570 UserCrosSettingsTrust::GetInstance()->Set(path, in_value);
695 } 571 }
696 572
697 bool UserCrosSettingsProvider::Get(const std::string& path, 573 const base::Value* UserCrosSettingsProvider::Get(
698 Value** out_value) const { 574 const std::string& path) const {
699 if (path == kAccountsPrefUsers) { 575 if (HandlesSetting(path)) {
700 ListValue* user_list = new ListValue; 576 PrefService* prefs = g_browser_process->local_state();
701 GetUserWhitelist(user_list); 577 const PrefService::Preference* pref = prefs->FindPreference(path.c_str());
702 *out_value = user_list; 578 return pref->GetValue();
703 return true; 579 }
580 return NULL;
581 }
582
583 class TrustedEntryFetcher : public Task {
584 public:
585 explicit TrustedEntryFetcher(const CrosSettingsProvider::Callback& callback)
586 : callback_(callback) {
704 } 587 }
705 588
706 if (IsControlledBooleanSetting(path) || IsControlledStringSetting(path)) { 589 void Run() {
707 PrefService* prefs = g_browser_process->local_state(); 590 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 } 591 }
717 592
718 return false; 593 private:
594 CrosSettingsProvider::Callback callback_;
595 };
596
597 bool UserCrosSettingsProvider::GetTrusted(const std::string& path,
598 const Callback& callback) const {
599 return UserCrosSettingsTrust::GetInstance()->RequestTrustedEntity(
600 path, new TrustedEntryFetcher(callback));
719 } 601 }
720 602
721 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) const { 603 bool UserCrosSettingsProvider::HandlesSetting(const std::string& path) const {
722 return ::StartsWithASCII(path, "cros.accounts.", true) || 604 return ::StartsWithASCII(path, "cros.accounts.", true) ||
723 ::StartsWithASCII(path, "cros.signed.", true) || 605 ::StartsWithASCII(path, "cros.signed.", true) ||
724 ::StartsWithASCII(path, "cros.metrics.", true) || 606 ::StartsWithASCII(path, "cros.metrics.", true) ||
607 path == kDeviceOwner ||
725 path == kReleaseChannel; 608 path == kReleaseChannel;
726 } 609 }
727 610
728 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) { 611 void UserCrosSettingsProvider::WhitelistUser(const std::string& email) {
729 SignedSettingsHelper::Get()->StartWhitelistOp( 612 SignedSettingsHelper::Get()->StartWhitelistOp(
730 email, true, UserCrosSettingsTrust::GetInstance()); 613 email, true, UserCrosSettingsTrust::GetInstance());
731 PrefService* prefs = g_browser_process->local_state(); 614 PrefService* prefs = g_browser_process->local_state();
732 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); 615 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers);
733 cached_whitelist_update->Append(Value::CreateStringValue(email)); 616 cached_whitelist_update->Append(Value::CreateStringValue(email));
734 prefs->ScheduleSavePersistentPrefs(); 617 prefs->ScheduleSavePersistentPrefs();
735 } 618 }
736 619
737 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) { 620 void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) {
738 SignedSettingsHelper::Get()->StartWhitelistOp( 621 SignedSettingsHelper::Get()->StartWhitelistOp(
739 email, false, UserCrosSettingsTrust::GetInstance()); 622 email, false, UserCrosSettingsTrust::GetInstance());
740 623
741 PrefService* prefs = g_browser_process->local_state(); 624 PrefService* prefs = g_browser_process->local_state();
742 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers); 625 ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers);
743 StringValue email_value(email); 626 StringValue email_value(email);
744 if (cached_whitelist_update->Remove(email_value, NULL)) 627 if (cached_whitelist_update->Remove(email_value, NULL))
745 prefs->ScheduleSavePersistentPrefs(); 628 prefs->ScheduleSavePersistentPrefs();
746 } 629 }
747 630
748 // static 631 // static
749 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { 632 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) {
750 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); 633 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED);
751 } 634 }
752 635
753 } // namespace chromeos 636 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698