| 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 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 void UserSessionManager::DoBrowserLaunchInternal(Profile* profile, | 1587 void UserSessionManager::DoBrowserLaunchInternal(Profile* profile, |
| 1550 LoginDisplayHost* login_host, | 1588 LoginDisplayHost* login_host, |
| 1551 bool locale_pref_checked) { | 1589 bool locale_pref_checked) { |
| 1552 if (browser_shutdown::IsTryingToQuit()) | 1590 if (browser_shutdown::IsTryingToQuit()) |
| 1553 return; | 1591 return; |
| 1554 | 1592 |
| 1555 if (!locale_pref_checked) { | 1593 if (!locale_pref_checked) { |
| 1556 RespectLocalePreferenceWrapper( | 1594 RespectLocalePreferenceWrapper( |
| 1557 profile, | 1595 profile, |
| 1558 base::Bind(&UserSessionManager::DoBrowserLaunchInternal, AsWeakPtr(), | 1596 base::Bind(&UserSessionManager::DoBrowserLaunchInternal, AsWeakPtr(), |
| 1559 profile, login_host, true /* locale_pref_checked */)); | 1597 profile, login_host, true /* locale_pref_checked */), |
| 1598 false /* synchronous */); |
| 1560 return; | 1599 return; |
| 1561 } | 1600 } |
| 1562 | 1601 |
| 1563 if (!ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { | 1602 if (!ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { |
| 1564 ChromeUserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); | 1603 ChromeUserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); |
| 1565 return; | 1604 return; |
| 1566 } | 1605 } |
| 1567 | 1606 |
| 1568 if (RestartToApplyPerSessionFlagsIfNeed(profile, false)) | 1607 if (RestartToApplyPerSessionFlagsIfNeed(profile, false)) |
| 1569 return; | 1608 return; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1600 // browser before it is dereferenced by the login host. | 1639 // browser before it is dereferenced by the login host. |
| 1601 if (login_host) | 1640 if (login_host) |
| 1602 login_host->Finalize(); | 1641 login_host->Finalize(); |
| 1603 user_manager::UserManager::Get()->SessionStarted(); | 1642 user_manager::UserManager::Get()->SessionStarted(); |
| 1604 chromeos::BootTimesRecorder::Get()->LoginDone( | 1643 chromeos::BootTimesRecorder::Get()->LoginDone( |
| 1605 user_manager::UserManager::Get()->IsCurrentUserNew()); | 1644 user_manager::UserManager::Get()->IsCurrentUserNew()); |
| 1606 } | 1645 } |
| 1607 | 1646 |
| 1608 void UserSessionManager::RespectLocalePreferenceWrapper( | 1647 void UserSessionManager::RespectLocalePreferenceWrapper( |
| 1609 Profile* profile, | 1648 Profile* profile, |
| 1610 const base::Closure& callback) { | 1649 const base::Closure& callback, |
| 1650 bool synchronous) { |
| 1611 if (browser_shutdown::IsTryingToQuit()) | 1651 if (browser_shutdown::IsTryingToQuit()) |
| 1612 return; | 1652 return; |
| 1613 | 1653 |
| 1614 const user_manager::User* const user = | 1654 const user_manager::User* const user = |
| 1615 ProfileHelper::Get()->GetUserByProfile(profile); | 1655 ProfileHelper::Get()->GetUserByProfile(profile); |
| 1656 |
| 1657 LocalePreferenceRespectedWaiter waiter; |
| 1658 |
| 1616 locale_util::SwitchLanguageCallback locale_switched_callback(base::Bind( | 1659 locale_util::SwitchLanguageCallback locale_switched_callback(base::Bind( |
| 1617 &UserSessionManager::RunCallbackOnLocaleLoaded, callback, | 1660 &UserSessionManager::RunCallbackOnLocaleLoaded, callback, |
| 1618 base::Owned(new InputEventsBlocker))); // Block UI events until | 1661 base::Owned(new InputEventsBlocker))); // Block UI events until |
| 1619 // the ResourceBundle is | 1662 // the ResourceBundle is |
| 1620 // reloaded. | 1663 // reloaded. |
| 1621 if (!RespectLocalePreference(profile, user, locale_switched_callback)) | 1664 if (synchronous) |
| 1665 locale_switched_callback = waiter.Callback(locale_switched_callback); |
| 1666 |
| 1667 if (!RespectLocalePreference(profile, user, locale_switched_callback)) { |
| 1622 callback.Run(); | 1668 callback.Run(); |
| 1669 } else if (synchronous) { |
| 1670 waiter.RunUntilLocaleSet(); |
| 1671 } |
| 1623 } | 1672 } |
| 1624 | 1673 |
| 1625 // static | 1674 // static |
| 1626 void UserSessionManager::RunCallbackOnLocaleLoaded( | 1675 void UserSessionManager::RunCallbackOnLocaleLoaded( |
| 1627 const base::Closure& callback, | 1676 const base::Closure& callback, |
| 1628 InputEventsBlocker* /* input_events_blocker */, | 1677 InputEventsBlocker* /* input_events_blocker */, |
| 1629 const locale_util::LanguageSwitchResult& /* result */) { | 1678 const locale_util::LanguageSwitchResult& /* result */) { |
| 1630 callback.Run(); | 1679 callback.Run(); |
| 1631 } | 1680 } |
| 1632 | 1681 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1657 if (is_enterprise_managed) | 1706 if (is_enterprise_managed) |
| 1658 display = USER_PODS_DISPLAY_DISABLED_MANAGED; | 1707 display = USER_PODS_DISPLAY_DISABLED_MANAGED; |
| 1659 else | 1708 else |
| 1660 display = USER_PODS_DISPLAY_DISABLED_REGULAR; | 1709 display = USER_PODS_DISPLAY_DISABLED_REGULAR; |
| 1661 } | 1710 } |
| 1662 UMA_HISTOGRAM_ENUMERATION("UserSessionManager.UserPodsDisplay", display, | 1711 UMA_HISTOGRAM_ENUMERATION("UserSessionManager.UserPodsDisplay", display, |
| 1663 NUM_USER_PODS_DISPLAY); | 1712 NUM_USER_PODS_DISPLAY); |
| 1664 } | 1713 } |
| 1665 | 1714 |
| 1666 } // namespace chromeos | 1715 } // namespace chromeos |
| OLD | NEW |