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

Unified 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 build. 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 side-by-side diff with in-line comments
Download patch
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..e306fa0ee92d61a5711f79fb67f503aa93c64bc1 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);
@@ -648,12 +654,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);
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.
+ }
+
+ 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 +751,68 @@ 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 ((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_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) {
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.
+ 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 +849,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();

Powered by Google App Engine
This is Rietveld 408576698