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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 } else { | 395 } else { |
396 authenticator_ = new ChromeCryptohomeAuthenticator(consumer); | 396 authenticator_ = new ChromeCryptohomeAuthenticator(consumer); |
397 } | 397 } |
398 } else { | 398 } else { |
399 // TODO(nkostylev): Fix this hack by improving Authenticator dependencies. | 399 // TODO(nkostylev): Fix this hack by improving Authenticator dependencies. |
400 authenticator_->SetConsumer(consumer); | 400 authenticator_->SetConsumer(consumer); |
401 } | 401 } |
402 return authenticator_; | 402 return authenticator_; |
403 } | 403 } |
404 | 404 |
405 void UserSessionManager::FetchOAuth2Tokens( | |
406 const UserContext& user_context, | |
407 const FetchOAuth2TokensCallback& callback) { | |
408 DCHECK(!user_context.GetAuthCode().empty()); | |
409 login_callback_ = callback; | |
410 user_context_ = user_context; | |
411 oauth2_token_fetcher_.reset(new OAuth2TokenFetcher( | |
412 this, g_browser_process->system_request_context())); | |
413 oauth2_token_fetcher_->StartExchangeFromAuthCode(user_context.GetAuthCode()); | |
414 } | |
415 | |
416 void UserSessionManager::OnOAuth2TokensAvailable( | |
417 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { | |
418 VLOG(1) << "OAuth2 tokens fetched"; | |
419 | |
420 refresh_token_ = oauth2_tokens.refresh_token; | |
421 oauthlogin_access_token_ = oauth2_tokens.access_token; | |
422 login_callback_.Run(user_context_, LoginPerformer::AUTH_MODE_EXTENSION); | |
423 } | |
424 | |
425 void UserSessionManager::OnOAuth2TokensFetchFailed() { | |
426 LOG(WARNING) << "UserSessionManager::OnOAuth2TokensFetchFailed"; | |
xiyuan
2015/04/20 22:02:41
Should we still call login_callback_.Run()? Otherw
achuithb
2015/04/21 07:10:21
Done.
| |
427 } | |
428 | |
405 void UserSessionManager::StartSession( | 429 void UserSessionManager::StartSession( |
406 const UserContext& user_context, | 430 const UserContext& user_context, |
407 StartSessionType start_session_type, | 431 StartSessionType start_session_type, |
408 bool has_auth_cookies, | 432 bool has_auth_cookies, |
409 bool has_active_session, | 433 bool has_active_session, |
410 UserSessionManagerDelegate* delegate) { | 434 UserSessionManagerDelegate* delegate) { |
411 delegate_ = delegate; | 435 delegate_ = delegate; |
412 start_session_type_ = start_session_type; | 436 start_session_type_ = start_session_type; |
413 | 437 |
414 VLOG(1) << "Starting session for " << user_context.GetUserID(); | 438 VLOG(1) << "Starting session for " << user_context.GetUserID(); |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 void UserSessionManager::StopChildStatusObserving() { | 819 void UserSessionManager::StopChildStatusObserving() { |
796 if (!waiting_for_child_account_status_) { | 820 if (!waiting_for_child_account_status_) { |
797 InitializeStartUrls(); | 821 InitializeStartUrls(); |
798 waiting_for_child_account_status_ = false; | 822 waiting_for_child_account_status_ = false; |
799 } | 823 } |
800 } | 824 } |
801 | 825 |
802 void UserSessionManager::CreateUserSession(const UserContext& user_context, | 826 void UserSessionManager::CreateUserSession(const UserContext& user_context, |
803 bool has_auth_cookies) { | 827 bool has_auth_cookies) { |
804 user_context_ = user_context; | 828 user_context_ = user_context; |
829 | |
830 // If we have already fetched OAuth2 tokens, set them here. | |
831 if (!refresh_token_.empty()) | |
832 user_context_.SetRefreshToken(refresh_token_); | |
833 if (!oauthlogin_access_token_.empty()) | |
834 user_context_.SetAuthCode(std::string()); | |
xiyuan
2015/04/20 22:02:41
Move 831-834 to OnOAuth2TokensAvailable.
achuithb
2015/04/21 07:10:21
Done.
| |
835 | |
805 has_auth_cookies_ = has_auth_cookies; | 836 has_auth_cookies_ = has_auth_cookies; |
806 InitSessionRestoreStrategy(); | 837 InitSessionRestoreStrategy(); |
807 StoreUserContextDataBeforeProfileIsCreated(); | 838 StoreUserContextDataBeforeProfileIsCreated(); |
808 } | 839 } |
809 | 840 |
810 void UserSessionManager::PreStartSession() { | 841 void UserSessionManager::PreStartSession() { |
811 // Switch log file as soon as possible. | 842 // Switch log file as soon as possible. |
812 if (base::SysInfo::IsRunningOnChromeOS()) | 843 if (base::SysInfo::IsRunningOnChromeOS()) |
813 logging::RedirectChromeLogging(*(base::CommandLine::ForCurrentProcess())); | 844 logging::RedirectChromeLogging(*(base::CommandLine::ForCurrentProcess())); |
814 } | 845 } |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1207 if (command_line->HasSwitch(::switches::kAppModeAuthCode)) { | 1238 if (command_line->HasSwitch(::switches::kAppModeAuthCode)) { |
1208 user_context_.SetAuthCode(command_line->GetSwitchValueASCII( | 1239 user_context_.SetAuthCode(command_line->GetSwitchValueASCII( |
1209 ::switches::kAppModeAuthCode)); | 1240 ::switches::kAppModeAuthCode)); |
1210 } | 1241 } |
1211 | 1242 |
1212 DCHECK(!has_auth_cookies_); | 1243 DCHECK(!has_auth_cookies_); |
1213 } | 1244 } |
1214 | 1245 |
1215 if (has_auth_cookies_) { | 1246 if (has_auth_cookies_) { |
1216 session_restore_strategy_ = OAuth2LoginManager::RESTORE_FROM_COOKIE_JAR; | 1247 session_restore_strategy_ = OAuth2LoginManager::RESTORE_FROM_COOKIE_JAR; |
1217 } else if (!user_context_.GetAuthCode().empty()) { | 1248 } else if (!oauthlogin_access_token_.empty()) { |
1218 session_restore_strategy_ = OAuth2LoginManager::RESTORE_FROM_AUTH_CODE; | 1249 session_restore_strategy_ = |
1250 OAuth2LoginManager::RESTORE_FROM_PASSED_OAUTH2_ACCESS_TOKEN; | |
xiyuan
2015/04/20 22:02:41
We probably don't need a new strategy. After we ge
achuithb
2015/04/21 07:10:21
So RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN doesn'
xiyuan
2015/04/22 00:37:17
Yes, it should as long as refresh token is involve
achuithb
2015/04/22 22:58:14
Done.
| |
1219 } else if (!user_context_.GetRefreshToken().empty()) { | 1251 } else if (!user_context_.GetRefreshToken().empty()) { |
1220 session_restore_strategy_ = | 1252 session_restore_strategy_ = |
1221 OAuth2LoginManager::RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN; | 1253 OAuth2LoginManager::RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN; |
1222 } else { | 1254 } else { |
1223 session_restore_strategy_ = | 1255 session_restore_strategy_ = |
1224 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN; | 1256 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN; |
1225 } | 1257 } |
1226 } | 1258 } |
1227 | 1259 |
1228 void UserSessionManager::RestoreAuthSessionImpl( | 1260 void UserSessionManager::RestoreAuthSessionImpl( |
(...skipping 21 matching lines...) Expand all Loading... | |
1250 | 1282 |
1251 // Authentication request context may not be available if user was not | 1283 // Authentication request context may not be available if user was not |
1252 // signing in with GAIA webview (i.e. webview instance hasn't been | 1284 // signing in with GAIA webview (i.e. webview instance hasn't been |
1253 // initialized at all). Use fallback request context. | 1285 // initialized at all). Use fallback request context. |
1254 if (!auth_request_context) { | 1286 if (!auth_request_context) { |
1255 auth_request_context = | 1287 auth_request_context = |
1256 authenticator_->authentication_context()->GetRequestContext(); | 1288 authenticator_->authentication_context()->GetRequestContext(); |
1257 } | 1289 } |
1258 login_manager->RestoreSession(auth_request_context, session_restore_strategy_, | 1290 login_manager->RestoreSession(auth_request_context, session_restore_strategy_, |
1259 user_context_.GetRefreshToken(), | 1291 user_context_.GetRefreshToken(), |
1260 user_context_.GetAuthCode()); | 1292 oauthlogin_access_token_); |
1261 } | 1293 } |
1262 | 1294 |
1263 void UserSessionManager::InitRlzImpl(Profile* profile, bool disabled) { | 1295 void UserSessionManager::InitRlzImpl(Profile* profile, bool disabled) { |
1264 #if defined(ENABLE_RLZ) | 1296 #if defined(ENABLE_RLZ) |
1265 PrefService* local_state = g_browser_process->local_state(); | 1297 PrefService* local_state = g_browser_process->local_state(); |
1266 if (disabled) { | 1298 if (disabled) { |
1267 // Empty brand code means an organic install (no RLZ pings are sent). | 1299 // Empty brand code means an organic install (no RLZ pings are sent). |
1268 google_brand::chromeos::ClearBrandForCurrentSession(); | 1300 google_brand::chromeos::ClearBrandForCurrentSession(); |
1269 } | 1301 } |
1270 if (disabled != local_state->GetBoolean(prefs::kRLZDisabled)) { | 1302 if (disabled != local_state->GetBoolean(prefs::kRLZDisabled)) { |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1649 if (is_enterprise_managed) | 1681 if (is_enterprise_managed) |
1650 display = USER_PODS_DISPLAY_DISABLED_MANAGED; | 1682 display = USER_PODS_DISPLAY_DISABLED_MANAGED; |
1651 else | 1683 else |
1652 display = USER_PODS_DISPLAY_DISABLED_REGULAR; | 1684 display = USER_PODS_DISPLAY_DISABLED_REGULAR; |
1653 } | 1685 } |
1654 UMA_HISTOGRAM_ENUMERATION("UserSessionManager.UserPodsDisplay", display, | 1686 UMA_HISTOGRAM_ENUMERATION("UserSessionManager.UserPodsDisplay", display, |
1655 NUM_USER_PODS_DISPLAY); | 1687 NUM_USER_PODS_DISPLAY); |
1656 } | 1688 } |
1657 | 1689 |
1658 } // namespace chromeos | 1690 } // namespace chromeos |
OLD | NEW |