Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 5 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/prefs/pref_member.h" | 15 #include "base/prefs/pref_member.h" |
| 16 #include "base/prefs/pref_registry_simple.h" | 16 #include "base/prefs/pref_registry_simple.h" |
| 17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 18 #include "base/run_loop.h" | |
| 18 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 20 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
| 21 #include "base/task_runner_util.h" | 22 #include "base/task_runner_util.h" |
| 22 #include "base/threading/worker_pool.h" | 23 #include "base/threading/worker_pool.h" |
| 23 #include "chrome/browser/about_flags.h" | 24 #include "chrome/browser/about_flags.h" |
| 24 #include "chrome/browser/app_mode/app_mode_utils.h" | 25 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 25 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 27 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
| 27 #include "chrome/browser/browser_shutdown.h" | 28 #include "chrome/browser/browser_shutdown.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 | 274 |
| 274 void LogCustomSwitches(const std::set<std::string>& switches) { | 275 void LogCustomSwitches(const std::set<std::string>& switches) { |
| 275 if (!VLOG_IS_ON(1)) | 276 if (!VLOG_IS_ON(1)) |
| 276 return; | 277 return; |
| 277 for (std::set<std::string>::const_iterator it = switches.begin(); | 278 for (std::set<std::string>::const_iterator it = switches.begin(); |
| 278 it != switches.end(); ++it) { | 279 it != switches.end(); ++it) { |
| 279 VLOG(1) << "Switch leading to restart: '" << *it << "'"; | 280 VLOG(1) << "Switch leading to restart: '" << *it << "'"; |
| 280 } | 281 } |
| 281 } | 282 } |
| 282 | 283 |
| 284 // Wait until language is switched. | |
| 285 class LocalePreferenceRespectedWaiter | |
| 286 : public base::SupportsWeakPtr<LocalePreferenceRespectedWaiter> { | |
| 287 public: | |
| 288 LocalePreferenceRespectedWaiter() : done_(false) {} | |
| 289 | |
| 290 locale_util::SwitchLanguageCallback Callback( | |
| 291 const locale_util::SwitchLanguageCallback& callback) { | |
| 292 return base::Bind(&LocalePreferenceRespectedWaiter::OnLanguageSwitched, | |
| 293 AsWeakPtr(), callback); | |
| 294 } | |
| 295 | |
| 296 void RunUntilLocaleSet(void) { | |
| 297 if (done_) | |
| 298 return; | |
| 299 | |
| 300 base::MessageLoop::ScopedNestableTaskAllower allow( | |
| 301 base::MessageLoop::current()); | |
| 302 | |
| 303 run_loop_.Run(); | |
| 304 } | |
| 305 | |
| 306 private: | |
| 307 void OnLanguageSwitched(const locale_util::SwitchLanguageCallback& callback, | |
| 308 const locale_util::LanguageSwitchResult& result) { | |
| 309 done_ = true; | |
| 310 run_loop_.Quit(); | |
| 311 | |
| 312 callback.Run(result); | |
| 313 } | |
| 314 | |
| 315 base::RunLoop run_loop_; | |
| 316 bool done_; | |
| 317 | |
| 318 DISALLOW_COPY_AND_ASSIGN(LocalePreferenceRespectedWaiter); | |
| 319 }; | |
| 320 | |
| 283 } // namespace | 321 } // namespace |
| 284 | 322 |
| 285 UserSessionManagerDelegate::~UserSessionManagerDelegate() { | 323 UserSessionManagerDelegate::~UserSessionManagerDelegate() { |
| 286 } | 324 } |
| 287 | 325 |
| 288 void UserSessionStateObserver::PendingUserSessionsRestoreFinished() { | 326 void UserSessionStateObserver::PendingUserSessionsRestoreFinished() { |
| 289 } | 327 } |
| 290 | 328 |
| 291 UserSessionStateObserver::~UserSessionStateObserver() { | 329 UserSessionStateObserver::~UserSessionStateObserver() { |
| 292 } | 330 } |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 // are set up when the user first logs in. Then the user may customize the | 640 // are set up when the user first logs in. Then the user may customize the |
| 603 // input methods. Hence changing input methods here, just because the user's | 641 // input methods. Hence changing input methods here, just because the user's |
| 604 // UI language is different from the login screen UI language, is not | 642 // UI language is different from the login screen UI language, is not |
| 605 // desirable. Note that input method preferences are synced, so users can use | 643 // desirable. Note that input method preferences are synced, so users can use |
| 606 // their farovite input methods as soon as the preferences are synced. | 644 // their farovite input methods as soon as the preferences are synced. |
| 607 // | 645 // |
| 608 // For Guest mode, user locale preferences will never get initialized. | 646 // For Guest mode, user locale preferences will never get initialized. |
| 609 // So input methods should be enabled somewhere. | 647 // So input methods should be enabled somewhere. |
| 610 const bool enable_layouts = | 648 const bool enable_layouts = |
| 611 user_manager::UserManager::Get()->IsLoggedInAsGuest(); | 649 user_manager::UserManager::Get()->IsLoggedInAsGuest(); |
| 612 locale_util::SwitchLanguage( | 650 locale_util::SwitchLanguage(pref_locale, enable_layouts, |
| 613 pref_locale, enable_layouts, false /* login_layouts_only */, callback); | 651 false /* login_layouts_only */, callback, |
| 652 profile); | |
| 614 | 653 |
| 615 return true; | 654 return true; |
| 616 } | 655 } |
| 617 | 656 |
| 618 bool UserSessionManager::RestartToApplyPerSessionFlagsIfNeed( | 657 bool UserSessionManager::RestartToApplyPerSessionFlagsIfNeed( |
| 619 Profile* profile, | 658 Profile* profile, |
| 620 bool early_restart) { | 659 bool early_restart) { |
| 621 if (ProfileHelper::IsSigninProfile(profile)) | 660 if (ProfileHelper::IsSigninProfile(profile)) |
| 622 return false; | 661 return false; |
| 623 | 662 |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1549 void UserSessionManager::DoBrowserLaunchInternal(Profile* profile, | 1588 void UserSessionManager::DoBrowserLaunchInternal(Profile* profile, |
| 1550 LoginDisplayHost* login_host, | 1589 LoginDisplayHost* login_host, |
| 1551 bool locale_pref_checked) { | 1590 bool locale_pref_checked) { |
| 1552 if (browser_shutdown::IsTryingToQuit()) | 1591 if (browser_shutdown::IsTryingToQuit()) |
| 1553 return; | 1592 return; |
| 1554 | 1593 |
| 1555 if (!locale_pref_checked) { | 1594 if (!locale_pref_checked) { |
| 1556 RespectLocalePreferenceWrapper( | 1595 RespectLocalePreferenceWrapper( |
| 1557 profile, | 1596 profile, |
| 1558 base::Bind(&UserSessionManager::DoBrowserLaunchInternal, AsWeakPtr(), | 1597 base::Bind(&UserSessionManager::DoBrowserLaunchInternal, AsWeakPtr(), |
| 1559 profile, login_host, true /* locale_pref_checked */)); | 1598 profile, login_host, true /* locale_pref_checked */), |
| 1599 false /* synchronous */); | |
| 1560 return; | 1600 return; |
| 1561 } | 1601 } |
| 1562 | 1602 |
| 1563 if (!ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { | 1603 if (!ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { |
| 1564 ChromeUserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); | 1604 ChromeUserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); |
| 1565 return; | 1605 return; |
| 1566 } | 1606 } |
| 1567 | 1607 |
| 1568 if (RestartToApplyPerSessionFlagsIfNeed(profile, false)) | 1608 if (RestartToApplyPerSessionFlagsIfNeed(profile, false)) |
| 1569 return; | 1609 return; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1600 // browser before it is dereferenced by the login host. | 1640 // browser before it is dereferenced by the login host. |
| 1601 if (login_host) | 1641 if (login_host) |
| 1602 login_host->Finalize(); | 1642 login_host->Finalize(); |
| 1603 user_manager::UserManager::Get()->SessionStarted(); | 1643 user_manager::UserManager::Get()->SessionStarted(); |
| 1604 chromeos::BootTimesRecorder::Get()->LoginDone( | 1644 chromeos::BootTimesRecorder::Get()->LoginDone( |
| 1605 user_manager::UserManager::Get()->IsCurrentUserNew()); | 1645 user_manager::UserManager::Get()->IsCurrentUserNew()); |
| 1606 } | 1646 } |
| 1607 | 1647 |
| 1608 void UserSessionManager::RespectLocalePreferenceWrapper( | 1648 void UserSessionManager::RespectLocalePreferenceWrapper( |
| 1609 Profile* profile, | 1649 Profile* profile, |
| 1610 const base::Closure& callback) { | 1650 const base::Closure& callback, |
| 1651 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.
| |
| 1611 if (browser_shutdown::IsTryingToQuit()) | 1652 if (browser_shutdown::IsTryingToQuit()) |
| 1612 return; | 1653 return; |
| 1613 | 1654 |
| 1614 const user_manager::User* const user = | 1655 const user_manager::User* const user = |
| 1615 ProfileHelper::Get()->GetUserByProfile(profile); | 1656 ProfileHelper::Get()->GetUserByProfile(profile); |
| 1657 | |
| 1658 LocalePreferenceRespectedWaiter waiter; | |
| 1659 | |
| 1616 locale_util::SwitchLanguageCallback locale_switched_callback(base::Bind( | 1660 locale_util::SwitchLanguageCallback locale_switched_callback(base::Bind( |
| 1617 &UserSessionManager::RunCallbackOnLocaleLoaded, callback, | 1661 &UserSessionManager::RunCallbackOnLocaleLoaded, callback, |
| 1618 base::Owned(new InputEventsBlocker))); // Block UI events until | 1662 base::Owned(new InputEventsBlocker))); // Block UI events until |
| 1619 // the ResourceBundle is | 1663 // the ResourceBundle is |
| 1620 // reloaded. | 1664 // reloaded. |
| 1621 if (!RespectLocalePreference(profile, user, locale_switched_callback)) | 1665 if (synchronous) |
| 1666 locale_switched_callback = waiter.Callback(locale_switched_callback); | |
| 1667 | |
| 1668 if (!RespectLocalePreference(profile, user, locale_switched_callback)) { | |
| 1622 callback.Run(); | 1669 callback.Run(); |
| 1670 } else if (synchronous) { | |
| 1671 waiter.RunUntilLocaleSet(); | |
| 1672 } | |
| 1623 } | 1673 } |
| 1624 | 1674 |
| 1625 // static | 1675 // static |
| 1626 void UserSessionManager::RunCallbackOnLocaleLoaded( | 1676 void UserSessionManager::RunCallbackOnLocaleLoaded( |
| 1627 const base::Closure& callback, | 1677 const base::Closure& callback, |
| 1628 InputEventsBlocker* /* input_events_blocker */, | 1678 InputEventsBlocker* /* input_events_blocker */, |
| 1629 const locale_util::LanguageSwitchResult& /* result */) { | 1679 const locale_util::LanguageSwitchResult& /* result */) { |
| 1630 callback.Run(); | 1680 callback.Run(); |
| 1631 } | 1681 } |
| 1632 | 1682 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1657 if (is_enterprise_managed) | 1707 if (is_enterprise_managed) |
| 1658 display = USER_PODS_DISPLAY_DISABLED_MANAGED; | 1708 display = USER_PODS_DISPLAY_DISABLED_MANAGED; |
| 1659 else | 1709 else |
| 1660 display = USER_PODS_DISPLAY_DISABLED_REGULAR; | 1710 display = USER_PODS_DISPLAY_DISABLED_REGULAR; |
| 1661 } | 1711 } |
| 1662 UMA_HISTOGRAM_ENUMERATION("UserSessionManager.UserPodsDisplay", display, | 1712 UMA_HISTOGRAM_ENUMERATION("UserSessionManager.UserPodsDisplay", display, |
| 1663 NUM_USER_PODS_DISPLAY); | 1713 NUM_USER_PODS_DISPLAY); |
| 1664 } | 1714 } |
| 1665 | 1715 |
| 1666 } // namespace chromeos | 1716 } // namespace chromeos |
| OLD | NEW |