| 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 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 CheckOwnership(); | 623 CheckOwnership(); |
| 623 RetrieveTrustedDevicePolicies(); | 624 RetrieveTrustedDevicePolicies(); |
| 624 break; | 625 break; |
| 625 case chrome::NOTIFICATION_PROFILE_ADDED: | 626 case chrome::NOTIFICATION_PROFILE_ADDED: |
| 626 if (IsUserLoggedIn() && | 627 if (IsUserLoggedIn() && |
| 627 !IsLoggedInAsGuest() && | 628 !IsLoggedInAsGuest() && |
| 628 !IsLoggedInAsLocallyManagedUser() && | 629 !IsLoggedInAsLocallyManagedUser() && |
| 629 !IsLoggedInAsKioskApp()) { | 630 !IsLoggedInAsKioskApp()) { |
| 630 Profile* profile = content::Source<Profile>(source).ptr(); | 631 Profile* profile = content::Source<Profile>(source).ptr(); |
| 631 if (!profile->IsOffTheRecord() && | 632 if (!profile->IsOffTheRecord() && |
| 632 // TODO(nkostylev): We should observe all logged in user's profiles. | |
| 633 profile == ProfileManager::GetDefaultProfile()) { | 633 profile == ProfileManager::GetDefaultProfile()) { |
| 634 DCHECK(NULL == observed_sync_service_); | 634 // TODO(nkostylev): We should observe all logged in user's profiles. |
| 635 // http://crbug.com/230860 |
| 636 if (!CommandLine::ForCurrentProcess()-> |
| 637 HasSwitch(::switches::kMultiProfiles)) { |
| 638 DCHECK(NULL == observed_sync_service_); |
| 639 } |
| 635 observed_sync_service_ = | 640 observed_sync_service_ = |
| 636 ProfileSyncServiceFactory::GetForProfile(profile); | 641 ProfileSyncServiceFactory::GetForProfile(profile); |
| 637 if (observed_sync_service_) | 642 if (observed_sync_service_) |
| 638 observed_sync_service_->AddObserver(this); | 643 observed_sync_service_->AddObserver(this); |
| 639 } | 644 } |
| 640 } | 645 } |
| 641 break; | 646 break; |
| 642 case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: | 647 case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: |
| 643 DCHECK_EQ(*content::Details<const std::string>(details).ptr(), | 648 DCHECK_EQ(*content::Details<const std::string>(details).ptr(), |
| 644 kAccountsPrefDeviceLocalAccounts); | 649 kAccountsPrefDeviceLocalAccounts); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 840 session_state_observer_list_.RemoveObserver(obs); | 845 session_state_observer_list_.RemoveObserver(obs); |
| 841 } | 846 } |
| 842 | 847 |
| 843 void UserManagerImpl::NotifyLocalStateChanged() { | 848 void UserManagerImpl::NotifyLocalStateChanged() { |
| 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 849 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 845 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, | 850 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, |
| 846 LocalStateChanged(this)); | 851 LocalStateChanged(this)); |
| 847 } | 852 } |
| 848 | 853 |
| 854 void UserManagerImpl::OnProfilePrepared(Profile* profile) { |
| 855 LoginUtils::Get()->DoBrowserLaunch(profile, |
| 856 NULL); // host_, not needed here |
| 857 |
| 858 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestName)) { |
| 859 // Did not log in (we crashed or are debugging), need to restore Sync. |
| 860 // TODO(nkostylev): Make sure that OAuth state is restored correctly for all |
| 861 // users once it is fully multi-profile aware. http://crbug.com/238987 |
| 862 // For now if we have other user pending sessions they'll override OAuth |
| 863 // session restore for previous users. |
| 864 LoginUtils::Get()->RestoreAuthenticationSession(profile); |
| 865 } |
| 866 |
| 867 // Restore other user sessions if any. |
| 868 RestorePendingUserSessions(); |
| 869 } |
| 870 |
| 849 void UserManagerImpl::EnsureUsersLoaded() { | 871 void UserManagerImpl::EnsureUsersLoaded() { |
| 850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 851 if (!g_browser_process || !g_browser_process->local_state()) | 873 if (!g_browser_process || !g_browser_process->local_state()) |
| 852 return; | 874 return; |
| 853 | 875 |
| 854 if (users_loaded_) | 876 if (users_loaded_) |
| 855 return; | 877 return; |
| 856 users_loaded_ = true; | 878 users_loaded_ = true; |
| 857 | 879 |
| 858 // Clean up user list first. | 880 // Clean up user list first. |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1538 lru_logged_in_users_.end(), | 1560 lru_logged_in_users_.end(), |
| 1539 user); | 1561 user); |
| 1540 if (it != lru_logged_in_users_.end()) | 1562 if (it != lru_logged_in_users_.end()) |
| 1541 lru_logged_in_users_.erase(it); | 1563 lru_logged_in_users_.erase(it); |
| 1542 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); | 1564 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); |
| 1543 } | 1565 } |
| 1544 | 1566 |
| 1545 void UserManagerImpl::OnRestoreActiveSessions( | 1567 void UserManagerImpl::OnRestoreActiveSessions( |
| 1546 const SessionManagerClient::ActiveSessionsMap& sessions, | 1568 const SessionManagerClient::ActiveSessionsMap& sessions, |
| 1547 bool success) { | 1569 bool success) { |
| 1548 // TODO(nkostylev): Restore all user sessions (in the background). | 1570 if (!success) { |
| 1549 // This requires first refactoring this flow out of LoginUtils. | 1571 LOG(ERROR) << "Could not get list of active user sessions after crash."; |
| 1550 // 1. UserManager::UserLoggedIn() | 1572 // If we could not get list of active user sessions it is safer to just |
| 1551 // 2. InitSessionRestoreStrategy() (OAuth) | 1573 // sign out so that we don't get in the inconsistent state. |
| 1552 // 2. ProfileManager::CreateDefaultProfileAsync() | 1574 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession(); |
| 1553 // 3. InitProfilePreferences | 1575 return; |
| 1554 // 4. chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED | 1576 } |
| 1577 |
| 1578 // One profile has been already loaded on browser start. |
| 1579 DCHECK(GetLoggedInUsers().size() == 1); |
| 1580 DCHECK(GetActiveUser()); |
| 1581 std::string active_user_id = GetActiveUser()->email(); |
| 1582 |
| 1583 SessionManagerClient::ActiveSessionsMap::const_iterator it; |
| 1584 for (it = sessions.begin(); it != sessions.end(); ++it) { |
| 1585 if (active_user_id == it->first) |
| 1586 continue; |
| 1587 pending_user_sessions_[it->first] = it->second; |
| 1588 } |
| 1589 RestorePendingUserSessions(); |
| 1590 } |
| 1591 |
| 1592 void UserManagerImpl::RestorePendingUserSessions() { |
| 1593 if (pending_user_sessions_.empty()) |
| 1594 return; |
| 1595 |
| 1596 // Get next user to restore sessions and delete it from list. |
| 1597 SessionManagerClient::ActiveSessionsMap::const_iterator it = |
| 1598 pending_user_sessions_.begin(); |
| 1599 std::string user_id = it->first; |
| 1600 std::string user_id_hash = it->second; |
| 1601 DCHECK(!user_id.empty()); |
| 1602 DCHECK(!user_id_hash.empty()); |
| 1603 pending_user_sessions_.erase(user_id); |
| 1604 |
| 1605 // Check that this user is not logged in yet. |
| 1606 UserList logged_in_users = GetLoggedInUsers(); |
| 1607 bool user_already_logged_in = false; |
| 1608 for (UserList::const_iterator it = logged_in_users.begin(); |
| 1609 it != logged_in_users.end(); ++it) { |
| 1610 const User* user = (*it); |
| 1611 if (user->email() == user_id) { |
| 1612 user_already_logged_in = true; |
| 1613 break; |
| 1614 } |
| 1615 } |
| 1616 DCHECK(!user_already_logged_in); |
| 1617 |
| 1618 if (!user_already_logged_in) { |
| 1619 // Will call OnProfilePrepared() once profile has been loaded. |
| 1620 LoginUtils::Get()->PrepareProfile(UserContext(user_id, |
| 1621 std::string(), // password |
| 1622 std::string(), // auth_code |
| 1623 user_id_hash), |
| 1624 std::string(), // display_email |
| 1625 false, // using_oauth |
| 1626 false, // has_cookies |
| 1627 true, // has_active_session |
| 1628 this); |
| 1629 } else { |
| 1630 RestorePendingUserSessions(); |
| 1631 } |
| 1555 } | 1632 } |
| 1556 | 1633 |
| 1557 } // namespace chromeos | 1634 } // namespace chromeos |
| OLD | NEW |