Commit b2db1d43 authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

cros: Do not reuse GaiaOAuthClient for different tokens

GaiaOAuthClient does not support concurrent requests. So when focusing
different pods user selection screen might try to check several tokens
at the same time.

Fixed: 1085612
Change-Id: I017dee8944db0e82194626c9b0abeefe65d335ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2213536Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772189}
parent e87a42bc
......@@ -28,10 +28,7 @@ constexpr int kMaxRetries = 3;
TokenHandleUtil::TokenHandleUtil() {}
TokenHandleUtil::~TokenHandleUtil() {
weak_factory_.InvalidateWeakPtrs();
gaia_client_.reset();
}
TokenHandleUtil::~TokenHandleUtil() {}
// static
bool TokenHandleUtil::HasToken(const AccountId& account_id) {
......@@ -93,16 +90,10 @@ void TokenHandleUtil::CheckToken(
return;
}
if (!gaia_client_.get()) {
gaia_client_.reset(
new gaia::GaiaOAuthClient(std::move(url_loader_factory)));
}
validation_delegates_[token] =
std::unique_ptr<TokenDelegate>(new TokenDelegate(
weak_factory_.GetWeakPtr(), account_id, token, callback));
gaia_client_->GetTokenHandleInfo(token, kMaxRetries,
validation_delegates_[token].get());
// Constructor starts validation.
validation_delegates_[token] = std::make_unique<TokenDelegate>(
weak_factory_.GetWeakPtr(), account_id, token,
std::move(url_loader_factory), callback);
}
// static
......@@ -121,12 +112,16 @@ TokenHandleUtil::TokenDelegate::TokenDelegate(
const base::WeakPtr<TokenHandleUtil>& owner,
const AccountId& account_id,
const std::string& token,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const TokenValidationCallback& callback)
: owner_(owner),
account_id_(account_id),
token_(token),
tokeninfo_response_start_time_(base::TimeTicks::Now()),
callback_(callback) {}
callback_(callback),
gaia_client_(std::move(url_loader_factory)) {
gaia_client_.GetTokenHandleInfo(token_, kMaxRetries, this);
}
TokenHandleUtil::TokenDelegate::~TokenDelegate() {}
......
......@@ -63,11 +63,14 @@ class TokenHandleUtil {
// Associates GaiaOAuthClient::Delegate with User ID and Token.
class TokenDelegate : public gaia::GaiaOAuthClient::Delegate {
public:
TokenDelegate(const base::WeakPtr<TokenHandleUtil>& owner,
const AccountId& account_id,
const std::string& token,
const TokenValidationCallback& callback);
TokenDelegate(
const base::WeakPtr<TokenHandleUtil>& owner,
const AccountId& account_id,
const std::string& token,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const TokenValidationCallback& callback);
~TokenDelegate() override;
void OnOAuthError() override;
void OnNetworkError(int response_code) override;
void OnGetTokenInfoResponse(
......@@ -80,6 +83,7 @@ class TokenHandleUtil {
std::string token_;
base::TimeTicks tokeninfo_response_start_time_;
TokenValidationCallback callback_;
gaia::GaiaOAuthClient gaia_client_;
DISALLOW_COPY_AND_ASSIGN(TokenDelegate);
};
......@@ -90,9 +94,6 @@ class TokenHandleUtil {
std::unordered_map<std::string, std::unique_ptr<TokenDelegate>>
validation_delegates_;
// Instance of GAIA Client.
std::unique_ptr<gaia::GaiaOAuthClient> gaia_client_;
base::WeakPtrFactory<TokenHandleUtil> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(TokenHandleUtil);
......
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