Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/login/user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/chromeos/chromeos_version.h" | 12 #include "base/chromeos/chromeos_version.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/prefs/pref_registry_simple.h" | 18 #include "base/prefs/pref_registry_simple.h" |
| 19 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
| 20 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "chrome/browser/app_mode/app_mode_utils.h" | 25 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/chrome_notification_types.h" | 27 #include "chrome/browser/chrome_notification_types.h" |
| 28 #include "chrome/browser/chromeos/cros/cert_library.h" | 28 #include "chrome/browser/chromeos/cros/cert_library.h" |
| 29 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" | 29 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" |
| 30 #include "chrome/browser/chromeos/login/language_switch_menu.h" | |
| 30 #include "chrome/browser/chromeos/login/login_display.h" | 31 #include "chrome/browser/chromeos/login/login_display.h" |
| 31 #include "chrome/browser/chromeos/login/login_utils.h" | 32 #include "chrome/browser/chromeos/login/login_utils.h" |
| 32 #include "chrome/browser/chromeos/login/remove_user_delegate.h" | 33 #include "chrome/browser/chromeos/login/remove_user_delegate.h" |
| 33 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" | 34 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" |
| 34 #include "chrome/browser/chromeos/login/wizard_controller.h" | 35 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 35 #include "chrome/browser/chromeos/policy/device_local_account.h" | 36 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 37 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 36 #include "chrome/browser/chromeos/session_length_limiter.h" | 38 #include "chrome/browser/chromeos/session_length_limiter.h" |
| 37 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 39 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 38 #include "chrome/browser/managed_mode/managed_user_service.h" | 40 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 39 #include "chrome/browser/policy/browser_policy_connector.h" | 41 #include "chrome/browser/policy/browser_policy_connector.h" |
| 40 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 42 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 43 #include "chrome/browser/profiles/profile.h" | |
| 41 #include "chrome/browser/profiles/profile_manager.h" | 44 #include "chrome/browser/profiles/profile_manager.h" |
| 42 #include "chrome/browser/sync/profile_sync_service.h" | 45 #include "chrome/browser/sync/profile_sync_service.h" |
| 43 #include "chrome/browser/sync/profile_sync_service_factory.h" | 46 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 44 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
| 45 #include "chrome/common/pref_names.h" | 48 #include "chrome/common/pref_names.h" |
| 46 #include "chromeos/chromeos_switches.h" | 49 #include "chromeos/chromeos_switches.h" |
| 47 #include "chromeos/cryptohome/async_method_caller.h" | 50 #include "chromeos/cryptohome/async_method_caller.h" |
| 48 #include "chromeos/dbus/dbus_thread_manager.h" | 51 #include "chromeos/dbus/dbus_thread_manager.h" |
| 49 #include "chromeos/ime/input_method_manager.h" | 52 #include "chromeos/ime/input_method_manager.h" |
| 50 #include "chromeos/login/login_state.h" | 53 #include "chromeos/login/login_state.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 merge_session_state_(MERGE_STATUS_NOT_STARTED), | 227 merge_session_state_(MERGE_STATUS_NOT_STARTED), |
| 225 observed_sync_service_(NULL), | 228 observed_sync_service_(NULL), |
| 226 user_image_manager_(new UserImageManagerImpl), | 229 user_image_manager_(new UserImageManagerImpl), |
| 227 manager_creation_time_(base::TimeTicks::Now()) { | 230 manager_creation_time_(base::TimeTicks::Now()) { |
| 228 // UserManager instance should be used only on UI thread. | 231 // UserManager instance should be used only on UI thread. |
| 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 230 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, | 233 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, |
| 231 content::NotificationService::AllSources()); | 234 content::NotificationService::AllSources()); |
| 232 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 235 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 233 content::NotificationService::AllSources()); | 236 content::NotificationService::AllSources()); |
| 237 registrar_.Add(this, | |
| 238 chrome::NOTIFICATION_PROFILE_CREATED, | |
| 239 content::NotificationService::AllSources()); | |
| 234 RetrieveTrustedDevicePolicies(); | 240 RetrieveTrustedDevicePolicies(); |
| 235 cros_settings_->AddSettingsObserver(kAccountsPrefDeviceLocalAccounts, | 241 cros_settings_->AddSettingsObserver(kAccountsPrefDeviceLocalAccounts, |
| 236 this); | 242 this); |
| 237 cros_settings_->AddSettingsObserver(kAccountsPrefSupervisedUsersEnabled, | 243 cros_settings_->AddSettingsObserver(kAccountsPrefSupervisedUsersEnabled, |
| 238 this); | 244 this); |
| 239 UpdateLoginState(); | 245 UpdateLoginState(); |
| 240 } | 246 } |
| 241 | 247 |
| 242 UserManagerImpl::~UserManagerImpl() { | 248 UserManagerImpl::~UserManagerImpl() { |
| 243 // Can't use STLDeleteElements because of the private destructor of User. | 249 // Can't use STLDeleteElements because of the private destructor of User. |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 static_cast<User::OAuthTokenStatus>(oauth_token_status); | 647 static_cast<User::OAuthTokenStatus>(oauth_token_status); |
| 642 if (result == User::OAUTH2_TOKEN_STATUS_INVALID) | 648 if (result == User::OAUTH2_TOKEN_STATUS_INVALID) |
| 643 GetUserFlow(username)->HandleOAuthTokenStatusChange(result); | 649 GetUserFlow(username)->HandleOAuthTokenStatusChange(result); |
| 644 return result; | 650 return result; |
| 645 } | 651 } |
| 646 return User::OAUTH_TOKEN_STATUS_UNKNOWN; | 652 return User::OAUTH_TOKEN_STATUS_UNKNOWN; |
| 647 } | 653 } |
| 648 | 654 |
| 649 void UserManagerImpl::SaveUserDisplayName(const std::string& username, | 655 void UserManagerImpl::SaveUserDisplayName(const std::string& username, |
| 650 const string16& display_name) { | 656 const string16& display_name) { |
| 657 UpdateUserAccountDataImpl(username, display_name, NULL); | |
| 658 } | |
| 659 | |
| 660 void UserManagerImpl::UpdateUserAccountData(const std::string& username, | |
| 661 const string16& display_name, | |
| 662 const std::string& locale) { | |
| 663 UpdateUserAccountDataImpl(username, display_name, &locale); | |
| 664 } | |
| 665 | |
| 666 void UserManagerImpl::UpdateUserAccountDataImpl(const std::string& username, | |
| 667 const string16& display_name, | |
| 668 const std::string* locale) { | |
| 651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 652 | 670 |
| 653 User* user = FindUserAndModify(username); | 671 User* user = FindUserAndModify(username); |
| 654 if (!user) | 672 if (!user) |
| 655 return; // Ignore if there is no such user. | 673 return; // Ignore if there is no such user. |
| 656 | 674 |
| 675 // locale is not NULL if User Account has been downloaded | |
| 676 // (i.e. it is UpdateUserAccountData(), not SaveUserDisplayName() ) | |
| 677 if (locale != NULL) { | |
| 678 user->SetAccountLocale(*locale); | |
| 679 RespectLocalePreference( | |
| 680 g_browser_process->profile_manager()->GetDefaultProfile(), user); | |
|
Dmitry Polukhin
2013/09/14 15:58:46
Here you need to use profile associated with usern
Alexander Alekseev
2013/09/16 18:39:07
Done.
| |
| 681 } | |
| 682 | |
| 683 if (display_name.empty()) | |
| 684 return; | |
| 685 | |
| 657 user->set_display_name(display_name); | 686 user->set_display_name(display_name); |
| 658 | 687 |
| 659 // Do not update local store if data stored or cached outside the user's | 688 // Do not update local store if data stored or cached outside the user's |
| 660 // cryptohome is to be treated as ephemeral. | 689 // cryptohome is to be treated as ephemeral. |
| 661 if (IsUserNonCryptohomeDataEphemeral(username)) | 690 if (IsUserNonCryptohomeDataEphemeral(username)) |
| 662 return; | 691 return; |
| 663 | 692 |
| 664 PrefService* local_state = g_browser_process->local_state(); | 693 PrefService* local_state = g_browser_process->local_state(); |
| 665 | 694 |
| 666 DictionaryPrefUpdate display_name_update(local_state, kUserDisplayName); | 695 DictionaryPrefUpdate display_name_update(local_state, kUserDisplayName); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 username, | 744 username, |
| 716 new base::StringValue(display_email)); | 745 new base::StringValue(display_email)); |
| 717 } | 746 } |
| 718 | 747 |
| 719 std::string UserManagerImpl::GetUserDisplayEmail( | 748 std::string UserManagerImpl::GetUserDisplayEmail( |
| 720 const std::string& username) const { | 749 const std::string& username) const { |
| 721 const User* user = FindUser(username); | 750 const User* user = FindUser(username); |
| 722 return user ? user->display_email() : username; | 751 return user ? user->display_email() : username; |
| 723 } | 752 } |
| 724 | 753 |
| 754 // TODO(alemate): http://crbug.com/288941 : Respect preferred language list in | |
| 755 // the Google user profile. | |
| 756 void UserManagerImpl::RespectLocalePreference(Profile* profile, | |
| 757 const User* user) const { | |
| 758 if (g_browser_process == NULL) | |
| 759 return; | |
| 760 if ((active_user_ == NULL) || (user != active_user_) || | |
| 761 !active_user_->is_profile_created()) | |
| 762 return; | |
| 763 | |
| 764 if (profile != ProfileManager::GetDefaultProfile()) | |
| 765 return; | |
| 766 const PrefService* prefs = profile->GetPrefs(); | |
| 767 if (prefs == NULL) | |
| 768 return; | |
| 769 | |
| 770 std::string pref_locale = prefs->GetString(prefs::kApplicationLocale); | |
| 771 if (pref_locale.empty()) | |
| 772 pref_locale = prefs->GetString(prefs::kApplicationLocaleBackup); | |
| 773 | |
| 774 if (pref_locale.empty() && user->has_gaia_account()) { | |
| 775 if (user->GetAccountLocale() == NULL) | |
| 776 return; // wait until Account profile is loaded. | |
| 777 pref_locale = *(user->GetAccountLocale()); | |
| 778 } | |
| 779 if (pref_locale.empty()) | |
| 780 pref_locale = g_browser_process->GetApplicationLocale(); | |
| 781 DCHECK(!pref_locale.empty()); | |
| 782 profile->ChangeAppLocale(pref_locale, Profile::APP_LOCALE_CHANGED_VIA_LOGIN); | |
| 783 // Here we don't enable keyboard layouts. Input methods are set up when | |
| 784 // the user first logs in. Then the user may customize the input methods. | |
| 785 // Hence changing input methods here, just because the user's UI language | |
| 786 // is different from the login screen UI language, is not desirable. Note | |
| 787 // that input method preferences are synced, so users can use their | |
| 788 // farovite input methods as soon as the preferences are synced. | |
| 789 chromeos::LanguageSwitchMenu::SwitchLanguage(pref_locale); | |
| 790 } | |
| 791 | |
| 792 class UserHashMatcher { | |
| 793 public: | |
| 794 explicit UserHashMatcher(const std::string& h) : username_hash(h) {} | |
| 795 bool operator()(const User* user) const { | |
| 796 return user->username_hash() == username_hash; | |
| 797 } | |
| 798 | |
| 799 private: | |
| 800 const std::string& username_hash; | |
| 801 }; | |
| 802 | |
| 803 // Returns NULL if user is not created | |
| 804 User* UserManagerImpl::GetUserByProfile(Profile* profile) { | |
|
Dmitry Polukhin
2013/09/14 15:58:46
This can be done simpler. You can get user email f
Alexander Alekseev
2013/09/16 18:39:07
As far as I know, GetProfileName() is a real e-mai
Dmitry Polukhin
2013/09/16 19:02:26
GetProfileName is set in InitProfilePreferences an
Alexander Alekseev
2013/09/18 20:21:19
Done.
| |
| 805 if (CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles)) { | |
| 806 const std::string username_hash = | |
| 807 ProfileHelper::GetUserIdHashFromProfile(profile); | |
| 808 const UserList& users = GetUsers(); | |
| 809 const UserList::const_iterator pos = std::find_if( | |
| 810 users.begin(), users.end(), UserHashMatcher(username_hash)); | |
| 811 return (pos != users.end()) ? *pos : NULL; | |
| 812 } | |
| 813 return active_user_; | |
| 814 } | |
| 815 | |
| 725 void UserManagerImpl::Observe(int type, | 816 void UserManagerImpl::Observe(int type, |
| 726 const content::NotificationSource& source, | 817 const content::NotificationSource& source, |
| 727 const content::NotificationDetails& details) { | 818 const content::NotificationDetails& details) { |
| 728 switch (type) { | 819 switch (type) { |
| 729 case chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED: | 820 case chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED: |
| 730 if (!device_local_account_policy_service_) { | 821 if (!device_local_account_policy_service_) { |
| 731 device_local_account_policy_service_ = | 822 device_local_account_policy_service_ = |
| 732 g_browser_process->browser_policy_connector()-> | 823 g_browser_process->browser_policy_connector()-> |
| 733 GetDeviceLocalAccountPolicyService(); | 824 GetDeviceLocalAccountPolicyService(); |
| 734 if (device_local_account_policy_service_) | 825 if (device_local_account_policy_service_) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 751 HasSwitch(::switches::kMultiProfiles)) { | 842 HasSwitch(::switches::kMultiProfiles)) { |
| 752 DCHECK(NULL == observed_sync_service_); | 843 DCHECK(NULL == observed_sync_service_); |
| 753 observed_sync_service_ = | 844 observed_sync_service_ = |
| 754 ProfileSyncServiceFactory::GetForProfile(profile); | 845 ProfileSyncServiceFactory::GetForProfile(profile); |
| 755 if (observed_sync_service_) | 846 if (observed_sync_service_) |
| 756 observed_sync_service_->AddObserver(this); | 847 observed_sync_service_->AddObserver(this); |
| 757 } | 848 } |
| 758 } | 849 } |
| 759 } | 850 } |
| 760 break; | 851 break; |
| 852 case chrome::NOTIFICATION_PROFILE_CREATED: { | |
| 853 Profile* profile = content::Source<Profile>(source).ptr(); | |
| 854 User* user = GetUserByProfile(profile); | |
| 855 if (user != NULL) { | |
| 856 user->set_profile_is_created(); | |
| 857 if (user == active_user_) | |
| 858 RespectLocalePreference(profile, user); | |
| 859 } | |
| 860 break; | |
| 861 } | |
| 761 case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: { | 862 case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: { |
| 762 std::string changed_setting = | 863 std::string changed_setting = |
| 763 *content::Details<const std::string>(details).ptr(); | 864 *content::Details<const std::string>(details).ptr(); |
| 764 DCHECK(changed_setting == kAccountsPrefDeviceLocalAccounts || | 865 DCHECK(changed_setting == kAccountsPrefDeviceLocalAccounts || |
| 765 changed_setting == kAccountsPrefSupervisedUsersEnabled); | 866 changed_setting == kAccountsPrefSupervisedUsersEnabled); |
| 766 RetrieveTrustedDevicePolicies(); | 867 RetrieveTrustedDevicePolicies(); |
| 767 break; | 868 break; |
| 768 } | 869 } |
| 769 default: | 870 default: |
| 770 NOTREACHED(); | 871 NOTREACHED(); |
| (...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1804 base::TimeTicks::Now() - manager_creation_time_; | 1905 base::TimeTicks::Now() - manager_creation_time_; |
| 1805 if (!last_email.empty() && email != last_email && | 1906 if (!last_email.empty() && email != last_email && |
| 1806 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { | 1907 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { |
| 1807 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", | 1908 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", |
| 1808 time_to_login.InSeconds(), 0, kLogoutToLoginDelayMaxSec, 50); | 1909 time_to_login.InSeconds(), 0, kLogoutToLoginDelayMaxSec, 50); |
| 1809 } | 1910 } |
| 1810 } | 1911 } |
| 1811 } | 1912 } |
| 1812 | 1913 |
| 1813 } // namespace chromeos | 1914 } // namespace chromeos |
| OLD | NEW |