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" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 if (user_manager->GetLoggedInUsers().size() == 1) { | 321 if (user_manager->GetLoggedInUsers().size() == 1) { |
| 322 if (NetworkPortalDetector::IsInitialized()) { | 322 if (NetworkPortalDetector::IsInitialized()) { |
| 323 NetworkPortalDetector::Get()->SetStrategy( | 323 NetworkPortalDetector::Get()->SetStrategy( |
| 324 PortalDetectorStrategy::STRATEGY_ID_SESSION); | 324 PortalDetectorStrategy::STRATEGY_ID_SESSION); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 | 328 |
| 329 void UserSessionManager::RestoreAuthenticationSession(Profile* user_profile) { | 329 void UserSessionManager::RestoreAuthenticationSession(Profile* user_profile) { |
| 330 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 330 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 331 // We need to restore session only for logged in regular (GAIA) users. | 331 // We need to restore session only for logged in GAIA (regular) users. |
|
bartfab (slow)
2014/11/27 12:51:50
Nit: As elsewhere, I think we can drop the "regula
| |
| 332 // Note: stub user is a special case that is used for tests, running | 332 // Note: stub user is a special case that is used for tests, running |
| 333 // linux_chromeos build on dev workstations w/o user_id parameters. | 333 // linux_chromeos build on dev workstations w/o user_id parameters. |
| 334 // Stub user is considered to be a regular GAIA user but it has special | 334 // Stub user is considered to be a regular GAIA user but it has special |
| 335 // user_id (kStubUser) and certain services like restoring OAuth session are | 335 // user_id (kStubUser) and certain services like restoring OAuth session are |
| 336 // explicitly disabled for it. | 336 // explicitly disabled for it. |
| 337 if (!user_manager->IsUserLoggedIn() || | 337 if (!user_manager->IsUserLoggedIn() || |
| 338 !user_manager->IsLoggedInAsRegularUser() || | 338 !user_manager->IsLoggedInAsUserWithGaiaAccount() || |
| 339 user_manager->IsLoggedInAsStub()) { | 339 user_manager->IsLoggedInAsStub()) { |
| 340 return; | 340 return; |
| 341 } | 341 } |
| 342 | 342 |
| 343 user_manager::User* user = | 343 user_manager::User* user = |
| 344 ProfileHelper::Get()->GetUserByProfile(user_profile); | 344 ProfileHelper::Get()->GetUserByProfile(user_profile); |
| 345 DCHECK(user); | 345 DCHECK(user); |
| 346 if (!net::NetworkChangeNotifier::IsOffline()) { | 346 if (!net::NetworkChangeNotifier::IsOffline()) { |
| 347 pending_signin_restore_sessions_.erase(user->email()); | 347 pending_signin_restore_sessions_.erase(user->email()); |
| 348 RestoreAuthSessionImpl(user_profile, false /* has_auth_cookies */); | 348 RestoreAuthSessionImpl(user_profile, false /* has_auth_cookies */); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 user_manager::UserManager::Get()->IsLoggedInAsGuest(); | 498 user_manager::UserManager::Get()->IsLoggedInAsGuest(); |
| 499 locale_util::SwitchLanguage( | 499 locale_util::SwitchLanguage( |
| 500 pref_locale, enable_layouts, false /* login_layouts_only */, callback); | 500 pref_locale, enable_layouts, false /* login_layouts_only */, callback); |
| 501 | 501 |
| 502 return true; | 502 return true; |
| 503 } | 503 } |
| 504 | 504 |
| 505 bool UserSessionManager::NeedsToUpdateEasyUnlockKeys() const { | 505 bool UserSessionManager::NeedsToUpdateEasyUnlockKeys() const { |
| 506 return EasyUnlockService::IsSignInEnabled() && | 506 return EasyUnlockService::IsSignInEnabled() && |
| 507 !user_context_.GetUserID().empty() && | 507 !user_context_.GetUserID().empty() && |
| 508 user_context_.GetUserType() == user_manager::USER_TYPE_REGULAR && | 508 user_manager::User::TypeHasGaiaAccount(user_context_.GetUserType()) && |
| 509 user_context_.GetKey() && !user_context_.GetKey()->GetSecret().empty(); | 509 user_context_.GetKey() && !user_context_.GetKey()->GetSecret().empty(); |
| 510 } | 510 } |
| 511 | 511 |
| 512 bool UserSessionManager::CheckEasyUnlockKeyOps(const base::Closure& callback) { | 512 bool UserSessionManager::CheckEasyUnlockKeyOps(const base::Closure& callback) { |
| 513 if (!running_easy_unlock_key_ops_) | 513 if (!running_easy_unlock_key_ops_) |
| 514 return false; | 514 return false; |
| 515 | 515 |
| 516 // Assumes only one deferred callback is needed. | 516 // Assumes only one deferred callback is needed. |
| 517 DCHECK(easy_unlock_key_ops_finished_callback_.is_null()); | 517 DCHECK(easy_unlock_key_ops_finished_callback_.is_null()); |
| 518 | 518 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 | 592 |
| 593 void UserSessionManager::OnConnectionTypeChanged( | 593 void UserSessionManager::OnConnectionTypeChanged( |
| 594 net::NetworkChangeNotifier::ConnectionType type) { | 594 net::NetworkChangeNotifier::ConnectionType type) { |
| 595 bool is_running_test = | 595 bool is_running_test = |
| 596 base::CommandLine::ForCurrentProcess()->HasSwitch( | 596 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 597 ::switches::kTestName) || | 597 ::switches::kTestName) || |
| 598 base::CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType); | 598 base::CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType); |
| 599 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 599 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 600 if (type == net::NetworkChangeNotifier::CONNECTION_NONE || | 600 if (type == net::NetworkChangeNotifier::CONNECTION_NONE || |
| 601 !user_manager->IsUserLoggedIn() || | 601 !user_manager->IsUserLoggedIn() || |
| 602 !user_manager->IsLoggedInAsRegularUser() || | 602 !user_manager->IsLoggedInAsUserWithGaiaAccount() || |
| 603 user_manager->IsLoggedInAsStub() || is_running_test) { | 603 user_manager->IsLoggedInAsStub() || is_running_test) { |
| 604 return; | 604 return; |
| 605 } | 605 } |
| 606 | 606 |
| 607 // Need to iterate over all users and their OAuth2 session state. | 607 // Need to iterate over all users and their OAuth2 session state. |
| 608 const user_manager::UserList& users = user_manager->GetLoggedInUsers(); | 608 const user_manager::UserList& users = user_manager->GetLoggedInUsers(); |
| 609 for (user_manager::UserList::const_iterator it = users.begin(); | 609 for (user_manager::UserList::const_iterator it = users.begin(); |
| 610 it != users.end(); | 610 it != users.end(); |
| 611 ++it) { | 611 ++it) { |
| 612 if (!(*it)->is_profile_created()) | 612 if (!(*it)->is_profile_created()) |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 } | 737 } |
| 738 | 738 |
| 739 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { | 739 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { |
| 740 user_manager::User* active_user = | 740 user_manager::User* active_user = |
| 741 user_manager::UserManager::Get()->GetActiveUser(); | 741 user_manager::UserManager::Get()->GetActiveUser(); |
| 742 std::string supervised_user_sync_id = | 742 std::string supervised_user_sync_id = |
| 743 ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId( | 743 ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId( |
| 744 active_user->email()); | 744 active_user->email()); |
| 745 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, | 745 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, |
| 746 supervised_user_sync_id); | 746 supervised_user_sync_id); |
| 747 } else if (user_manager::UserManager::Get()->IsLoggedInAsRegularUser()) { | 747 } else if (user_manager::UserManager::Get()-> |
| 748 IsLoggedInAsUserWithGaiaAccount()) { | |
| 748 // Prime the account tracker with this combination of gaia id/display email. | 749 // Prime the account tracker with this combination of gaia id/display email. |
| 749 // Don't do this unless both email and gaia_id are valid. They may not | 750 // Don't do this unless both email and gaia_id are valid. They may not |
| 750 // be when simply unlocking the profile. | 751 // be when simply unlocking the profile. |
| 751 if (!user_context.GetGaiaID().empty() && | 752 if (!user_context.GetGaiaID().empty() && |
| 752 !user_context.GetUserID().empty()) { | 753 !user_context.GetUserID().empty()) { |
| 753 AccountTrackerService* account_tracker = | 754 AccountTrackerService* account_tracker = |
| 754 AccountTrackerServiceFactory::GetForProfile(profile); | 755 AccountTrackerServiceFactory::GetForProfile(profile); |
| 755 account_tracker->SeedAccountInfo(user_context.GetGaiaID(), | 756 account_tracker->SeedAccountInfo(user_context.GetGaiaID(), |
| 756 user_context.GetUserID()); | 757 user_context.GetUserID()); |
| 757 } | 758 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 841 btl->AddLoginTimeMarker("TPMOwn-Start", false); | 842 btl->AddLoginTimeMarker("TPMOwn-Start", false); |
| 842 if (cryptohome_util::TpmIsEnabled() && !cryptohome_util::TpmIsBeingOwned()) { | 843 if (cryptohome_util::TpmIsEnabled() && !cryptohome_util::TpmIsBeingOwned()) { |
| 843 if (cryptohome_util::TpmIsOwned()) | 844 if (cryptohome_util::TpmIsOwned()) |
| 844 client->CallTpmClearStoredPasswordAndBlock(); | 845 client->CallTpmClearStoredPasswordAndBlock(); |
| 845 else | 846 else |
| 846 client->TpmCanAttemptOwnership(EmptyVoidDBusMethodCallback()); | 847 client->TpmCanAttemptOwnership(EmptyVoidDBusMethodCallback()); |
| 847 } | 848 } |
| 848 btl->AddLoginTimeMarker("TPMOwn-End", false); | 849 btl->AddLoginTimeMarker("TPMOwn-End", false); |
| 849 | 850 |
| 850 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 851 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 851 if (user_manager->IsLoggedInAsRegularUser()) { | 852 if (user_manager->IsLoggedInAsUserWithGaiaAccount()) { |
| 852 SAMLOfflineSigninLimiter* saml_offline_signin_limiter = | 853 SAMLOfflineSigninLimiter* saml_offline_signin_limiter = |
| 853 SAMLOfflineSigninLimiterFactory::GetForProfile(profile); | 854 SAMLOfflineSigninLimiterFactory::GetForProfile(profile); |
| 854 if (saml_offline_signin_limiter) | 855 if (saml_offline_signin_limiter) |
| 855 saml_offline_signin_limiter->SignedIn(user_context_.GetAuthFlow()); | 856 saml_offline_signin_limiter->SignedIn(user_context_.GetAuthFlow()); |
| 856 } | 857 } |
| 857 | 858 |
| 858 profile->OnLogin(); | 859 profile->OnLogin(); |
| 859 | 860 |
| 860 g_browser_process->platform_part()->SessionManager()->SetSessionState( | 861 g_browser_process->platform_part()->SessionManager()->SetSessionState( |
| 861 session_manager::SESSION_STATE_LOGGED_IN_NOT_ACTIVE); | 862 session_manager::SESSION_STATE_LOGGED_IN_NOT_ACTIVE); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1193 } | 1194 } |
| 1194 | 1195 |
| 1195 void UserSessionManager::UpdateEasyUnlockKeys(const UserContext& user_context) { | 1196 void UserSessionManager::UpdateEasyUnlockKeys(const UserContext& user_context) { |
| 1196 // Skip key update because FakeCryptohomeClient always return success | 1197 // Skip key update because FakeCryptohomeClient always return success |
| 1197 // and RemoveKey op expects a failure to stop. As a result, some tests would | 1198 // and RemoveKey op expects a failure to stop. As a result, some tests would |
| 1198 // timeout. | 1199 // timeout. |
| 1199 // TODO(xiyuan): Revisit this when adding tests. | 1200 // TODO(xiyuan): Revisit this when adding tests. |
| 1200 if (!base::SysInfo::IsRunningOnChromeOS()) | 1201 if (!base::SysInfo::IsRunningOnChromeOS()) |
| 1201 return; | 1202 return; |
| 1202 | 1203 |
| 1203 // Only update Easy unlock keys for regular user. | 1204 // Only update Easy unlock keys for regular user. |
|
bartfab (slow)
2014/11/27 12:51:50
Nit: s/regular/gaia/
| |
| 1204 // TODO(xiyuan): Fix inconsistency user type of |user_context| introduced in | 1205 // TODO(xiyuan): Fix inconsistency user type of |user_context| introduced in |
| 1205 // authenticator. | 1206 // authenticator. |
| 1206 const user_manager::User* user = | 1207 const user_manager::User* user = |
| 1207 user_manager::UserManager::Get()->FindUser(user_context.GetUserID()); | 1208 user_manager::UserManager::Get()->FindUser(user_context.GetUserID()); |
| 1208 if (!user || user->GetType() != user_manager::USER_TYPE_REGULAR) | 1209 if (!user || !user->HasGaiaAccount()) |
| 1209 return; | 1210 return; |
| 1210 | 1211 |
| 1211 // Bail if |user_context| does not have secret. | 1212 // Bail if |user_context| does not have secret. |
| 1212 if (user_context.GetKey()->GetSecret().empty()) | 1213 if (user_context.GetKey()->GetSecret().empty()) |
| 1213 return; | 1214 return; |
| 1214 | 1215 |
| 1215 const base::ListValue* device_list = NULL; | 1216 const base::ListValue* device_list = NULL; |
| 1216 EasyUnlockService* easy_unlock_service = EasyUnlockService::GetForUser(*user); | 1217 EasyUnlockService* easy_unlock_service = EasyUnlockService::GetForUser(*user); |
| 1217 if (easy_unlock_service) { | 1218 if (easy_unlock_service) { |
| 1218 device_list = easy_unlock_service->GetRemoteDevices(); | 1219 device_list = easy_unlock_service->GetRemoteDevices(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1279 } | 1280 } |
| 1280 | 1281 |
| 1281 EasyUnlockKeyManager* UserSessionManager::GetEasyUnlockKeyManager() { | 1282 EasyUnlockKeyManager* UserSessionManager::GetEasyUnlockKeyManager() { |
| 1282 if (!easy_unlock_key_manager_) | 1283 if (!easy_unlock_key_manager_) |
| 1283 easy_unlock_key_manager_.reset(new EasyUnlockKeyManager); | 1284 easy_unlock_key_manager_.reset(new EasyUnlockKeyManager); |
| 1284 | 1285 |
| 1285 return easy_unlock_key_manager_.get(); | 1286 return easy_unlock_key_manager_.get(); |
| 1286 } | 1287 } |
| 1287 | 1288 |
| 1288 } // namespace chromeos | 1289 } // namespace chromeos |
| OLD | NEW |