| Index: chrome/browser/chromeos/login/session/user_session_manager.cc
|
| diff --git a/chrome/browser/chromeos/login/session/user_session_manager.cc b/chrome/browser/chromeos/login/session/user_session_manager.cc
|
| index 871233e03287e1aa36b5093627814797f1ce5484..9b97e9f7b7e4bb8d0b48f94fce19c974e687aae0 100644
|
| --- a/chrome/browser/chromeos/login/session/user_session_manager.cc
|
| +++ b/chrome/browser/chromeos/login/session/user_session_manager.cc
|
| @@ -15,6 +15,7 @@
|
| #include "base/prefs/pref_member.h"
|
| #include "base/prefs/pref_registry_simple.h"
|
| #include "base/prefs/pref_service.h"
|
| +#include "base/run_loop.h"
|
| #include "base/strings/string16.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/sys_info.h"
|
| @@ -280,6 +281,43 @@ void LogCustomSwitches(const std::set<std::string>& switches) {
|
| }
|
| }
|
|
|
| +// Wait until language is switched.
|
| +class LocalePreferenceRespectedWaiter
|
| + : public base::SupportsWeakPtr<LocalePreferenceRespectedWaiter> {
|
| + public:
|
| + LocalePreferenceRespectedWaiter() : done_(false) {}
|
| +
|
| + locale_util::SwitchLanguageCallback Callback(
|
| + const locale_util::SwitchLanguageCallback& callback) {
|
| + return base::Bind(&LocalePreferenceRespectedWaiter::OnLanguageSwitched,
|
| + AsWeakPtr(), callback);
|
| + }
|
| +
|
| + void RunUntilLocaleSet(void) {
|
| + if (done_)
|
| + return;
|
| +
|
| + base::MessageLoop::ScopedNestableTaskAllower allow(
|
| + base::MessageLoop::current());
|
| +
|
| + run_loop_.Run();
|
| + }
|
| +
|
| + private:
|
| + void OnLanguageSwitched(const locale_util::SwitchLanguageCallback& callback,
|
| + const locale_util::LanguageSwitchResult& result) {
|
| + done_ = true;
|
| + run_loop_.Quit();
|
| +
|
| + callback.Run(result);
|
| + }
|
| +
|
| + base::RunLoop run_loop_;
|
| + bool done_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(LocalePreferenceRespectedWaiter);
|
| +};
|
| +
|
| } // namespace
|
|
|
| UserSessionManagerDelegate::~UserSessionManagerDelegate() {
|
| @@ -1556,7 +1594,8 @@ void UserSessionManager::DoBrowserLaunchInternal(Profile* profile,
|
| RespectLocalePreferenceWrapper(
|
| profile,
|
| base::Bind(&UserSessionManager::DoBrowserLaunchInternal, AsWeakPtr(),
|
| - profile, login_host, true /* locale_pref_checked */));
|
| + profile, login_host, true /* locale_pref_checked */),
|
| + false /* synchronous */);
|
| return;
|
| }
|
|
|
| @@ -1607,19 +1646,29 @@ void UserSessionManager::DoBrowserLaunchInternal(Profile* profile,
|
|
|
| void UserSessionManager::RespectLocalePreferenceWrapper(
|
| Profile* profile,
|
| - const base::Closure& callback) {
|
| + const base::Closure& callback,
|
| + bool synchronous) {
|
| if (browser_shutdown::IsTryingToQuit())
|
| return;
|
|
|
| const user_manager::User* const user =
|
| ProfileHelper::Get()->GetUserByProfile(profile);
|
| +
|
| + LocalePreferenceRespectedWaiter waiter;
|
| +
|
| locale_util::SwitchLanguageCallback locale_switched_callback(base::Bind(
|
| &UserSessionManager::RunCallbackOnLocaleLoaded, callback,
|
| base::Owned(new InputEventsBlocker))); // Block UI events until
|
| // the ResourceBundle is
|
| // reloaded.
|
| - if (!RespectLocalePreference(profile, user, locale_switched_callback))
|
| + if (synchronous)
|
| + locale_switched_callback = waiter.Callback(locale_switched_callback);
|
| +
|
| + if (!RespectLocalePreference(profile, user, locale_switched_callback)) {
|
| callback.Run();
|
| + } else if (synchronous) {
|
| + waiter.RunUntilLocaleSet();
|
| + }
|
| }
|
|
|
| // static
|
|
|