Commit 29bdbadd authored by Owen Min's avatar Owen Min Committed by Commit Bot

Handle case that network status returned asynchronously in ForceSigninVerifier.

When the GetConnectionType returns asynchronously, verification request is never
sent because the default network type is CONNECTION_NONE and there is no network
change notification later either.

Resolves the issue by handling the callback from the API.

Also
1) Separate network check from others so that we don't fetch network type again
   when we know it.
2) Rewrite the unittest to use more fake services instead of stun value. It
   increase the code coverage. Including SigninManager, ProfileOAuth2TokenService
   and TestNetworkConnectionTracker.

Bug: 891817
Change-Id: Iebdc5bbc30e699b347d6a343bb6f4c979fbe1596
Reviewed-on: https://chromium-review.googlesource.com/c/1259542Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Owen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597560}
parent 75d0995f
......@@ -92,8 +92,7 @@ void ForceSigninVerifier::OnConnectionChanged(
if (backoff_request_timer_.IsRunning())
backoff_request_timer_.Stop();
if (type != network::mojom::ConnectionType::CONNECTION_NONE)
SendRequest();
SendRequestIfNetworkAvailable(type);
}
void ForceSigninVerifier::Cancel() {
......@@ -108,8 +107,21 @@ bool ForceSigninVerifier::HasTokenBeenVerified() {
}
void ForceSigninVerifier::SendRequest() {
if (!ShouldSendRequest())
auto type = network::mojom::ConnectionType::CONNECTION_NONE;
if (content::GetNetworkConnectionTracker()->GetConnectionType(
&type,
base::BindOnce(&ForceSigninVerifier::SendRequestIfNetworkAvailable,
base::Unretained(this)))) {
SendRequestIfNetworkAvailable(type);
}
}
void ForceSigninVerifier::SendRequestIfNetworkAvailable(
network::mojom::ConnectionType network_type) {
if (network_type == network::mojom::ConnectionType::CONNECTION_NONE ||
!ShouldSendRequest()) {
return;
}
std::string account_id = signin_manager_->GetAuthenticatedAccountId();
OAuth2TokenService::ScopeSet oauth2_scopes;
......@@ -119,11 +131,7 @@ void ForceSigninVerifier::SendRequest() {
}
bool ForceSigninVerifier::ShouldSendRequest() {
auto type = network::mojom::ConnectionType::CONNECTION_NONE;
content::GetNetworkConnectionTracker()->GetConnectionType(&type,
base::DoNothing());
return !has_token_verified_ && access_token_request_.get() == nullptr &&
type != network::mojom::ConnectionType::CONNECTION_NONE &&
signin_manager_->IsAuthenticated();
}
......
......@@ -57,7 +57,12 @@ class ForceSigninVerifier
//
void SendRequest();
virtual bool ShouldSendRequest();
// Send the request if |network_type| is not CONNECTION_NONE and
// ShouldSendRequest returns true.
void SendRequestIfNetworkAvailable(
network::mojom::ConnectionType network_type);
bool ShouldSendRequest();
virtual void CloseAllBrowserWindows();
......
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