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

Unified Diff: chrome/browser/chromeos/login/oauth2_login_manager.cc

Issue 23678007: OAuth2LoginManager+MergeSessionThrottle hardening, multi-profle support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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/oauth2_login_manager.cc
diff --git a/chrome/browser/chromeos/login/oauth2_login_manager.cc b/chrome/browser/chromeos/login/oauth2_login_manager.cc
index b5efe020333c7d1e5580e5fde47c3f29b4fd3ce3..383f815feb3cc19b392fd785a0466ee5f3b3d064 100644
--- a/chrome/browser/chromeos/login/oauth2_login_manager.cc
+++ b/chrome/browser/chromeos/login/oauth2_login_manager.cc
@@ -21,25 +21,34 @@
namespace chromeos {
-OAuth2LoginManager::OAuth2LoginManager(OAuthLoginManager::Delegate* delegate)
- : OAuthLoginManager(delegate),
+OAuth2LoginManager::OAuth2LoginManager(Profile* user_profile)
+ : user_profile_(user_profile),
+ restore_strategy_(RESTORE_FROM_COOKIE_JAR),
+ state_(SESSION_RESTORE_NOT_STARTED),
loading_reported_(false) {
+ ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_)->
+ AddObserver(this);
}
OAuth2LoginManager::~OAuth2LoginManager() {
- StopObservingRefreshToken();
+}
+
+void OAuth2LoginManager::AddObserver(OAuth2LoginManager::Observer* observer) {
+ observer_list_.AddObserver(observer);
+}
+
+void OAuth2LoginManager::RemoveObserver(OAuth2LoginManager::Observer* observer) {
+ observer_list_.RemoveObserver(observer);
}
void OAuth2LoginManager::RestoreSession(
- Profile* user_profile,
net::URLRequestContextGetter* auth_request_context,
SessionRestoreStrategy restore_strategy,
const std::string& oauth2_refresh_token,
const std::string& auth_code) {
- StopObservingRefreshToken();
- user_profile_ = user_profile;
+ DCHECK(user_profile_);
auth_request_context_ = auth_request_context;
- state_ = OAuthLoginManager::SESSION_RESTORE_IN_PROGRESS;
+ state_ = OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS;
restore_strategy_ = restore_strategy;
refresh_token_ = oauth2_refresh_token;
auth_code_ = auth_code;
@@ -49,9 +58,6 @@ void OAuth2LoginManager::RestoreSession(
// below until OAuthLoginManager fully supports multi-profiles.
Stop();
- ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_)->
- AddObserver(this);
-
ContinueSessionRestore();
}
@@ -83,8 +89,12 @@ void OAuth2LoginManager::Stop() {
void OAuth2LoginManager::OnRefreshTokenAvailable(
const std::string& account_id) {
+ if (state_ == SESSION_RESTORE_NOT_STARTED)
+ return;
+
// TODO(fgorski): Once ProfileOAuth2TokenService supports multi-login, make
// sure to restore session cookies in the context of the correct account_id.
+ LOG(INFO) << "OnRefreshTokenAvailable";
RestoreSessionCookies();
}
@@ -123,6 +133,8 @@ void OAuth2LoginManager::FetchOAuth2Tokens() {
oauth2_token_fetcher_->StartExchangeFromAuthCode(auth_code_);
} else {
NOTREACHED();
+ FOR_EACH_OBSERVER(Observer, observer_list_,
+ OnCompletedMergeSession(user_profile_));
}
}
@@ -134,7 +146,7 @@ void OAuth2LoginManager::OnOAuth2TokensAvailable(
void OAuth2LoginManager::OnOAuth2TokensFetchFailed() {
LOG(ERROR) << "OAuth2 tokens fetch failed!";
- state_ = OAuthLoginManager::SESSION_RESTORE_DONE;
+ state_ = OAuth2LoginManager::SESSION_RESTORE_DONE;
UserManager::Get()->SaveUserOAuthStatus(
UserManager::Get()->GetLoggedInUser()->email(),
User::OAUTH2_TOKEN_STATUS_INVALID);
@@ -145,6 +157,8 @@ void OAuth2LoginManager::OnOAuth2TokensFetchFailed() {
void OAuth2LoginManager::RestoreSessionCookies() {
DCHECK(!login_verifier_.get());
+ FOR_EACH_OBSERVER(Observer, observer_list_,
+ OnStartMergeSession(user_profile_));
login_verifier_.reset(
new OAuth2LoginVerifier(this,
g_browser_process->system_request_context(),
@@ -152,6 +166,13 @@ void OAuth2LoginManager::RestoreSessionCookies() {
login_verifier_->VerifyProfileTokens(user_profile_);
}
+void OAuth2LoginManager::Shutdown() {
+ ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_)->
+ RemoveObserver(this);
+ login_verifier_.reset();
+ oauth2_token_fetcher_.reset();
+}
+
void OAuth2LoginManager::OnOAuthLoginSuccess(
const GaiaAuthConsumer::ClientLoginResult& gaia_credentials) {
LOG(INFO) << "OAuth2 refresh token successfully exchanged for GAIA token.";
@@ -160,52 +181,53 @@ void OAuth2LoginManager::OnOAuthLoginSuccess(
void OAuth2LoginManager::OnOAuthLoginFailure() {
LOG(ERROR) << "OAuth2 refresh token verification failed!";
- state_ = OAuthLoginManager::SESSION_RESTORE_DONE;
+ state_ = OAuth2LoginManager::SESSION_RESTORE_DONE;
UserManager::Get()->SaveUserOAuthStatus(
UserManager::Get()->GetLoggedInUser()->email(),
User::OAUTH2_TOKEN_STATUS_INVALID);
UMA_HISTOGRAM_ENUMERATION("OAuth2Login.SessionRestore",
SESSION_RESTORE_OAUTHLOGIN_FAILED,
SESSION_RESTORE_COUNT);
- delegate_->OnCompletedMergeSession();
+ FOR_EACH_OBSERVER(Observer, observer_list_,
+ OnCompletedMergeSession(user_profile_));
}
void OAuth2LoginManager::OnSessionMergeSuccess() {
LOG(INFO) << "OAuth2 refresh and/or GAIA token verification succeeded.";
- state_ = OAuthLoginManager::SESSION_RESTORE_DONE;
+ state_ = OAuth2LoginManager::SESSION_RESTORE_DONE;
UserManager::Get()->SaveUserOAuthStatus(
UserManager::Get()->GetLoggedInUser()->email(),
User::OAUTH2_TOKEN_STATUS_VALID);
UMA_HISTOGRAM_ENUMERATION("OAuth2Login.SessionRestore",
SESSION_RESTORE_SUCCESS,
SESSION_RESTORE_COUNT);
- delegate_->OnCompletedMergeSession();
+ FOR_EACH_OBSERVER(Observer, observer_list_,
+ OnCompletedMergeSession(user_profile_));
}
void OAuth2LoginManager::OnSessionMergeFailure() {
LOG(ERROR) << "OAuth2 refresh and GAIA token verification failed!";
- state_ = OAuthLoginManager::SESSION_RESTORE_DONE;
+ state_ = OAuth2LoginManager::SESSION_RESTORE_DONE;
UserManager::Get()->SaveUserOAuthStatus(
UserManager::Get()->GetLoggedInUser()->email(),
User::OAUTH2_TOKEN_STATUS_INVALID);
UMA_HISTOGRAM_ENUMERATION("OAuth2Login.SessionRestore",
SESSION_RESTORE_MERGE_SESSION_FAILED,
SESSION_RESTORE_COUNT);
- delegate_->OnCompletedMergeSession();
+ FOR_EACH_OBSERVER(Observer, observer_list_,
+ OnCompletedMergeSession(user_profile_));
}
void OAuth2LoginManager::StartTokenService(
const GaiaAuthConsumer::ClientLoginResult& gaia_credentials) {
TokenService* token_service = SetupTokenService();
token_service->UpdateCredentials(gaia_credentials);
- CompleteAuthentication();
-}
-void OAuth2LoginManager::StopObservingRefreshToken() {
- if (user_profile_) {
- ProfileOAuth2TokenServiceFactory::GetForProfile(user_profile_)->
- RemoveObserver(this);
- }
+ FOR_EACH_OBSERVER(Observer, observer_list_,
+ OnCompletedAuthentication(user_profile_));
+
+ if (token_service->AreCredentialsValid())
+ token_service->StartFetchingTokens();
}
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698