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

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 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 189d8a95ef4634755c589c52dddcb3d9d673cb89..0c7d69b4cc894ead91bb1c0b6b248c7d66600c4c 100644
--- a/chrome/browser/chromeos/login/user_manager_impl.cc
+++ b/chrome/browser/chromeos/login/user_manager_impl.cc
@@ -28,17 +28,20 @@
#include "chrome/browser/chromeos/login/auth_sync_observer.h"
#include "chrome/browser/chromeos/login/auth_sync_observer_factory.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"
@@ -235,6 +238,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();
local_accounts_subscription_ = cros_settings_->AddSettingsObserver(
kAccountsPrefDeviceLocalAccounts,
@@ -697,12 +703,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
@@ -771,6 +799,94 @@ 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;
+
+ // In case of Multi Profile mode we don't apply profile locale because it is
+ // unsafe.
+ if (GetLoggedInUsers().size() != 1)
+ return;
+ const PrefService* prefs = profile->GetPrefs();
+ if (prefs == NULL)
+ return;
+
+ std::string pref_locale;
+ const std::string pref_app_locale =
+ prefs->GetString(prefs::kApplicationLocale);
+ const std::string pref_bkup_locale =
+ prefs->GetString(prefs::kApplicationLocaleBackup);
+
+ pref_locale = pref_app_locale;
+ if (pref_locale.empty())
+ pref_locale = pref_bkup_locale;
+
+ const std::string* account_locale = NULL;
+ if (pref_locale.empty() && user->has_gaia_account()) {
+ if (user->GetAccountLocale() == NULL)
+ return; // wait until Account profile is loaded.
+ account_locale = user->GetAccountLocale();
+ pref_locale = *account_locale;
+ }
+ const std::string global_app_locale =
+ g_browser_process->GetApplicationLocale();
+ if (pref_locale.empty())
+ pref_locale = global_app_locale;
+ DCHECK(!pref_locale.empty());
+ LOG(WARNING) << "RespectLocalePreference: "
+ << "app_locale='" << pref_app_locale << "', "
+ << "bkup_locale='" << pref_bkup_locale << "', "
+ << (account_locale != NULL
+ ? (std::string("account_locale='") + (*account_locale) +
+ "'. ")
+ : (std::string("account_locale - unused. ")))
+ << " Selected '" << pref_locale << "'";
+ 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 (IsMultipleProfilesAllowed()) {
+ 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 (IsMultipleProfilesAllowed())
+ 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) {
@@ -798,6 +914,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;
+ }
default:
NOTREACHED();
}
« 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