Commit bf491549 authored by mlerman's avatar mlerman Committed by Commit bot

Let Ubertoken Fetch be primed with an access token.

BUG=483596
TEST=Logging in with ChromeOS still results in the user logging into the content area.

Review URL: https://codereview.chromium.org/1129463004

Cr-Commit-Position: refs/heads/master@{#330752}
parent 41065dad
......@@ -52,10 +52,12 @@ void OAuth2LoginVerifier::VerifyUserCookies(Profile* profile) {
void OAuth2LoginVerifier::VerifyProfileTokens(Profile* profile) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// TODO(xiyuan,mlerman): Use |access_token_| to cut down one round trip.
// See http://crbug.com/483596
cookie_manager_service_->AddAccountToCookie(primary_account_id_);
if (access_token_.empty()) {
cookie_manager_service_->AddAccountToCookie(primary_account_id_);
} else {
cookie_manager_service_->AddAccountToCookieWithToken(primary_account_id_,
access_token_);
}
}
void OAuth2LoginVerifier::OnAddAccountToCookieCompleted(
......
......@@ -307,16 +307,16 @@ void GaiaCookieManagerService::Shutdown() {
cookie_changed_subscription_.reset();
}
void GaiaCookieManagerService::AddAccountToCookie(
void GaiaCookieManagerService::AddAccountToCookieInternal(
const std::string& account_id) {
DCHECK(!account_id.empty());
if (!signin_client_->AreSigninCookiesAllowed()) {
SignalComplete(account_id,
GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED));
return;
}
DCHECK(!account_id.empty());
VLOG(1) << "GaiaCookieManagerService::AddAccountToCookie: " << account_id;
requests_.push_back(GaiaCookieRequest::CreateAddAccountRequest(account_id));
if (requests_.size() == 1) {
signin_client_->DelayNetworkCall(
......@@ -325,6 +325,23 @@ void GaiaCookieManagerService::AddAccountToCookie(
}
}
void GaiaCookieManagerService::AddAccountToCookie(
const std::string& account_id) {
VLOG(1) << "GaiaCookieManagerService::AddAccountToCookie: " << account_id;
access_token_ = std::string();
AddAccountToCookieInternal(account_id);
}
void GaiaCookieManagerService::AddAccountToCookieWithToken(
const std::string& account_id,
const std::string& access_token) {
VLOG(1) << "GaiaCookieManagerService::AddAccountToCookieWithToken: "
<< account_id;
DCHECK(!access_token.empty());
access_token_ = access_token;
AddAccountToCookieInternal(account_id);
}
bool GaiaCookieManagerService::ListAccounts(
std::vector<std::pair<std::string,bool> >* accounts) {
DCHECK(accounts);
......@@ -590,12 +607,17 @@ void GaiaCookieManagerService::OnListAccountsFailure(
}
void GaiaCookieManagerService::StartFetchingUbertoken() {
VLOG(1) << "GaiaCookieManagerService::StartFetching account_id="
VLOG(1) << "GaiaCookieManagerService::StartFetchingUbertoken account_id="
<< requests_.front().account_id();
uber_token_fetcher_.reset(
new UbertokenFetcher(token_service_, this, source_,
signin_client_->GetURLRequestContext()));
uber_token_fetcher_->StartFetchingToken(requests_.front().account_id());
if (access_token_.empty()) {
uber_token_fetcher_->StartFetchingToken(requests_.front().account_id());
} else {
uber_token_fetcher_->StartFetchingTokenWithAccessToken(
requests_.front().account_id(), access_token_);
}
}
void GaiaCookieManagerService::StartFetchingMergeSession() {
......@@ -659,6 +681,7 @@ void GaiaCookieManagerService::HandleNextRequest() {
if (requests_.empty()) {
VLOG(1) << "GaiaCookieManagerService::HandleNextRequest: no more";
uber_token_fetcher_.reset();
access_token_ = std::string();
} else {
switch (requests_.front().request_type()) {
case GaiaCookieRequestType::ADD_ACCOUNT:
......
......@@ -160,6 +160,8 @@ class GaiaCookieManagerService : public KeyedService,
void Shutdown() override;
void AddAccountToCookie(const std::string& account_id);
void AddAccountToCookieWithToken(const std::string& account_id,
const std::string& access_token);
// Returns if the listed accounts are up to date or not (ignore the out
// parameter if return is false). The parameter will be assigned the current
......@@ -214,6 +216,9 @@ class GaiaCookieManagerService : public KeyedService,
void OnListAccountsSuccess(const std::string& data) override;
void OnListAccountsFailure(const GoogleServiceAuthError& error) override;
// Helper method for AddAccountToCookie* methods.
void AddAccountToCookieInternal(const std::string& account_id);
// Starts the proess of fetching the uber token and performing a merge session
// for the next account. Virtual so that it can be overriden in tests.
virtual void StartFetchingUbertoken();
......@@ -250,6 +255,9 @@ class GaiaCookieManagerService : public KeyedService,
// The last fetched ubertoken, for use in MergeSession retries.
std::string uber_token_;
// The access token that can be used to prime the UberToken fetch.
std::string access_token_;
// Subscription to be called whenever the GAIA cookies change.
scoped_ptr<SigninClient::CookieChangedSubscription>
cookie_changed_subscription_;
......
......@@ -43,6 +43,16 @@ void UbertokenFetcher::StartFetchingToken(const std::string& account_id) {
RequestAccessToken();
}
void UbertokenFetcher::StartFetchingTokenWithAccessToken(
const std::string& account_id, const std::string& access_token) {
DCHECK(!account_id.empty());
DCHECK(!access_token.empty());
account_id_ = account_id;
access_token_ = access_token;
ExchangeTokens();
}
void UbertokenFetcher::OnUberAuthTokenSuccess(const std::string& token) {
consumer_->OnUbertokenSuccess(token);
}
......
......@@ -50,6 +50,8 @@ class UbertokenFetcher : public GaiaAuthConsumer,
// Start fetching the token for |account_id|.
virtual void StartFetchingToken(const std::string& account_id);
virtual void StartFetchingTokenWithAccessToken(const std::string& account_id,
const std::string& access_token);
// Overriden from GaiaAuthConsumer
void OnUberAuthTokenSuccess(const std::string& token) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment