Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(655)

Unified Diff: chrome/browser/chromeos/login/session/user_session_manager.cc

Issue 1097663003: Fetch OAuth2 tokens prior to profile creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove logging Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/session/user_session_manager.cc
diff --git a/chrome/browser/chromeos/login/session/user_session_manager.cc b/chrome/browser/chromeos/login/session/user_session_manager.cc
index 50f75fb68cd713c08ddc28c90c3147a267af8aac..17aee896b8e568484a20e51941d525876ec81b1f 100644
--- a/chrome/browser/chromeos/login/session/user_session_manager.cc
+++ b/chrome/browser/chromeos/login/session/user_session_manager.cc
@@ -402,6 +402,30 @@ scoped_refptr<Authenticator> UserSessionManager::CreateAuthenticator(
return authenticator_;
}
+void UserSessionManager::FetchOAuth2Tokens(
+ const UserContext& user_context,
+ const FetchOAuth2TokensCallback& callback) {
+ DCHECK(!user_context.GetAuthCode().empty());
+ login_callback_ = callback;
+ user_context_ = user_context;
+ oauth2_token_fetcher_.reset(new OAuth2TokenFetcher(
+ this, g_browser_process->system_request_context()));
+ oauth2_token_fetcher_->StartExchangeFromAuthCode(user_context.GetAuthCode());
+}
+
+void UserSessionManager::OnOAuth2TokensAvailable(
+ const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) {
+ VLOG(1) << "OAuth2 tokens fetched";
+
+ refresh_token_ = oauth2_tokens.refresh_token;
+ oauthlogin_access_token_ = oauth2_tokens.access_token;
+ login_callback_.Run(user_context_, LoginPerformer::AUTH_MODE_EXTENSION);
+}
+
+void UserSessionManager::OnOAuth2TokensFetchFailed() {
+ 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.
+}
+
void UserSessionManager::StartSession(
const UserContext& user_context,
StartSessionType start_session_type,
@@ -802,6 +826,13 @@ void UserSessionManager::StopChildStatusObserving() {
void UserSessionManager::CreateUserSession(const UserContext& user_context,
bool has_auth_cookies) {
user_context_ = user_context;
+
+ // If we have already fetched OAuth2 tokens, set them here.
+ if (!refresh_token_.empty())
+ user_context_.SetRefreshToken(refresh_token_);
+ if (!oauthlogin_access_token_.empty())
+ 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.
+
has_auth_cookies_ = has_auth_cookies;
InitSessionRestoreStrategy();
StoreUserContextDataBeforeProfileIsCreated();
@@ -1214,8 +1245,9 @@ void UserSessionManager::InitSessionRestoreStrategy() {
if (has_auth_cookies_) {
session_restore_strategy_ = OAuth2LoginManager::RESTORE_FROM_COOKIE_JAR;
- } else if (!user_context_.GetAuthCode().empty()) {
- session_restore_strategy_ = OAuth2LoginManager::RESTORE_FROM_AUTH_CODE;
+ } else if (!oauthlogin_access_token_.empty()) {
+ session_restore_strategy_ =
+ 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.
} else if (!user_context_.GetRefreshToken().empty()) {
session_restore_strategy_ =
OAuth2LoginManager::RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN;
@@ -1257,7 +1289,7 @@ void UserSessionManager::RestoreAuthSessionImpl(
}
login_manager->RestoreSession(auth_request_context, session_restore_strategy_,
user_context_.GetRefreshToken(),
- user_context_.GetAuthCode());
+ oauthlogin_access_token_);
}
void UserSessionManager::InitRlzImpl(Profile* profile, bool disabled) {

Powered by Google App Engine
This is Rietveld 408576698