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 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 // authentication to the user's profile. The proxy authentication state is | 990 // authentication to the user's profile. The proxy authentication state is |
991 // transferred unconditionally. If the user authenticated via an auth | 991 // transferred unconditionally. If the user authenticated via an auth |
992 // extension, authentication cookies and channel IDs will be transferred as | 992 // extension, authentication cookies and channel IDs will be transferred as |
993 // well when the user's cookie jar is empty. If the cookie jar is not empty, | 993 // well when the user's cookie jar is empty. If the cookie jar is not empty, |
994 // the authentication states in the browser context and the user's profile | 994 // the authentication states in the browser context and the user's profile |
995 // must be merged using /MergeSession instead. Authentication cookies set by | 995 // must be merged using /MergeSession instead. Authentication cookies set by |
996 // a SAML IdP will also be transferred when the user's cookie jar is not | 996 // a SAML IdP will also be transferred when the user's cookie jar is not |
997 // empty if |transfer_saml_auth_cookies_on_subsequent_login| is true. | 997 // empty if |transfer_saml_auth_cookies_on_subsequent_login| is true. |
998 const bool transfer_auth_cookies_and_channel_ids_on_first_login = | 998 const bool transfer_auth_cookies_and_channel_ids_on_first_login = |
999 has_auth_cookies_; | 999 has_auth_cookies_; |
1000 ProfileAuthData::Transfer( | 1000 |
1001 GetAuthRequestContext(), | 1001 net::URLRequestContextGetter* auth_request_context = |
1002 profile->GetRequestContext(), | 1002 GetAuthRequestContext(); |
1003 transfer_auth_cookies_and_channel_ids_on_first_login, | 1003 |
1004 transfer_saml_auth_cookies_on_subsequent_login, | 1004 // Authentication request context may be missing especially if user didn't |
1005 base::Bind(&UserSessionManager::CompleteProfileCreateAfterAuthTransfer, | 1005 // sign in using GAIA (webview) and webview didn't yet initialize. |
1006 AsWeakPtr(), | 1006 if (auth_request_context) { |
1007 profile)); | 1007 ProfileAuthData::Transfer( |
| 1008 auth_request_context, profile->GetRequestContext(), |
| 1009 transfer_auth_cookies_and_channel_ids_on_first_login, |
| 1010 transfer_saml_auth_cookies_on_subsequent_login, |
| 1011 base::Bind( |
| 1012 &UserSessionManager::CompleteProfileCreateAfterAuthTransfer, |
| 1013 AsWeakPtr(), profile)); |
| 1014 } else { |
| 1015 // We need to post task so that OnProfileCreated() caller sends out |
| 1016 // NOTIFICATION_PROFILE_CREATED which marks user profile as initialized. |
| 1017 base::MessageLoopProxy::current()->PostTask( |
| 1018 FROM_HERE, |
| 1019 base::Bind( |
| 1020 &UserSessionManager::CompleteProfileCreateAfterAuthTransfer, |
| 1021 AsWeakPtr(), profile)); |
| 1022 } |
1008 return; | 1023 return; |
1009 } | 1024 } |
1010 | 1025 |
1011 FinalizePrepareProfile(profile); | 1026 FinalizePrepareProfile(profile); |
1012 } | 1027 } |
1013 | 1028 |
1014 void UserSessionManager::CompleteProfileCreateAfterAuthTransfer( | 1029 void UserSessionManager::CompleteProfileCreateAfterAuthTransfer( |
1015 Profile* profile) { | 1030 Profile* profile) { |
1016 RestoreAuthSessionImpl(profile, has_auth_cookies_); | 1031 RestoreAuthSessionImpl(profile, has_auth_cookies_); |
1017 FinalizePrepareProfile(profile); | 1032 FinalizePrepareProfile(profile); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 | 1239 |
1225 exit_after_session_restore_ = false; | 1240 exit_after_session_restore_ = false; |
1226 | 1241 |
1227 // Remove legacy OAuth1 token if we have one. If it's valid, we should already | 1242 // Remove legacy OAuth1 token if we have one. If it's valid, we should already |
1228 // have OAuth2 refresh token in OAuth2TokenService that could be used to | 1243 // have OAuth2 refresh token in OAuth2TokenService that could be used to |
1229 // retrieve all other tokens and user_context. | 1244 // retrieve all other tokens and user_context. |
1230 OAuth2LoginManager* login_manager = | 1245 OAuth2LoginManager* login_manager = |
1231 OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile); | 1246 OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile); |
1232 login_manager->AddObserver(this); | 1247 login_manager->AddObserver(this); |
1233 | 1248 |
1234 login_manager->RestoreSession( | 1249 net::URLRequestContextGetter* auth_request_context = GetAuthRequestContext(); |
1235 GetAuthRequestContext(), session_restore_strategy_, | 1250 |
1236 user_context_.GetRefreshToken(), user_context_.GetAuthCode()); | 1251 // Authentication request context may not be available if user was not |
| 1252 // signing in with GAIA webview (i.e. webview instance hasn't been |
| 1253 // initialized at all). Use fallback request context. |
| 1254 if (!auth_request_context) { |
| 1255 auth_request_context = |
| 1256 authenticator_->authentication_context()->GetRequestContext(); |
| 1257 } |
| 1258 login_manager->RestoreSession(auth_request_context, session_restore_strategy_, |
| 1259 user_context_.GetRefreshToken(), |
| 1260 user_context_.GetAuthCode()); |
1237 } | 1261 } |
1238 | 1262 |
1239 void UserSessionManager::InitRlzImpl(Profile* profile, bool disabled) { | 1263 void UserSessionManager::InitRlzImpl(Profile* profile, bool disabled) { |
1240 #if defined(ENABLE_RLZ) | 1264 #if defined(ENABLE_RLZ) |
1241 PrefService* local_state = g_browser_process->local_state(); | 1265 PrefService* local_state = g_browser_process->local_state(); |
1242 if (disabled) { | 1266 if (disabled) { |
1243 // Empty brand code means an organic install (no RLZ pings are sent). | 1267 // Empty brand code means an organic install (no RLZ pings are sent). |
1244 google_brand::chromeos::ClearBrandForCurrentSession(); | 1268 google_brand::chromeos::ClearBrandForCurrentSession(); |
1245 } | 1269 } |
1246 if (disabled != local_state->GetBoolean(prefs::kRLZDisabled)) { | 1270 if (disabled != local_state->GetBoolean(prefs::kRLZDisabled)) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 EasyUnlockKeyManager* key_manager = GetEasyUnlockKeyManager(); | 1439 EasyUnlockKeyManager* key_manager = GetEasyUnlockKeyManager(); |
1416 running_easy_unlock_key_ops_ = true; | 1440 running_easy_unlock_key_ops_ = true; |
1417 key_manager->RefreshKeys( | 1441 key_manager->RefreshKeys( |
1418 user_context, *device_list, | 1442 user_context, *device_list, |
1419 base::Bind(&UserSessionManager::OnEasyUnlockKeyOpsFinished, AsWeakPtr(), | 1443 base::Bind(&UserSessionManager::OnEasyUnlockKeyOpsFinished, AsWeakPtr(), |
1420 user_context.GetUserID())); | 1444 user_context.GetUserID())); |
1421 } | 1445 } |
1422 | 1446 |
1423 net::URLRequestContextGetter* | 1447 net::URLRequestContextGetter* |
1424 UserSessionManager::GetAuthRequestContext() const { | 1448 UserSessionManager::GetAuthRequestContext() const { |
1425 net::URLRequestContextGetter* auth_request_context = NULL; | 1449 net::URLRequestContextGetter* auth_request_context = nullptr; |
1426 | 1450 |
1427 if (StartupUtils::IsWebviewSigninEnabled()) { | 1451 if (StartupUtils::IsWebviewSigninEnabled()) { |
1428 // Webview uses different partition storage than iframe. We need to get | 1452 // Webview uses different partition storage than iframe. We need to get |
1429 // cookies from the right storage for url request to get auth token into | 1453 // cookies from the right storage for url request to get auth token into |
1430 // session. | 1454 // session. |
1431 auth_request_context = login::GetSigninPartition()->GetURLRequestContext(); | 1455 content::StoragePartition* signin_partition = login::GetSigninPartition(); |
| 1456 if (signin_partition) |
| 1457 auth_request_context = signin_partition->GetURLRequestContext(); |
1432 } else if (authenticator_.get() && authenticator_->authentication_context()) { | 1458 } else if (authenticator_.get() && authenticator_->authentication_context()) { |
1433 auth_request_context = | 1459 auth_request_context = |
1434 authenticator_->authentication_context()->GetRequestContext(); | 1460 authenticator_->authentication_context()->GetRequestContext(); |
1435 } | 1461 } |
1436 return auth_request_context; | 1462 return auth_request_context; |
1437 } | 1463 } |
1438 | 1464 |
1439 void UserSessionManager::AttemptRestart(Profile* profile) { | 1465 void UserSessionManager::AttemptRestart(Profile* profile) { |
1440 if (CheckEasyUnlockKeyOps(base::Bind(&UserSessionManager::AttemptRestart, | 1466 if (CheckEasyUnlockKeyOps(base::Bind(&UserSessionManager::AttemptRestart, |
1441 AsWeakPtr(), profile))) { | 1467 AsWeakPtr(), profile))) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 if (is_enterprise_managed) | 1649 if (is_enterprise_managed) |
1624 display = USER_PODS_DISPLAY_DISABLED_MANAGED; | 1650 display = USER_PODS_DISPLAY_DISABLED_MANAGED; |
1625 else | 1651 else |
1626 display = USER_PODS_DISPLAY_DISABLED_REGULAR; | 1652 display = USER_PODS_DISPLAY_DISABLED_REGULAR; |
1627 } | 1653 } |
1628 UMA_HISTOGRAM_ENUMERATION("UserSessionManager.UserPodsDisplay", display, | 1654 UMA_HISTOGRAM_ENUMERATION("UserSessionManager.UserPodsDisplay", display, |
1629 NUM_USER_PODS_DISPLAY); | 1655 NUM_USER_PODS_DISPLAY); |
1630 } | 1656 } |
1631 | 1657 |
1632 } // namespace chromeos | 1658 } // namespace chromeos |
OLD | NEW |