Chromium Code Reviews| Index: chrome/browser/chromeos/login/user_manager_impl.cc |
| diff --git a/chrome/browser/chromeos/login/user_manager_impl.cc b/chrome/browser/chromeos/login/user_manager_impl.cc |
| index cdcf4bb5c9abf714e71aa973515785e6eca10bde..77d71365682c4f145c493914a1f71b4d9c286c77 100644 |
| --- a/chrome/browser/chromeos/login/user_manager_impl.cc |
| +++ b/chrome/browser/chromeos/login/user_manager_impl.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/chromeos/chromeos_version.h" |
| #include "base/command_line.h" |
| #include "base/compiler_specific.h" |
| +#include "base/debug/stack_trace.h" |
| #include "base/files/file_path.h" |
| #include "base/logging.h" |
| #include "base/metrics/histogram.h" |
| @@ -27,17 +28,20 @@ |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/chromeos/cros/cert_library.h" |
| #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" |
| +#include "chrome/browser/chromeos/login/language_switch_menu.h" |
| #include "chrome/browser/chromeos/login/login_display.h" |
| #include "chrome/browser/chromeos/login/login_utils.h" |
| #include "chrome/browser/chromeos/login/remove_user_delegate.h" |
| #include "chrome/browser/chromeos/login/user_image_manager_impl.h" |
| #include "chrome/browser/chromeos/login/wizard_controller.h" |
| #include "chrome/browser/chromeos/policy/device_local_account.h" |
| +#include "chrome/browser/chromeos/profiles/profile_helper.h" |
| #include "chrome/browser/chromeos/session_length_limiter.h" |
| #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| #include "chrome/browser/managed_mode/managed_user_service.h" |
| #include "chrome/browser/policy/browser_policy_connector.h" |
| #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/sync/profile_sync_service.h" |
| #include "chrome/browser/sync/profile_sync_service_factory.h" |
| @@ -231,6 +235,9 @@ UserManagerImpl::UserManagerImpl() |
| content::NotificationService::AllSources()); |
| registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| content::NotificationService::AllSources()); |
| + registrar_.Add(this, |
| + chrome::NOTIFICATION_PROFILE_CREATED, |
| + content::NotificationService::AllSources()); |
| RetrieveTrustedDevicePolicies(); |
| cros_settings_->AddSettingsObserver(kAccountsPrefDeviceLocalAccounts, |
| this); |
| @@ -648,12 +655,35 @@ User::OAuthTokenStatus UserManagerImpl::LoadUserOAuthStatus( |
| void UserManagerImpl::SaveUserDisplayName(const std::string& username, |
| const string16& display_name) { |
| + UpdateUserAccountDataImpl(username, display_name, NULL); |
| +} |
| + |
| +void UserManagerImpl::UpdateUserAccountData(const std::string& username, |
| + const string16& display_name, |
| + const std::string& locale) { |
| + UpdateUserAccountDataImpl(username, display_name, &locale); |
| +} |
| + |
| +void UserManagerImpl::UpdateUserAccountDataImpl(const std::string& username, |
| + const string16& display_name, |
| + const std::string* locale) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| User* user = FindUserAndModify(username); |
| if (!user) |
| return; // Ignore if there is no such user. |
| + // locale is not NULL if User Account has been downloaded |
| + // (i.e. it is UpdateUserAccountData(), not SaveUserDisplayName() ) |
| + if (locale != NULL) { |
| + user->SetAccountLocale(*locale); |
| + RespectLocalePreference( |
| + g_browser_process->profile_manager()->GetDefaultProfile(), user); |
| + } |
| + |
| + if (display_name.empty()) |
| + return; |
| + |
| user->set_display_name(display_name); |
| // Do not update local store if data stored or cached outside the user's |
| @@ -722,6 +752,71 @@ std::string UserManagerImpl::GetUserDisplayEmail( |
| return user ? user->display_email() : username; |
| } |
| +// TODO(alemate): Jungshik Shin: 2013/08/26 16:42:50 |
|
Dmitry Polukhin
2013/09/06 20:30:05
Please file issue about and add here. TODO(alemate
Alexander Alekseev
2013/09/11 18:53:02
Done.
|
| +// This does not take into account the preferred language list in the Google |
| +// user profile. If a user's primary language is not supported by Chrome OS |
| +// (let's say, "Foo") but one of languages in the fallback list in the user's |
| +// Google profile (e.g. French) is supported by Chrome, we have to pick it up |
| +// instead of falling back to the universal (hard-coded) fallback ('en-US'). |
| +void UserManagerImpl::RespectLocalePreference(Profile* profile, |
| + const User* user) const { |
| + if (g_browser_process == NULL) |
| + return; |
| + if ((active_user_ == NULL) || (user != active_user_) || |
| + !active_user_->is_profile_created()) |
| + return; |
| + |
| + if (profile != ProfileManager::GetDefaultProfile()) |
| + return; |
| + const PrefService* prefs = profile->GetPrefs(); |
| + if (prefs == NULL) |
| + return; |
| + |
| + std::string pref_locale = prefs->GetString(prefs::kApplicationLocale); |
| + if (pref_locale.empty()) |
| + pref_locale = prefs->GetString(prefs::kApplicationLocaleBackup); |
| + |
| + if (pref_locale.empty() && user->has_account()) { |
| + if (user->GetAccountLocale() == NULL) |
| + return; // wait until Account profile is loaded. |
| + pref_locale = *(user->GetAccountLocale()); |
| + } |
| + if (pref_locale.empty()) |
| + pref_locale = g_browser_process->GetApplicationLocale(); |
| + DCHECK(!pref_locale.empty()); |
| + profile->ChangeAppLocale(pref_locale, Profile::APP_LOCALE_CHANGED_VIA_LOGIN); |
| + // Here we don't enable keyboard layouts. Input methods are set up when |
| + // the user first logs in. Then the user may customize the input methods. |
| + // Hence changing input methods here, just because the user's UI language |
| + // is different from the login screen UI language, is not desirable. Note |
| + // that input method preferences are synced, so users can use their |
| + // farovite input methods as soon as the preferences are synced. |
| + chromeos::LanguageSwitchMenu::SwitchLanguage(pref_locale); |
| +} |
| + |
| +class UserHashMatcher { |
| + const std::string& username_hash; |
|
Dmitry Polukhin
2013/09/06 20:30:05
Please make private members last.
Alexander Alekseev
2013/09/11 18:53:02
Done.
|
| + |
| + public: |
| + explicit UserHashMatcher(const std::string& h) : username_hash(h) {} |
| + bool operator()(const User* user) const { |
| + return user->username_hash() == username_hash; |
| + } |
| +}; |
| + |
| +// Returns NULL if user is not created |
| +User* UserManagerImpl::GetUserByProfile(Profile* profile) { |
| + if (CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles)) { |
| + const std::string username_hash = |
| + ProfileHelper::GetUserIdHashFromProfile(profile); |
| + const UserList& users = GetUsers(); |
| + const UserList::const_iterator pos = std::find_if( |
| + users.begin(), users.end(), UserHashMatcher(username_hash)); |
| + return (pos != users.end()) ? *pos : NULL; |
| + } |
| + return active_user_; |
| +} |
| + |
| void UserManagerImpl::Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| @@ -758,6 +853,16 @@ void UserManagerImpl::Observe(int type, |
| } |
| } |
| break; |
| + case chrome::NOTIFICATION_PROFILE_CREATED: { |
| + Profile* profile = content::Source<Profile>(source).ptr(); |
| + User* user = GetUserByProfile(profile); |
| + if (user != NULL) { |
| + user->set_profile_is_created(); |
| + if (user == active_user_) |
| + RespectLocalePreference(profile, user); |
| + } |
| + break; |
| + } |
| case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: { |
| std::string changed_setting = |
| *content::Details<const std::string>(details).ptr(); |