Commit 6fd575e1 authored by Valeriya Sinevich's avatar Valeriya Sinevich Committed by Commit Bot

Implement StartFetchingAccesstokens

Now CookieManagerService inherits from TokenServoice::consumer and can fetch access tokens.

Change-Id: I0329257b9cb5908576beb7dae7b938c0d39cd487
Reviewed-on: https://chromium-review.googlesource.com/1169816
Commit-Queue: Valeriya Sinevich <valeriyas@google.com>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584044}
parent b0a316c7
...@@ -350,7 +350,8 @@ GaiaCookieManagerService::GaiaCookieManagerService( ...@@ -350,7 +350,8 @@ GaiaCookieManagerService::GaiaCookieManagerService(
OAuth2TokenService* token_service, OAuth2TokenService* token_service,
const std::string& source, const std::string& source,
SigninClient* signin_client) SigninClient* signin_client)
: token_service_(token_service), : OAuth2TokenService::Consumer("gaia_cookie_manager"),
token_service_(token_service),
signin_client_(signin_client), signin_client_(signin_client),
external_cc_result_fetcher_(this), external_cc_result_fetcher_(this),
fetcher_backoff_(&kBackoffPolicy), fetcher_backoff_(&kBackoffPolicy),
...@@ -413,6 +414,10 @@ void GaiaCookieManagerService::SetAccountsInCookie( ...@@ -413,6 +414,10 @@ void GaiaCookieManagerService::SetAccountsInCookie(
} }
} }
void GaiaCookieManagerService::SetAccountsInCookieWithTokens() {
// TODO (valeriyas): map account_ids with tokens and call StartMultilogin...
}
void GaiaCookieManagerService::AddAccountToCookieInternal( void GaiaCookieManagerService::AddAccountToCookieInternal(
const std::string& account_id, const std::string& account_id,
const std::string& source) { const std::string& source) {
...@@ -674,6 +679,32 @@ void GaiaCookieManagerService::OnUbertokenFailure( ...@@ -674,6 +679,32 @@ void GaiaCookieManagerService::OnUbertokenFailure(
SignalComplete(account_id, error); SignalComplete(account_id, error);
} }
void GaiaCookieManagerService::OnGetTokenSuccess(
const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) {
DCHECK(requests_.front().request_type() ==
GaiaCookieRequestType::SET_ACCOUNTS);
access_tokens_.insert(std::make_pair(request->GetAccountId(), access_token));
if (access_tokens_.size() == requests_.front().account_ids().size()) {
token_requests_.clear();
signin_client_->DelayNetworkCall(
base::Bind(&GaiaCookieManagerService::SetAccountsInCookieWithTokens,
base::Unretained(this)));
}
}
void GaiaCookieManagerService::OnGetTokenFailure(
const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) {
// TODO (valeriyas): Implement OnMultiloginFailure in this class and call it
// here.
token_requests_.clear();
VLOG(1) << "Failed to retrieve accesstoken"
<< " account=" << request->GetAccountId()
<< " error=" << error.ToString();
}
void GaiaCookieManagerService::OnMergeSessionSuccess(const std::string& data) { void GaiaCookieManagerService::OnMergeSessionSuccess(const std::string& data) {
const std::string account_id = requests_.front().GetAccountID(); const std::string account_id = requests_.front().GetAccountID();
VLOG(1) << "MergeSession successful account=" << account_id; VLOG(1) << "MergeSession successful account=" << account_id;
...@@ -813,8 +844,14 @@ void GaiaCookieManagerService::OnLogOutFailure( ...@@ -813,8 +844,14 @@ void GaiaCookieManagerService::OnLogOutFailure(
} }
void GaiaCookieManagerService::StartFetchingAccesstokens() { void GaiaCookieManagerService::StartFetchingAccesstokens() {
// TODO(valeriyas): Fetch access tokens and call SetAccountInCookiesWithTokens VLOG(1) << "GaiaCookieManagerService::StartFetchingAccesstoken account_id ="
// on success << base::JoinString(requests_.front().account_ids(), " ");
OAuth2TokenService::ScopeSet scopes;
scopes.insert(GaiaConstants::kOAuth1LoginScope);
for (const std::string& account_id : requests_.front().account_ids()) {
token_requests_.push_back(
token_service_->StartRequest(account_id, scopes, this));
}
} }
void GaiaCookieManagerService::StartFetchingUbertoken() { void GaiaCookieManagerService::StartFetchingUbertoken() {
...@@ -894,7 +931,9 @@ void GaiaCookieManagerService::HandleNextRequest() { ...@@ -894,7 +931,9 @@ void GaiaCookieManagerService::HandleNextRequest() {
break; break;
case GaiaCookieRequestType::SET_ACCOUNTS: case GaiaCookieRequestType::SET_ACCOUNTS:
DCHECK(!requests_.front().account_ids().empty()); DCHECK(!requests_.front().account_ids().empty());
// TODO(https://crbug.com/872725): StartFetchingAccessTokens... signin_client_->DelayNetworkCall(
base::Bind(&GaiaCookieManagerService::StartFetchingAccesstokens,
base::Unretained(this)));
break; break;
case GaiaCookieRequestType::LOG_OUT: case GaiaCookieRequestType::LOG_OUT:
DCHECK(requests_.front().account_ids().empty()); DCHECK(requests_.front().account_ids().empty());
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -44,7 +45,8 @@ class SimpleURLLoader; ...@@ -44,7 +45,8 @@ class SimpleURLLoader;
class GaiaCookieManagerService : public KeyedService, class GaiaCookieManagerService : public KeyedService,
public GaiaAuthConsumer, public GaiaAuthConsumer,
public UbertokenConsumer, public UbertokenConsumer,
public network::mojom::CookieChangeListener { public network::mojom::CookieChangeListener,
public OAuth2TokenService::Consumer {
public: public:
enum GaiaCookieRequestType { enum GaiaCookieRequestType {
ADD_ACCOUNT, ADD_ACCOUNT,
...@@ -197,6 +199,10 @@ class GaiaCookieManagerService : public KeyedService, ...@@ -197,6 +199,10 @@ class GaiaCookieManagerService : public KeyedService,
void SetAccountsInCookie(const std::vector<std::string>& account_ids, void SetAccountsInCookie(const std::vector<std::string>& account_ids,
const std::string& source); const std::string& source);
// Takes list of account_ids from the front request, matches them with a
// corresponding stored access_token and calls StartMultilogin.
void SetAccountsInCookieWithTokens();
// Returns if the listed accounts are up to date or not. The out parameter // Returns if the listed accounts are up to date or not. The out parameter
// will be assigned the current cached accounts (whether they are not up to // will be assigned the current cached accounts (whether they are not up to
// date or not). If the accounts are not up to date, a ListAccounts fetch is // date or not). If the accounts are not up to date, a ListAccounts fetch is
...@@ -272,6 +278,13 @@ class GaiaCookieManagerService : public KeyedService, ...@@ -272,6 +278,13 @@ class GaiaCookieManagerService : public KeyedService,
void OnUbertokenSuccess(const std::string& token) override; void OnUbertokenSuccess(const std::string& token) override;
void OnUbertokenFailure(const GoogleServiceAuthError& error) override; void OnUbertokenFailure(const GoogleServiceAuthError& error) override;
// Overridden from OAuth2TokenService::Consumer.
void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) override;
void OnGetTokenFailure(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) override;
// Overridden from GaiaAuthConsumer. // Overridden from GaiaAuthConsumer.
void OnMergeSessionSuccess(const std::string& data) override; void OnMergeSessionSuccess(const std::string& data) override;
void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; void OnMergeSessionFailure(const GoogleServiceAuthError& error) override;
...@@ -324,6 +337,14 @@ class GaiaCookieManagerService : public KeyedService, ...@@ -324,6 +337,14 @@ class GaiaCookieManagerService : public KeyedService,
// The last fetched ubertoken, for use in MergeSession retries. // The last fetched ubertoken, for use in MergeSession retries.
std::string uber_token_; std::string uber_token_;
// Access tokens for use inside SetAccountsToCookie.
// TODO (valeriyas): make FetchUberToken use those instead of a separate
// access_token.
std::unordered_map<std::string, std::string> access_tokens_;
// Current list of processed token requests;
std::vector<std::unique_ptr<OAuth2TokenService::Request>> token_requests_;
// The access token that can be used to prime the UberToken fetch. // The access token that can be used to prime the UberToken fetch.
std::string access_token_; std::string access_token_;
......
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