summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-04 13:07:38 +0000
committerdilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-04 13:07:38 +0000
commitcd87be13977746aca1f6849432c0c3673f50f92c (patch)
treec1326176d8affc165728201973bbe7a6f0154ca6
parent77641700fad68651e04cf3d56be7cdaa498b283f (diff)
downloadchromium_src-cd87be13977746aca1f6849432c0c3673f50f92c.zip
chromium_src-cd87be13977746aca1f6849432c0c3673f50f92c.tar.gz
chromium_src-cd87be13977746aca1f6849432c0c3673f50f92c.tar.bz2
Respect owner's locale preference.
When device powered up or woke up or when user signs out: switch login screen to owner's locale. Users are still able to switch language via language switch menu on new user pod but those changes are transient till next wakeup/powerup/signout. (1)We add another setting to LocalState: kOwnerLocale in addition to kApplicationLocale. (2)When device is already owned and user switches locale on new user pod -- then we do NOT change kApplicationLocale -- we just reload resources and change locale internally. (3) On startup browser_main.cc initializes locale based on kApplicationLocale (4) When login screen appears we check that kApplicationLocale equals to kOwnerLocale. Under common usage they are equal. However when we initiate Guest session we need to pass current locale there, so we set kApplicationLocale. So after Guest session kApplicationLocale and kOwnerLocale may differ. BUG=chromium-os:11212 TEST=Manual Review URL: http://codereview.chromium.org/6334054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73799 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_main.cc15
-rw-r--r--chrome/browser/chromeos/login/existing_user_controller.cc20
-rw-r--r--chrome/browser/chromeos/login/language_switch_menu.cc13
-rw-r--r--chrome/browser/chromeos/login/login_utils.cc12
-rw-r--r--chrome/browser/profiles/profile_impl.cc12
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/common/pref_names.h1
7 files changed, 62 insertions, 14 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index c6573b6..7a207d42 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -646,11 +646,16 @@ PrefService* InitializeLocalState(const CommandLine& parsed_command_line,
PrefService* local_state = g_browser_process->local_state();
DCHECK(local_state);
+ // TODO(brettw,*): this comment about ResourceBundle was here since
+ // initial commit. This comment seems unrelated, bit-rotten and
+ // a candidate for removal.
// Initialize ResourceBundle which handles files loaded from external
// sources. This has to be done before uninstall code path and before prefs
// are registered.
- local_state->RegisterStringPref(prefs::kApplicationLocale,
- std::string());
+ local_state->RegisterStringPref(prefs::kApplicationLocale, std::string());
+#if defined(OS_CHROMEOS)
+ local_state->RegisterStringPref(prefs::kOwnerLocale, std::string());
+#endif // defined(OS_CHROMEOS)
#if !defined(OS_CHROMEOS)
local_state->RegisterBooleanPref(prefs::kMetricsReportingEnabled,
GoogleUpdateSettings::GetCollectStatsConsent());
@@ -1189,10 +1194,10 @@ int BrowserMain(const MainFunctionParams& parameters) {
#if defined(OS_MACOSX)
g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride());
#else
- // On a POSIX OS other than ChromeOS, the parameter that is passed to the
- // method InitSharedInstance is ignored.
const std::string locale =
local_state->GetString(prefs::kApplicationLocale);
+ // On a POSIX OS other than ChromeOS, the parameter that is passed to the
+ // method InitSharedInstance is ignored.
const std::string loaded_locale =
ResourceBundle::InitSharedInstance(locale);
CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
@@ -1201,7 +1206,7 @@ int BrowserMain(const MainFunctionParams& parameters) {
FilePath resources_pack_path;
PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
ResourceBundle::AddDataPackToSharedInstance(resources_pack_path);
-#endif // !defined(OS_MACOSX)
+#endif // defined(OS_MACOSX)
}
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
diff --git a/chrome/browser/chromeos/login/existing_user_controller.cc b/chrome/browser/chromeos/login/existing_user_controller.cc
index 7bf9b0a..c19371f5 100644
--- a/chrome/browser/chromeos/login/existing_user_controller.cc
+++ b/chrome/browser/chromeos/login/existing_user_controller.cc
@@ -8,6 +8,7 @@
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/boot_times_loader.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/cryptohome_library.h"
@@ -22,12 +23,14 @@
#include "chrome/browser/chromeos/status/status_area_view.h"
#include "chrome/browser/chromeos/user_cros_settings_provider.h"
#include "chrome/browser/google/google_util.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/views/window.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/net/gaia/google_service_auth_error.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
+#include "chrome/common/pref_names.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "views/window/window.h"
@@ -100,6 +103,23 @@ ExistingUserController::ExistingUserController(
}
void ExistingUserController::Init(const UserVector& users) {
+ if (g_browser_process) {
+ PrefService* state = g_browser_process->local_state();
+ if (state) {
+ std::string owner_locale =
+ state->GetString(prefs::kOwnerLocale);
+ // Ensure that we start with owner's locale. Under common usage
+ // kApplicationLocale value equals to kOwnerLocale value.
+ // However in current implementation it may breach during guest session:
+ // we store current locale into kApplicationLocale to setup guest session.
+ if (!owner_locale.empty() &&
+ state->GetString(prefs::kApplicationLocale) != owner_locale) {
+ state->SetString(prefs::kApplicationLocale, owner_locale);
+ state->ScheduleSavePersistentPrefs();
+ LanguageSwitchMenu::SwitchLanguage(owner_locale);
+ }
+ }
+ }
if (!background_window_) {
background_window_ = BackgroundView::CreateWindowContainingView(
background_bounds_,
diff --git a/chrome/browser/chromeos/login/language_switch_menu.cc b/chrome/browser/chromeos/login/language_switch_menu.cc
index a731f9e..7ed8596 100644
--- a/chrome/browser/chromeos/login/language_switch_menu.cc
+++ b/chrome/browser/chromeos/login/language_switch_menu.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/chromeos/cros/keyboard_library.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chrome/browser/chromeos/language_preferences.h"
+#include "chrome/browser/chromeos/login/ownership_service.h"
#include "chrome/browser/chromeos/login/screen_observer.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/pref_names.h"
@@ -83,15 +84,12 @@ void LanguageSwitchMenu::SwitchLanguage(const std::string& locale) {
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.
// TODO(markusheintz): Change the if condition to prefs->IsUserModifiable()
// once Mattias landed his pending patch.
- if (!prefs->IsManagedPreference(prefs::kApplicationLocale)) {
- prefs->SetString(prefs::kApplicationLocale, locale);
- prefs->SavePersistentPrefs();
+ if (!g_browser_process->local_state()->
+ IsManagedPreference(prefs::kApplicationLocale)) {
std::string loaded_locale;
{
// Reloading resource bundle causes us to do blocking IO on UI thread.
@@ -154,6 +152,11 @@ bool LanguageSwitchMenu::GetAcceleratorForCommandId(
void LanguageSwitchMenu::ExecuteCommand(int command_id) {
const std::string locale = language_list_->GetLocaleFromIndex(command_id);
SwitchLanguage(locale);
+ if (!chromeos::OwnershipService::GetSharedInstance()->IsAlreadyOwned()) {
+ g_browser_process->local_state()->SetString(
+ prefs::kApplicationLocale, locale);
+ g_browser_process->local_state()->ScheduleSavePersistentPrefs();
+ }
InitLanguageMenu();
// Update all view hierarchies that the locale has changed.
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index e9032fb..9465a43 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -427,6 +427,18 @@ void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) {
switches::kRegisterPepperPlugins).c_str());
}
+ PrefService* local_state = g_browser_process->local_state();
+ std::string cur_locale = g_browser_process->GetApplicationLocale();
+ // Guest session is starting in a new process so we need to communicate
+ // current locale to it. Current locale may differ from value of
+ // kApplicationLocale because switching language on new user pod does not
+ // change kApplicationLocale after ownership has been taken.
+ // We will restore kApplicationLocale back to kOwnerValue on next startup.
+ if (local_state->GetString(prefs::kApplicationLocale) != cur_locale) {
+ local_state->SetString(prefs::kApplicationLocale, cur_locale);
+ local_state->SavePersistentPrefs();
+ }
+
CrosLibrary::Get()->GetLoginLibrary()->RestartJob(getpid(), cmd_line_str);
}
}
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 30f8fba..6f6abfb 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -120,6 +120,7 @@
#endif
#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/login/ownership_service.h"
#include "chrome/browser/chromeos/preferences.h"
#endif
@@ -1402,10 +1403,6 @@ void ProfileImpl::ChangeAppLocale(
// 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.
- // In case of APP_LOCALE_CHANGED_VIA_LOGIN we won't touch local state
- // because login screen code is active and takes care of it.
- g_browser_process->local_state()->SetString(
- prefs::kApplicationLocale, new_locale);
break;
}
case APP_LOCALE_CHANGED_VIA_LOGIN: {
@@ -1448,6 +1445,13 @@ void ProfileImpl::ChangeAppLocale(
}
if (do_update_pref)
GetPrefs()->SetString(prefs::kApplicationLocale, new_locale);
+ if (!chromeos::OwnershipService::GetSharedInstance()->IsAlreadyOwned() ||
+ chromeos::OwnershipService::GetSharedInstance()->CurrentUserIsOwner()) {
+ g_browser_process->local_state()->SetString(
+ prefs::kOwnerLocale, new_locale);
+ g_browser_process->local_state()->SetString(
+ prefs::kApplicationLocale, new_locale);
+ }
GetPrefs()->ScheduleSavePersistentPrefs();
g_browser_process->local_state()->ScheduleSavePersistentPrefs();
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index cfcf98a..30f0730 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -46,6 +46,9 @@ const char kURLsToRestoreOnStartup[] = "session.urls_to_restore_on_startup";
// while user's profile determines his personal locale preference.
const char kApplicationLocale[] = "intl.app_locale";
#if defined(OS_CHROMEOS)
+// Locale preference of device' owner. ChromeOS device appears in this locale
+// after startup/wakeup/signout.
+const char kOwnerLocale[] = "intl.owner_locale";
// Locale accepted by user. Non-syncable.
// Used to determine whether we need to show Locale Change notification.
const char kApplicationLocaleAccepted[] = "intl.app_locale_accepted";
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 8f2094b..bea6914 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -28,6 +28,7 @@ extern const char kApplicationLocale[];
#if defined(OS_CHROMEOS)
extern const char kApplicationLocaleBackup[];
extern const char kApplicationLocaleAccepted[];
+extern const char kOwnerLocale[];
#endif
extern const char kDefaultCharset[];