diff options
author | dilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-15 11:49:44 +0000 |
---|---|---|
committer | dilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-15 11:49:44 +0000 |
commit | 464598b46f1a4bfaaec5841ad4b33fc2d747dabd (patch) | |
tree | 1b87c8e1b58a4c0a0967f398dc4403043e4c6339 /chrome | |
parent | 9f4e1e40affa2b0f8f256c52ac1ffc9208f7bd04 (diff) | |
download | chromium_src-464598b46f1a4bfaaec5841ad4b33fc2d747dabd.zip chromium_src-464598b46f1a4bfaaec5841ad4b33fc2d747dabd.tar.gz chromium_src-464598b46f1a4bfaaec5841ad4b33fc2d747dabd.tar.bz2 |
Chrome OS: make language per user.
BUG=http://crosbug.com/3873
TEST=Manual
Review URL: http://codereview.chromium.org/3579011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/dom_ui/language_options_handler.cc | 19 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/language_switch_menu.cc | 5 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_utils.cc | 22 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 8 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 5 |
5 files changed, 52 insertions, 7 deletions
diff --git a/chrome/browser/chromeos/dom_ui/language_options_handler.cc b/chrome/browser/chromeos/dom_ui/language_options_handler.cc index 05570bc..93135a7 100644 --- a/chrome/browser/chromeos/dom_ui/language_options_handler.cc +++ b/chrome/browser/chromeos/dom_ui/language_options_handler.cc @@ -10,6 +10,7 @@ #include <utility> #include "app/l10n_util.h" +#include "base/basictypes.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/app/chrome_command_ids.h" @@ -20,6 +21,7 @@ #include "chrome/browser/chromeos/input_method/input_method_util.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/pref_names.h" #include "chrome/common/spellcheck_common.h" @@ -57,7 +59,8 @@ void LanguageOptionsHandler::GetLocalizedValues( localized_strings->SetString("remove_button", l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_REMOVE_BUTTON)); localized_strings->SetString("sign_out_button", - l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_SIGN_OUT_BUTTON)); + l10n_util::GetStringUTF16( + IDS_OPTIONS_SETTINGS_LANGUAGES_SIGN_OUT_BUTTON)); localized_strings->SetString("add_language_instructions", l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_INSTRUCTIONS)); @@ -287,9 +290,17 @@ void LanguageOptionsHandler::UiLanguageChangeCallback( "LanguageOptions_UiLanguageChange_%s", language_code.c_str()); UserMetrics::RecordComputedAction(action); - PrefService* prefs = g_browser_process->local_state(); - prefs->SetString(prefs::kApplicationLocale, language_code); - prefs->SavePersistentPrefs(); + // We maintain kApplicationLocale property in both a global storage + // and user's profile. Global property determines locale of login screen, + // while user's profile determines his personal locale preference. + PrefService* prefs[] = { + g_browser_process->local_state(), + dom_ui_->GetProfile()->GetPrefs() + }; + for (size_t i = 0; i < arraysize(prefs); ++i) { + prefs[i]->SetString(prefs::kApplicationLocale, language_code); + prefs[i]->SavePersistentPrefs(); + } dom_ui_->CallJavascriptFunction( L"options.LanguageOptions.uiLanguageSaved"); } diff --git a/chrome/browser/chromeos/login/language_switch_menu.cc b/chrome/browser/chromeos/login/language_switch_menu.cc index 3d8bcbc..c18d20d 100644 --- a/chrome/browser/chromeos/login/language_switch_menu.cc +++ b/chrome/browser/chromeos/login/language_switch_menu.cc @@ -78,8 +78,11 @@ void LanguageSwitchMenu::SetFirstLevelMenuWidth(int width) { // static void LanguageSwitchMenu::SwitchLanguage(const std::string& locale) { - // Save new locale. DCHECK(g_browser_process); + if (g_browser_process->GetApplicationLocale() == locale) { + return; + } + // Save new locale. PrefService* prefs = g_browser_process->local_state(); // TODO(markusheintz): If the preference is managed and can not be changed by // the user, changing the language should be disabled in the UI. diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index d501cd0..c8ad2d2 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -26,6 +26,7 @@ #include "chrome/browser/chromeos/input_method/input_method_util.h" #include "chrome/browser/chromeos/login/cookie_fetcher.h" #include "chrome/browser/chromeos/login/google_authenticator.h" +#include "chrome/browser/chromeos/login/language_switch_menu.h" #include "chrome/browser/chromeos/login/ownership_service.h" #include "chrome/browser/chromeos/login/parallel_authenticator.h" #include "chrome/browser/chromeos/login/user_image_downloader.h" @@ -54,9 +55,8 @@ namespace chromeos { namespace { -// Prefix for Auth token received from ClientLogin request. +// Affixes for Auth token received from ClientLogin request. const char kAuthPrefix[] = "Auth="; -// Suffix for Auth token received from ClientLogin request. const char kAuthSuffix[] = "\n"; // Increase logging level for Guest mode to avoid LOG(INFO) messages in logs. @@ -99,6 +99,9 @@ class LoginUtilsImpl : public LoginUtils { virtual void PrewarmAuthentication(); private: + // Check user's profile for kApplicationLocale setting. + void RespectLocalePreference(PrefService* pref); + // Indicates if DoBrowserLaunch will actually launch the browser or not. bool browser_launch_enabled_; @@ -211,6 +214,8 @@ void LoginUtilsImpl::CompleteLogin( } btl->AddLoginTimeMarker("TPMOwned", false); + RespectLocalePreference(profile->GetPrefs()); + static const char kFallbackInputMethodLocale[] = "en-US"; if (first_login) { std::string locale(g_browser_process->GetApplicationLocale()); @@ -258,6 +263,19 @@ void LoginUtilsImpl::CompleteLogin( DoBrowserLaunch(profile); } +void LoginUtilsImpl::RespectLocalePreference(PrefService* pref) { + std::string pref_locale = pref->GetString(prefs::kApplicationLocale); + if (pref_locale.empty()) { + // TODO(dilmah): current code will clobber existing setting in case + // language preference was set via another device + // but still not synced yet. Profile is not synced at this point yet. + pref->SetString(prefs::kApplicationLocale, + g_browser_process->GetApplicationLocale()); + } else { + LanguageSwitchMenu::SwitchLanguage(pref_locale); + } +} + void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) { VLOG(1) << "Completing off the record login"; diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 626e602..0bb8892 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -96,6 +96,14 @@ void Profile::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties); prefs->RegisterBooleanPref(prefs::kDisableExtensions, false); prefs->RegisterStringPref(prefs::kSelectFileLastDirectory, ""); +#if defined(OS_CHROMEOS) + // TODO(dilmah): For OS_CHROMEOS we maintain kApplicationLocale in both + // local state and user's profile. For other platforms we maintain + // kApplicationLocale only in local state. + // In the future we may want to maintain kApplicationLocale + // in user's profile for other platforms as well. + prefs->RegisterStringPref(prefs::kApplicationLocale, ""); +#endif } // static diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 190178d..f051a78 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -20,7 +20,12 @@ extern const char kHomePage[]; extern const char kSessionExitedCleanly[]; extern const char kRestoreOnStartup[]; extern const char kURLsToRestoreOnStartup[]; + +// For OS_CHROMEOS we maintain kApplicationLocale property in both local state +// and user's profile. Global property determines locale of login screen, +// while user's profile determines his personal locale preference. extern const char kApplicationLocale[]; + extern const char kDefaultCharset[]; extern const char kAcceptLanguages[]; extern const char kStaticEncodings[]; |