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

Unified Diff: chrome/browser/signin/dice_response_handler.cc

Issue 2950073002: [Signin] Handle multiple concurrent Dice responses (Closed)
Patch Set: add tests Created 3 years, 6 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/signin/dice_response_handler.cc
diff --git a/chrome/browser/signin/dice_response_handler.cc b/chrome/browser/signin/dice_response_handler.cc
index 6a7aaf20681cccc66f1ae8aab5bd195279a93262..1369eb1d86d86219b402549283c5c144e7d890cd 100644
--- a/chrome/browser/signin/dice_response_handler.cc
+++ b/chrome/browser/signin/dice_response_handler.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/signin/dice_response_handler.h"
+#include "base/logging.h"
#include "base/memory/singleton.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
@@ -64,6 +65,45 @@ class DiceResponseHandlerFactory : public BrowserContextKeyedServiceFactory {
} // namespace
+////////////////////////////////////////////////////////////////////////////////
+// DiceTokenFetcher
+////////////////////////////////////////////////////////////////////////////////
+
+DiceResponseHandler::DiceTokenFetcher::DiceTokenFetcher(
+ const std::string& gaia_id,
+ const std::string& email,
+ const std::string& authorization_code,
+ SigninClient* signin_client,
+ DiceResponseHandler* dice_response_handler)
+ : gaia_id_(gaia_id),
+ email_(email),
+ dice_response_handler_(dice_response_handler) {
+ gaia_auth_fetcher_ = signin_client->CreateGaiaAuthFetcher(
+ this, GaiaConstants::kChromeSource,
+ signin_client->GetURLRequestContext());
+ gaia_auth_fetcher_->StartAuthCodeForOAuth2TokenExchange(authorization_code);
+
+ // TODO(droger): The token exchange must complete quickly or be cancelled. Add
+ // a timeout logic.
+}
+
+DiceResponseHandler::DiceTokenFetcher::~DiceTokenFetcher() {}
+
+void DiceResponseHandler::DiceTokenFetcher::OnClientOAuthSuccess(
+ const GaiaAuthConsumer::ClientOAuthResult& result) {
+ dice_response_handler_->OnTokenExchangeSuccess(this, gaia_id_, email_,
+ result);
+}
+
+void DiceResponseHandler::DiceTokenFetcher::OnClientOAuthFailure(
+ const GoogleServiceAuthError& error) {
+ dice_response_handler_->OnTokenExchangeFailure(this, error);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DiceResponseHandler
+////////////////////////////////////////////////////////////////////////////////
+
// static
DiceResponseHandler* DiceResponseHandler::GetForProfile(Profile* profile) {
return DiceResponseHandlerFactory::GetForProfile(profile);
@@ -110,36 +150,41 @@ void DiceResponseHandler::ProcessDiceSigninHeader(
const std::string& gaia_id,
const std::string& email,
const std::string& authorization_code) {
- DCHECK(!gaia_auth_fetcher_);
- DCHECK(gaia_id_.empty());
- DCHECK(email_.empty());
- gaia_id_ = gaia_id;
- email_ = email;
- gaia_auth_fetcher_ = signin_client_->CreateGaiaAuthFetcher(
- this, GaiaConstants::kChromeSource,
- signin_client_->GetURLRequestContext());
- gaia_auth_fetcher_->StartAuthCodeForOAuth2TokenExchange(authorization_code);
+ for (auto it = token_fetchers_.begin(); it != token_fetchers_.end(); ++it) {
+ if ((it->get()->gaia_id() == gaia_id) && (it->get()->email() == email))
msarda 2017/06/22 09:51:31 This is a tricky case - in this case the Gaia cook
droger 2017/06/22 11:54:20 Thanks fro bringing that up. Summary of offline d
+ return; // There is already a request in flight with the same parameters.
+ }
- // TODO(droger): The token exchange must complete quickly or be cancelled. Add
- // a timeout logic.
+ token_fetchers_.push_back(base::MakeUnique<DiceTokenFetcher>(
+ gaia_id, email, authorization_code, signin_client_, this));
}
-void DiceResponseHandler::OnClientOAuthSuccess(
- const ClientOAuthResult& result) {
+void DiceResponseHandler::DeleteTokenFetcher(DiceTokenFetcher* token_fetcher) {
+ for (auto it = token_fetchers_.begin(); it != token_fetchers_.end(); ++it) {
+ if (it->get() == token_fetcher) {
+ token_fetchers_.erase(it);
+ return;
+ }
+ }
+ NOTREACHED();
+}
+
+void DiceResponseHandler::OnTokenExchangeSuccess(
+ DiceTokenFetcher* token_fetcher,
+ const std::string& gaia_id,
+ const std::string& email,
+ const GaiaAuthConsumer::ClientOAuthResult& result) {
std::string account_id =
- account_tracker_service_->SeedAccountInfo(gaia_id_, email_);
+ account_tracker_service_->SeedAccountInfo(gaia_id, email);
profile_oauth2_token_service_->UpdateCredentials(account_id,
result.refresh_token);
- gaia_id_.clear();
- email_.clear();
- gaia_auth_fetcher_.reset();
+ DeleteTokenFetcher(token_fetcher);
}
-void DiceResponseHandler::OnClientOAuthFailure(
+void DiceResponseHandler::OnTokenExchangeFailure(
+ DiceTokenFetcher* token_fetcher,
const GoogleServiceAuthError& error) {
// TODO(droger): Handle authentication errors.
DLOG(ERROR) << "Dice OAuth failed: " << error.error_message();
- gaia_id_.clear();
- email_.clear();
- gaia_auth_fetcher_.reset();
+ DeleteTokenFetcher(token_fetcher);
}

Powered by Google App Engine
This is Rietveld 408576698