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

Side by Side Diff: chrome/browser/chromeos/login/user_manager_impl.cc

Issue 23095006: If user profile doesn't contain language setting, default to his Google account settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 7 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
OLDNEW
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"
(...skipping 10 matching lines...) Expand all
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/login/auth_sync_observer.h" 28 #include "chrome/browser/chromeos/login/auth_sync_observer.h"
29 #include "chrome/browser/chromeos/login/auth_sync_observer_factory.h" 29 #include "chrome/browser/chromeos/login/auth_sync_observer_factory.h"
30 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" 30 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h"
31 #include "chrome/browser/chromeos/login/language_switch_menu.h"
31 #include "chrome/browser/chromeos/login/login_display.h" 32 #include "chrome/browser/chromeos/login/login_display.h"
32 #include "chrome/browser/chromeos/login/login_utils.h" 33 #include "chrome/browser/chromeos/login/login_utils.h"
33 #include "chrome/browser/chromeos/login/remove_user_delegate.h" 34 #include "chrome/browser/chromeos/login/remove_user_delegate.h"
34 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" 35 #include "chrome/browser/chromeos/login/user_image_manager_impl.h"
35 #include "chrome/browser/chromeos/login/wizard_controller.h" 36 #include "chrome/browser/chromeos/login/wizard_controller.h"
36 #include "chrome/browser/chromeos/policy/device_local_account.h" 37 #include "chrome/browser/chromeos/policy/device_local_account.h"
38 #include "chrome/browser/chromeos/profiles/profile_helper.h"
37 #include "chrome/browser/chromeos/session_length_limiter.h" 39 #include "chrome/browser/chromeos/session_length_limiter.h"
38 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 40 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
39 #include "chrome/browser/managed_mode/managed_user_service.h" 41 #include "chrome/browser/managed_mode/managed_user_service.h"
40 #include "chrome/browser/policy/browser_policy_connector.h" 42 #include "chrome/browser/policy/browser_policy_connector.h"
41 #include "chrome/browser/prefs/scoped_user_pref_update.h" 43 #include "chrome/browser/prefs/scoped_user_pref_update.h"
44 #include "chrome/browser/profiles/profile.h"
42 #include "chrome/browser/profiles/profile_manager.h" 45 #include "chrome/browser/profiles/profile_manager.h"
43 #include "chrome/browser/sync/profile_sync_service.h" 46 #include "chrome/browser/sync/profile_sync_service.h"
44 #include "chrome/browser/sync/profile_sync_service_factory.h" 47 #include "chrome/browser/sync/profile_sync_service_factory.h"
45 #include "chrome/common/chrome_constants.h" 48 #include "chrome/common/chrome_constants.h"
46 #include "chrome/common/chrome_switches.h" 49 #include "chrome/common/chrome_switches.h"
47 #include "chrome/common/pref_names.h" 50 #include "chrome/common/pref_names.h"
48 #include "chromeos/chromeos_switches.h" 51 #include "chromeos/chromeos_switches.h"
49 #include "chromeos/cryptohome/async_method_caller.h" 52 #include "chromeos/cryptohome/async_method_caller.h"
50 #include "chromeos/dbus/dbus_thread_manager.h" 53 #include "chromeos/dbus/dbus_thread_manager.h"
51 #include "chromeos/login/login_state.h" 54 #include "chromeos/login/login_state.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 is_current_user_ephemeral_regular_user_(false), 231 is_current_user_ephemeral_regular_user_(false),
229 ephemeral_users_enabled_(false), 232 ephemeral_users_enabled_(false),
230 user_image_manager_(new UserImageManagerImpl), 233 user_image_manager_(new UserImageManagerImpl),
231 manager_creation_time_(base::TimeTicks::Now()) { 234 manager_creation_time_(base::TimeTicks::Now()) {
232 // UserManager instance should be used only on UI thread. 235 // UserManager instance should be used only on UI thread.
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
234 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, 237 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED,
235 content::NotificationService::AllSources()); 238 content::NotificationService::AllSources());
236 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 239 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
237 content::NotificationService::AllSources()); 240 content::NotificationService::AllSources());
241 registrar_.Add(this,
242 chrome::NOTIFICATION_PROFILE_CREATED,
243 content::NotificationService::AllSources());
238 RetrieveTrustedDevicePolicies(); 244 RetrieveTrustedDevicePolicies();
239 local_accounts_subscription_ = cros_settings_->AddSettingsObserver( 245 local_accounts_subscription_ = cros_settings_->AddSettingsObserver(
240 kAccountsPrefDeviceLocalAccounts, 246 kAccountsPrefDeviceLocalAccounts,
241 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, 247 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies,
242 base::Unretained(this))); 248 base::Unretained(this)));
243 supervised_users_subscription_ = cros_settings_->AddSettingsObserver( 249 supervised_users_subscription_ = cros_settings_->AddSettingsObserver(
244 kAccountsPrefSupervisedUsersEnabled, 250 kAccountsPrefSupervisedUsersEnabled,
245 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, 251 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies,
246 base::Unretained(this))); 252 base::Unretained(this)));
247 UpdateLoginState(); 253 UpdateLoginState();
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 static_cast<User::OAuthTokenStatus>(oauth_token_status); 696 static_cast<User::OAuthTokenStatus>(oauth_token_status);
691 if (result == User::OAUTH2_TOKEN_STATUS_INVALID) 697 if (result == User::OAUTH2_TOKEN_STATUS_INVALID)
692 GetUserFlow(username)->HandleOAuthTokenStatusChange(result); 698 GetUserFlow(username)->HandleOAuthTokenStatusChange(result);
693 return result; 699 return result;
694 } 700 }
695 return User::OAUTH_TOKEN_STATUS_UNKNOWN; 701 return User::OAUTH_TOKEN_STATUS_UNKNOWN;
696 } 702 }
697 703
698 void UserManagerImpl::SaveUserDisplayName(const std::string& username, 704 void UserManagerImpl::SaveUserDisplayName(const std::string& username,
699 const string16& display_name) { 705 const string16& display_name) {
706 UpdateUserAccountDataImpl(username, display_name, NULL);
707 }
708
709 void UserManagerImpl::UpdateUserAccountData(const std::string& username,
710 const string16& display_name,
711 const std::string& locale) {
712 UpdateUserAccountDataImpl(username, display_name, &locale);
713 }
714
715 void UserManagerImpl::UpdateUserAccountDataImpl(const std::string& username,
716 const string16& display_name,
717 const std::string* locale) {
700 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
701 719
702 User* user = FindUserAndModify(username); 720 User* user = FindUserAndModify(username);
703 if (!user) 721 if (!user)
704 return; // Ignore if there is no such user. 722 return; // Ignore if there is no such user.
705 723
724 // locale is not NULL if User Account has been downloaded
725 // (i.e. it is UpdateUserAccountData(), not SaveUserDisplayName() )
726 if (locale != NULL) {
727 user->SetAccountLocale(*locale);
728 RespectLocalePreference(GetProfileByUser(user), user);
729 }
730
731 if (display_name.empty())
732 return;
733
706 user->set_display_name(display_name); 734 user->set_display_name(display_name);
707 735
708 // Do not update local store if data stored or cached outside the user's 736 // Do not update local store if data stored or cached outside the user's
709 // cryptohome is to be treated as ephemeral. 737 // cryptohome is to be treated as ephemeral.
710 if (IsUserNonCryptohomeDataEphemeral(username)) 738 if (IsUserNonCryptohomeDataEphemeral(username))
711 return; 739 return;
712 740
713 PrefService* local_state = g_browser_process->local_state(); 741 PrefService* local_state = g_browser_process->local_state();
714 742
715 DictionaryPrefUpdate display_name_update(local_state, kUserDisplayName); 743 DictionaryPrefUpdate display_name_update(local_state, kUserDisplayName);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 username, 792 username,
765 new base::StringValue(display_email)); 793 new base::StringValue(display_email));
766 } 794 }
767 795
768 std::string UserManagerImpl::GetUserDisplayEmail( 796 std::string UserManagerImpl::GetUserDisplayEmail(
769 const std::string& username) const { 797 const std::string& username) const {
770 const User* user = FindUser(username); 798 const User* user = FindUser(username);
771 return user ? user->display_email() : username; 799 return user ? user->display_email() : username;
772 } 800 }
773 801
802 // TODO(alemate): http://crbug.com/288941 : Respect preferred language list in
803 // the Google user profile.
804 void UserManagerImpl::RespectLocalePreference(Profile* profile,
805 const User* user) const {
806 if (g_browser_process == NULL)
807 return;
808 if ((user == NULL) || (user != GetPrimaryUser()) ||
809 (!user->is_profile_created()))
810 return;
811
812 // In case of Multi Profile mode we don't apply profile locale because it is
813 // unsafe.
814 if (GetLoggedInUsers().size() != 1)
815 return;
816 const PrefService* prefs = profile->GetPrefs();
817 if (prefs == NULL)
818 return;
819
820 std::string pref_locale;
821 const std::string pref_app_locale =
822 prefs->GetString(prefs::kApplicationLocale);
823 const std::string pref_bkup_locale =
824 prefs->GetString(prefs::kApplicationLocaleBackup);
825
826 pref_locale = pref_app_locale;
827 if (pref_locale.empty())
828 pref_locale = pref_bkup_locale;
829
830 const std::string* account_locale = NULL;
831 if (pref_locale.empty() && user->has_gaia_account()) {
832 if (user->GetAccountLocale() == NULL)
833 return; // wait until Account profile is loaded.
834 account_locale = user->GetAccountLocale();
835 pref_locale = *account_locale;
836 }
837 const std::string global_app_locale =
838 g_browser_process->GetApplicationLocale();
839 if (pref_locale.empty())
840 pref_locale = global_app_locale;
841 DCHECK(!pref_locale.empty());
842 LOG(WARNING) << "RespectLocalePreference: "
843 << "app_locale='" << pref_app_locale << "', "
844 << "bkup_locale='" << pref_bkup_locale << "', "
845 << (account_locale != NULL
846 ? (std::string("account_locale='") + (*account_locale) +
847 "'. ")
848 : (std::string("account_locale - unused. ")))
849 << " Selected '" << pref_locale << "'";
850 profile->ChangeAppLocale(pref_locale, Profile::APP_LOCALE_CHANGED_VIA_LOGIN);
851 // Here we don't enable keyboard layouts. Input methods are set up when
852 // the user first logs in. Then the user may customize the input methods.
853 // Hence changing input methods here, just because the user's UI language
854 // is different from the login screen UI language, is not desirable. Note
855 // that input method preferences are synced, so users can use their
856 // farovite input methods as soon as the preferences are synced.
857 chromeos::LanguageSwitchMenu::SwitchLanguage(pref_locale);
858 }
859
860 class UserHashMatcher {
861 public:
862 explicit UserHashMatcher(const std::string& h) : username_hash(h) {}
863 bool operator()(const User* user) const {
864 return user->username_hash() == username_hash;
865 }
866
867 private:
868 const std::string& username_hash;
869 };
870
871 // Returns NULL if user is not created
872 User* UserManagerImpl::GetUserByProfile(Profile* profile) const {
873 if (IsMultipleProfilesAllowed()) {
874 const std::string username_hash =
875 ProfileHelper::GetUserIdHashFromProfile(profile);
876 const UserList& users = GetUsers();
877 const UserList::const_iterator pos = std::find_if(
878 users.begin(), users.end(), UserHashMatcher(username_hash));
879 return (pos != users.end()) ? *pos : NULL;
880 }
881 return active_user_;
882 }
883
884 Profile* UserManagerImpl::GetProfileByUser(const User* user) const {
885 if (IsMultipleProfilesAllowed())
886 return ProfileHelper::GetProfileByUserIdHash(user->username_hash());
887 return g_browser_process->profile_manager()->GetDefaultProfile();
888 }
889
774 void UserManagerImpl::Observe(int type, 890 void UserManagerImpl::Observe(int type,
775 const content::NotificationSource& source, 891 const content::NotificationSource& source,
776 const content::NotificationDetails& details) { 892 const content::NotificationDetails& details) {
777 switch (type) { 893 switch (type) {
778 case chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED: 894 case chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED:
779 if (!device_local_account_policy_service_) { 895 if (!device_local_account_policy_service_) {
780 device_local_account_policy_service_ = 896 device_local_account_policy_service_ =
781 g_browser_process->browser_policy_connector()-> 897 g_browser_process->browser_policy_connector()->
782 GetDeviceLocalAccountPolicyService(); 898 GetDeviceLocalAccountPolicyService();
783 if (device_local_account_policy_service_) 899 if (device_local_account_policy_service_)
784 device_local_account_policy_service_->AddObserver(this); 900 device_local_account_policy_service_->AddObserver(this);
785 } 901 }
786 RetrieveTrustedDevicePolicies(); 902 RetrieveTrustedDevicePolicies();
787 UpdateOwnership(); 903 UpdateOwnership();
788 break; 904 break;
789 case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: 905 case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED:
790 if (IsUserLoggedIn() && 906 if (IsUserLoggedIn() &&
791 !IsLoggedInAsGuest() && 907 !IsLoggedInAsGuest() &&
792 !IsLoggedInAsKioskApp()) { 908 !IsLoggedInAsKioskApp()) {
793 Profile* profile = content::Details<Profile>(details).ptr(); 909 Profile* profile = content::Details<Profile>(details).ptr();
794 if (!profile->IsOffTheRecord()) { 910 if (!profile->IsOffTheRecord()) {
795 AuthSyncObserver* sync_observer = 911 AuthSyncObserver* sync_observer =
796 AuthSyncObserverFactory::GetInstance()->GetForProfile(profile); 912 AuthSyncObserverFactory::GetInstance()->GetForProfile(profile);
797 sync_observer->StartObserving(); 913 sync_observer->StartObserving();
798 } 914 }
799 } 915 }
800 break; 916 break;
917 case chrome::NOTIFICATION_PROFILE_CREATED: {
918 Profile* profile = content::Source<Profile>(source).ptr();
919 User* user = GetUserByProfile(profile);
920 if (user != NULL) {
921 user->set_profile_is_created();
922 if (user == active_user_)
923 RespectLocalePreference(profile, user);
924 }
925 break;
926 }
801 default: 927 default:
802 NOTREACHED(); 928 NOTREACHED();
803 } 929 }
804 } 930 }
805 931
806 void UserManagerImpl::OnPolicyUpdated(const std::string& user_id) { 932 void UserManagerImpl::OnPolicyUpdated(const std::string& user_id) {
807 UpdatePublicAccountDisplayName(user_id); 933 UpdatePublicAccountDisplayName(user_id);
808 NotifyUserListChanged(); 934 NotifyUserListChanged();
809 } 935 }
810 936
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 base::TimeTicks::Now() - manager_creation_time_; 1950 base::TimeTicks::Now() - manager_creation_time_;
1825 if (!last_email.empty() && email != last_email && 1951 if (!last_email.empty() && email != last_email &&
1826 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { 1952 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) {
1827 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", 1953 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay",
1828 time_to_login.InSeconds(), 0, kLogoutToLoginDelayMaxSec, 50); 1954 time_to_login.InSeconds(), 0, kLogoutToLoginDelayMaxSec, 50);
1829 } 1955 }
1830 } 1956 }
1831 } 1957 }
1832 1958
1833 } // namespace chromeos 1959 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.h ('k') | chrome/browser/profiles/profile_downloader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698