| 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..123c58ec5a537cfe2486d288325b029b76f05464 100644
|
| --- a/chrome/browser/chromeos/login/user_manager_impl.cc
|
| +++ b/chrome/browser/chromeos/login/user_manager_impl.cc
|
| @@ -27,17 +27,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 +234,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);
|
| @@ -294,6 +300,11 @@ const UserList& UserManagerImpl::GetLoggedInUsers() const {
|
| return logged_in_users_;
|
| }
|
|
|
| +const User* UserManagerImpl::GetPrimaryUser() const {
|
| + return (logged_in_users_.size() == 0 ? active_user_
|
| + : logged_in_users_.front());
|
| +}
|
| +
|
| const UserList& UserManagerImpl::GetLRULoggedInUsers() {
|
| // If there is no user logged in, we return the active user as the only one.
|
| if (lru_logged_in_users_.empty() && active_user_) {
|
| @@ -648,12 +659,34 @@ 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(GetProfileByUser(user), 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 +755,74 @@ std::string UserManagerImpl::GetUserDisplayEmail(
|
| return user ? user->display_email() : username;
|
| }
|
|
|
| +// TODO(alemate): http://crbug.com/288941 : Respect preferred language list in
|
| +// the Google user profile.
|
| +void UserManagerImpl::RespectLocalePreference(Profile* profile,
|
| + const User* user) const {
|
| + if (g_browser_process == NULL)
|
| + return;
|
| + if ((user == NULL) || (user != GetPrimaryUser()) ||
|
| + (!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_gaia_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 {
|
| + public:
|
| + explicit UserHashMatcher(const std::string& h) : username_hash(h) {}
|
| + bool operator()(const User* user) const {
|
| + return user->username_hash() == username_hash;
|
| + }
|
| +
|
| + private:
|
| + const std::string& username_hash;
|
| +};
|
| +
|
| +// Returns NULL if user is not created
|
| +User* UserManagerImpl::GetUserByProfile(Profile* profile) const {
|
| + 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_;
|
| +}
|
| +
|
| +Profile* UserManagerImpl::GetProfileByUser(const User* user) const {
|
| + if (CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles))
|
| + return ProfileHelper::GetProfileByUserIdHash(user->username_hash());
|
| + return g_browser_process->profile_manager()->GetDefaultProfile();
|
| +}
|
| +
|
| void UserManagerImpl::Observe(int type,
|
| const content::NotificationSource& source,
|
| const content::NotificationDetails& details) {
|
| @@ -758,6 +859,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();
|
|
|