Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "chrome/browser/app_mode/app_mode_utils.h" | 25 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/chromeos/cros/cert_library.h" | 27 #include "chrome/browser/chromeos/cros/cert_library.h" |
| 28 #include "chrome/browser/chromeos/cros/cros_library.h" | 28 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 29 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" | 29 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" |
| 30 #include "chrome/browser/chromeos/login/login_display.h" | 30 #include "chrome/browser/chromeos/login/login_display.h" |
| 31 #include "chrome/browser/chromeos/login/login_utils.h" | |
| 31 #include "chrome/browser/chromeos/login/remove_user_delegate.h" | 32 #include "chrome/browser/chromeos/login/remove_user_delegate.h" |
| 32 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" | 33 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" |
| 33 #include "chrome/browser/chromeos/login/wizard_controller.h" | 34 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 34 #include "chrome/browser/chromeos/policy/device_local_account.h" | 35 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 35 #include "chrome/browser/chromeos/session_length_limiter.h" | 36 #include "chrome/browser/chromeos/session_length_limiter.h" |
| 36 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 37 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 37 #include "chrome/browser/policy/browser_policy_connector.h" | 38 #include "chrome/browser/policy/browser_policy_connector.h" |
| 38 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 39 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 39 #include "chrome/browser/profiles/profile_manager.h" | 40 #include "chrome/browser/profiles/profile_manager.h" |
| 40 #include "chrome/browser/sync/profile_sync_service.h" | 41 #include "chrome/browser/sync/profile_sync_service.h" |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 840 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 840 session_state_observer_list_.RemoveObserver(obs); | 841 session_state_observer_list_.RemoveObserver(obs); |
| 841 } | 842 } |
| 842 | 843 |
| 843 void UserManagerImpl::NotifyLocalStateChanged() { | 844 void UserManagerImpl::NotifyLocalStateChanged() { |
| 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 845 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, | 846 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, |
| 846 LocalStateChanged(this)); | 847 LocalStateChanged(this)); |
| 847 } | 848 } |
| 848 | 849 |
| 850 void UserManagerImpl::OnProfilePrepared(Profile* profile) { | |
| 851 LoginUtils::Get()->DoBrowserLaunch(profile, | |
| 852 NULL); // host_, not needed here | |
| 853 | |
| 854 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestName)) { | |
| 855 // Did not log in (we crashed or are debugging), need to restore Sync. | |
| 856 // TODO(nkostylev): Make sure that OAuth state is restored correctly for all | |
| 857 // users once it is fully multi-profile aware. http://crbug.com/238987 | |
| 858 // For now if we have other user pending sessions they'll override OAuth | |
| 859 // session restore for previous users. | |
| 860 LoginUtils::Get()->RestoreAuthenticationSession(profile); | |
| 861 } | |
| 862 | |
| 863 // Restore other user sessions if any. | |
| 864 RestorePendingUserSessions(); | |
| 865 } | |
| 866 | |
| 849 void UserManagerImpl::EnsureUsersLoaded() { | 867 void UserManagerImpl::EnsureUsersLoaded() { |
| 850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 868 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 851 if (!g_browser_process || !g_browser_process->local_state()) | 869 if (!g_browser_process || !g_browser_process->local_state()) |
| 852 return; | 870 return; |
| 853 | 871 |
| 854 if (users_loaded_) | 872 if (users_loaded_) |
| 855 return; | 873 return; |
| 856 users_loaded_ = true; | 874 users_loaded_ = true; |
| 857 | 875 |
| 858 // Clean up user list first. | 876 // Clean up user list first. |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1538 lru_logged_in_users_.end(), | 1556 lru_logged_in_users_.end(), |
| 1539 user); | 1557 user); |
| 1540 if (it != lru_logged_in_users_.end()) | 1558 if (it != lru_logged_in_users_.end()) |
| 1541 lru_logged_in_users_.erase(it); | 1559 lru_logged_in_users_.erase(it); |
| 1542 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); | 1560 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); |
| 1543 } | 1561 } |
| 1544 | 1562 |
| 1545 void UserManagerImpl::OnRestoreActiveSessions( | 1563 void UserManagerImpl::OnRestoreActiveSessions( |
| 1546 const SessionManagerClient::ActiveSessionsMap& sessions, | 1564 const SessionManagerClient::ActiveSessionsMap& sessions, |
| 1547 bool success) { | 1565 bool success) { |
| 1548 // TODO(nkostylev): Restore all user sessions (in the background). | 1566 if (!success) { |
| 1549 // This requires first refactoring this flow out of LoginUtils. | 1567 LOG(ERROR) << "Could not get list of active user sessions after crash."; |
|
Dmitry Polukhin
2013/05/27 13:51:04
Should we continue working or force sign out is mo
Nikita (slow)
2013/05/27 14:22:06
Done.
| |
| 1550 // 1. UserManager::UserLoggedIn() | 1568 return; |
| 1551 // 2. InitSessionRestoreStrategy() (OAuth) | 1569 } |
| 1552 // 2. ProfileManager::CreateDefaultProfileAsync() | 1570 |
| 1553 // 3. InitProfilePreferences | 1571 // One profile has been already loaded on browser start. |
| 1554 // 4. chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED | 1572 DCHECK(GetLoggedInUsers().size() == 1); |
| 1573 DCHECK(GetActiveUser()); | |
| 1574 std::string active_user_id = GetActiveUser()->email(); | |
| 1575 | |
| 1576 SessionManagerClient::ActiveSessionsMap::const_iterator it; | |
| 1577 for (it = sessions.begin(); it != sessions.end(); ++it) { | |
| 1578 if (active_user_id == it->first) | |
| 1579 continue; | |
| 1580 pending_user_sessions_[it->first] = it->second; | |
| 1581 } | |
| 1582 RestorePendingUserSessions(); | |
| 1583 } | |
| 1584 | |
| 1585 void UserManagerImpl::RestorePendingUserSessions() { | |
| 1586 if (pending_user_sessions_.empty()) | |
| 1587 return; | |
| 1588 | |
| 1589 // Get next user to restore sessions and delete it from list. | |
| 1590 SessionManagerClient::ActiveSessionsMap::const_iterator it = | |
| 1591 pending_user_sessions_.begin(); | |
| 1592 std::string user_id = it->first; | |
| 1593 std::string user_id_hash = it->second; | |
| 1594 DCHECK(!user_id.empty()); | |
| 1595 DCHECK(!user_id_hash.empty()); | |
| 1596 pending_user_sessions_.erase(user_id); | |
| 1597 | |
| 1598 // Check that this user is not logged in yet | |
| 1599 // i.e. session was not restored twice. | |
| 1600 UserList logged_in_users = GetLoggedInUsers(); | |
| 1601 bool user_already_logged_in = false; | |
| 1602 for (UserList::const_iterator it = logged_in_users.begin(); | |
| 1603 it != logged_in_users.end(); ++it) { | |
| 1604 const User* user = (*it); | |
| 1605 if (user->email() == user_id) { | |
| 1606 user_already_logged_in = true; | |
| 1607 break; | |
| 1608 } | |
| 1609 } | |
| 1610 DCHECK(user_already_logged_in); | |
| 1611 | |
| 1612 if (!user_already_logged_in) { | |
| 1613 // Will call OnProfilePrepared() once profile has been loaded. | |
| 1614 LoginUtils::Get()->PrepareProfile(UserContext(user_id, | |
| 1615 std::string(), // password | |
| 1616 std::string(), // auth_code | |
| 1617 user_id_hash), | |
| 1618 std::string(), // display_email | |
| 1619 false, // using_oauth | |
| 1620 false, // has_cookies | |
| 1621 this); | |
| 1622 } else { | |
| 1623 RestorePendingUserSessions(); | |
| 1624 } | |
| 1555 } | 1625 } |
| 1556 | 1626 |
| 1557 } // namespace chromeos | 1627 } // namespace chromeos |
| OLD | NEW |