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..cb1a8f348e40a16594376b613f677c0d5cecf2e5 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() { |
@@ -609,8 +647,9 @@ bool UserSessionManager::RespectLocalePreference( |
// So input methods should be enabled somewhere. |
const bool enable_layouts = |
user_manager::UserManager::Get()->IsLoggedInAsGuest(); |
- locale_util::SwitchLanguage( |
- pref_locale, enable_layouts, false /* login_layouts_only */, callback); |
+ locale_util::SwitchLanguage(pref_locale, enable_layouts, |
+ false /* login_layouts_only */, callback, |
+ profile); |
return true; |
} |
@@ -1556,7 +1595,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 +1647,29 @@ void UserSessionManager::DoBrowserLaunchInternal(Profile* profile, |
void UserSessionManager::RespectLocalePreferenceWrapper( |
Profile* profile, |
- const base::Closure& callback) { |
+ const base::Closure& callback, |
+ bool synchronous) { |
robliao
2015/05/06 18:20:32
Can this simply be the create mode instead? That w
Alexander Alekseev
2015/05/07 15:21:57
I've reverted this change.
|
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 |