Commit ded1993e authored by Valeriya Sinevich's avatar Valeriya Sinevich Committed by Commit Bot

Create PerformMultilogin function in AccountReconciler which calls...

Create PerformMultilogin function in AccountReconciler which calls SetAccountsInCookie in GaiaCookieManagerService.

This function will be later called in FinishReconcile() instead of multiple PerformMergeSession. SetAccountsInCookie is implemented in child CLs.

Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I7f8bed2e7ffcad5558c8b70a40301e85650fe50d
Reviewed-on: https://chromium-review.googlesource.com/1169210
Commit-Queue: Valeriya Sinevich <valeriyas@google.com>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582917}
parent f9ae1768
......@@ -286,6 +286,15 @@ void AccountReconcilor::PerformMergeAction(const std::string& account_id) {
delegate_->GetGaiaApiSource());
}
void AccountReconcilor::PerformSetCookiesAction(
const std::vector<std::string>& account_ids) {
reconcile_is_noop_ = false;
VLOG(1) << "AccountReconcilor::PerformSetCookiesAction: "
<< base::JoinString(account_ids, " ");
cookie_manager_service_->SetAccountsInCookie(account_ids,
delegate_->GetGaiaApiSource());
}
void AccountReconcilor::PerformLogoutAllAccountsAction() {
reconcile_is_noop_ = false;
if (!delegate_->IsAccountConsistencyEnforced())
......
......@@ -190,6 +190,8 @@ class AccountReconcilor : public KeyedService,
// consistency is enabled. Virtual so that they can be overridden in tests.
virtual void PerformMergeAction(const std::string& account_id);
virtual void PerformLogoutAllAccountsAction();
virtual void PerformSetCookiesAction(
const std::vector<std::string>& account_ids);
// Used during periodic reconciliation.
void StartReconcile();
......
......@@ -88,6 +88,7 @@ GaiaCookieManagerService::GaiaCookieRequest::~GaiaCookieRequest() {
}
const std::string GaiaCookieManagerService::GaiaCookieRequest::GetAccountID() {
DCHECK_EQ(request_type_, GaiaCookieRequestType::ADD_ACCOUNT);
DCHECK_EQ(1u, account_ids_.size());
return account_ids_[0];
}
......@@ -391,6 +392,27 @@ void GaiaCookieManagerService::Shutdown() {
cookie_change_subscription_.reset();
}
void GaiaCookieManagerService::SetAccountsInCookie(
const std::vector<std::string>& account_ids,
const std::string& source) {
VLOG(1) << "GaiaCookieManagerService::SetAccountsInCookie: "
<< base::JoinString(account_ids, " ");
// TODO(valeriyas): clear access_tokens_ here (introduced in follow-up cls)
if (!signin_client_->AreSigninCookiesAllowed()) {
for (const std::string account_id : account_ids) {
SignalComplete(account_id, GoogleServiceAuthError(
GoogleServiceAuthError::REQUEST_CANCELED));
}
return;
}
requests_.push_back(
GaiaCookieRequest::CreateSetAccountsRequest(account_ids, source));
if (requests_.size() == 1) {
signin_client_->DelayNetworkCall(
base::Bind(&GaiaCookieManagerService::StartFetchingAccesstokens,
base::Unretained(this)));
}
}
void GaiaCookieManagerService::AddAccountToCookieInternal(
const std::string& account_id,
......@@ -791,6 +813,11 @@ void GaiaCookieManagerService::OnLogOutFailure(
HandleNextRequest();
}
void GaiaCookieManagerService::StartFetchingAccesstokens() {
// TODO(valeriyas): Fetch access tokens and call SetAccountInCookiesWithTokens
// on success
}
void GaiaCookieManagerService::StartFetchingUbertoken() {
const std::string account_id = requests_.front().GetAccountID();
VLOG(1) << "GaiaCookieManagerService::StartFetchingUbertoken account_id="
......@@ -861,19 +888,23 @@ void GaiaCookieManagerService::HandleNextRequest() {
} else {
switch (requests_.front().request_type()) {
case GaiaCookieRequestType::ADD_ACCOUNT:
DCHECK_EQ(1u, requests_.front().account_ids().size());
signin_client_->DelayNetworkCall(
base::Bind(&GaiaCookieManagerService::StartFetchingUbertoken,
base::Unretained(this)));
break;
case GaiaCookieRequestType::SET_ACCOUNTS:
DCHECK(!requests_.front().account_ids().empty());
// TODO(https://crbug.com/872725): StartFetchingAccessTokens...
break;
case GaiaCookieRequestType::LOG_OUT:
DCHECK(requests_.front().account_ids().empty());
signin_client_->DelayNetworkCall(
base::Bind(&GaiaCookieManagerService::StartGaiaLogOut,
base::Unretained(this)));
break;
case GaiaCookieRequestType::LIST_ACCOUNTS:
DCHECK(requests_.front().account_ids().empty());
uber_token_fetcher_.reset();
signin_client_->DelayNetworkCall(
base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts,
......
......@@ -59,6 +59,9 @@ class GaiaCookieManagerService : public KeyedService,
GaiaCookieRequestType request_type() const { return request_type_; }
const std::vector<std::string>& account_ids() const { return account_ids_; }
// For use in the Request of type ADD_ACCOUNT which must have exactly one
// account_id in the array. It checks this condition and extracts this one
// account.
const std::string GetAccountID();
const std::string& source() const {return source_; }
......@@ -186,6 +189,12 @@ class GaiaCookieManagerService : public KeyedService,
const std::string& access_token,
const std::string& source);
// Takes list of account_ids and sets the cookie for these accounts regardless
// of the current cookie state. Removes the accounts that are not in
// account_ids and add the missing ones.
void SetAccountsInCookie(const std::vector<std::string>& account_ids,
const std::string& source);
// 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
// date or not). If the accounts are not up to date, a ListAccounts fetch is
......@@ -276,6 +285,11 @@ class GaiaCookieManagerService : public KeyedService,
void AddAccountToCookieInternal(const std::string& account_id,
const std::string& source);
// Starts the process of fetching the access token with OauthLogin scope and
// performing SetAccountsInCookie on success. Virtual so that it can be
// overridden in tests.
virtual void StartFetchingAccesstokens();
// 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();
......
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