Commit aa091f2d authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

On chrome://sync-internals, also show the time when an auth error was set

In some past investigations, it might have been useful to know since
when an auth error state has existed.

Bug: 948074
Change-Id: I4220dbea552725cd0d75b35e563e292f7d5eea12
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1557027Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649054}
parent 096ea836
...@@ -331,7 +331,6 @@ std::unique_ptr<base::DictionaryValue> ConstructAboutInformation( ...@@ -331,7 +331,6 @@ std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
Stat<std::string>* username = section_identity->AddStringStat("Username"); Stat<std::string>* username = section_identity->AddStringStat("Username");
Stat<bool>* user_is_primary = section_identity->AddBoolStat("Is Primary"); Stat<bool>* user_is_primary = section_identity->AddBoolStat("Is Primary");
Stat<std::string>* auth_error = section_identity->AddStringStat("Auth Error"); Stat<std::string>* auth_error = section_identity->AddStringStat("Auth Error");
// TODO(crbug.com/948074): Add the time of the auth error.
Section* section_credentials = section_list.AddSection("Credentials"); Section* section_credentials = section_list.AddSection("Credentials");
Stat<std::string>* request_token_time = Stat<std::string>* request_token_time =
...@@ -471,7 +470,9 @@ std::unique_ptr<base::DictionaryValue> ConstructAboutInformation( ...@@ -471,7 +470,9 @@ std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
username->Set(service->GetAuthenticatedAccountInfo().email); username->Set(service->GetAuthenticatedAccountInfo().email);
user_is_primary->Set(service->IsAuthenticatedAccountPrimary()); user_is_primary->Set(service->IsAuthenticatedAccountPrimary());
std::string auth_error_str = service->GetAuthError().ToString(); std::string auth_error_str = service->GetAuthError().ToString();
auth_error->Set(auth_error_str.empty() ? "None" : auth_error_str); auth_error->Set(base::StringPrintf(
"%s since %s", (auth_error_str.empty() ? "OK" : auth_error_str).c_str(),
GetTimeStr(service->GetAuthErrorTime(), "browser startup").c_str()));
// Credentials. // Credentials.
request_token_time->Set(GetTimeStr(token_status.token_request_time, "n/a")); request_token_time->Set(GetTimeStr(token_status.token_request_time, "n/a"));
......
...@@ -90,6 +90,10 @@ GoogleServiceAuthError FakeSyncService::GetAuthError() const { ...@@ -90,6 +90,10 @@ GoogleServiceAuthError FakeSyncService::GetAuthError() const {
return GoogleServiceAuthError(); return GoogleServiceAuthError();
} }
base::Time FakeSyncService::GetAuthErrorTime() const {
return base::Time();
}
bool FakeSyncService::RequiresClientUpgrade() const { bool FakeSyncService::RequiresClientUpgrade() const {
return false; return false;
} }
......
...@@ -45,6 +45,7 @@ class FakeSyncService : public SyncService { ...@@ -45,6 +45,7 @@ class FakeSyncService : public SyncService {
override; override;
bool IsSetupInProgress() const override; bool IsSetupInProgress() const override;
GoogleServiceAuthError GetAuthError() const override; GoogleServiceAuthError GetAuthError() const override;
base::Time GetAuthErrorTime() const override;
bool RequiresClientUpgrade() const override; bool RequiresClientUpgrade() const override;
UserShare* GetUserShare() const override; UserShare* GetUserShare() const override;
void ReenableDatatype(ModelType type) override; void ReenableDatatype(ModelType type) override;
......
...@@ -38,6 +38,7 @@ class MockSyncService : public SyncService { ...@@ -38,6 +38,7 @@ class MockSyncService : public SyncService {
MOCK_CONST_METHOD0(GetAuthenticatedAccountInfo, CoreAccountInfo()); MOCK_CONST_METHOD0(GetAuthenticatedAccountInfo, CoreAccountInfo());
MOCK_CONST_METHOD0(IsAuthenticatedAccountPrimary, bool()); MOCK_CONST_METHOD0(IsAuthenticatedAccountPrimary, bool());
MOCK_CONST_METHOD0(GetAuthError, GoogleServiceAuthError()); MOCK_CONST_METHOD0(GetAuthError, GoogleServiceAuthError());
MOCK_CONST_METHOD0(GetAuthErrorTime, base::Time());
MOCK_CONST_METHOD0(RequiresClientUpgrade, bool()); MOCK_CONST_METHOD0(RequiresClientUpgrade, bool());
MOCK_METHOD0(GetSetupInProgressHandle, MOCK_METHOD0(GetSetupInProgressHandle,
......
...@@ -1165,6 +1165,11 @@ GoogleServiceAuthError ProfileSyncService::GetAuthError() const { ...@@ -1165,6 +1165,11 @@ GoogleServiceAuthError ProfileSyncService::GetAuthError() const {
return auth_manager_->GetLastAuthError(); return auth_manager_->GetLastAuthError();
} }
base::Time ProfileSyncService::GetAuthErrorTime() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return auth_manager_->GetLastAuthErrorTime();
}
bool ProfileSyncService::RequiresClientUpgrade() const { bool ProfileSyncService::RequiresClientUpgrade() const {
return last_actionable_error_.action == UPGRADE_CLIENT; return last_actionable_error_.action == UPGRADE_CLIENT;
} }
......
...@@ -120,6 +120,7 @@ class ProfileSyncService : public SyncService, ...@@ -120,6 +120,7 @@ class ProfileSyncService : public SyncService,
CoreAccountInfo GetAuthenticatedAccountInfo() const override; CoreAccountInfo GetAuthenticatedAccountInfo() const override;
bool IsAuthenticatedAccountPrimary() const override; bool IsAuthenticatedAccountPrimary() const override;
GoogleServiceAuthError GetAuthError() const override; GoogleServiceAuthError GetAuthError() const override;
base::Time GetAuthErrorTime() const override;
bool RequiresClientUpgrade() const override; bool RequiresClientUpgrade() const override;
std::unique_ptr<SyncSetupInProgressHandle> GetSetupInProgressHandle() std::unique_ptr<SyncSetupInProgressHandle> GetSetupInProgressHandle()
override; override;
......
...@@ -104,6 +104,15 @@ GoogleServiceAuthError SyncAuthManager::GetLastAuthError() const { ...@@ -104,6 +104,15 @@ GoogleServiceAuthError SyncAuthManager::GetLastAuthError() const {
return last_auth_error_; return last_auth_error_;
} }
base::Time SyncAuthManager::GetLastAuthErrorTime() const {
// See GetLastAuthError().
if (partial_token_status_.connection_status ==
syncer::CONNECTION_SERVER_ERROR) {
return partial_token_status_.connection_status_update_time;
}
return last_auth_error_time_;
}
bool SyncAuthManager::IsSyncPaused() const { bool SyncAuthManager::IsSyncPaused() const {
return IsWebSignout(GetLastAuthError()); return IsWebSignout(GetLastAuthError());
} }
...@@ -281,7 +290,7 @@ void SyncAuthManager::OnRefreshTokenUpdatedForAccount( ...@@ -281,7 +290,7 @@ void SyncAuthManager::OnRefreshTokenUpdatedForAccount(
// that's not going to happen in this case. // that's not going to happen in this case.
// TODO(blundell): Long-term, it would be nicer if Sync didn't have to // TODO(blundell): Long-term, it would be nicer if Sync didn't have to
// cache signin-level authentication errors. // cache signin-level authentication errors.
last_auth_error_ = token_error; SetLastAuthError(token_error);
credentials_changed_callback_.Run(); credentials_changed_callback_.Run();
return; return;
...@@ -322,8 +331,8 @@ void SyncAuthManager::OnRefreshTokenRemovedForAccount( ...@@ -322,8 +331,8 @@ void SyncAuthManager::OnRefreshTokenRemovedForAccount(
// TODO(crbug.com/839834): REQUEST_CANCELED doesn't seem like the right auth // TODO(crbug.com/839834): REQUEST_CANCELED doesn't seem like the right auth
// error to use here. Maybe INVALID_GAIA_CREDENTIALS? // error to use here. Maybe INVALID_GAIA_CREDENTIALS?
last_auth_error_ = SetLastAuthError(
GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED));
ClearAccessTokenAndRequest(); ClearAccessTokenAndRequest();
credentials_changed_callback_.Run(); credentials_changed_callback_.Run();
...@@ -369,7 +378,7 @@ bool SyncAuthManager::UpdateSyncAccountIfNecessary() { ...@@ -369,7 +378,7 @@ bool SyncAuthManager::UpdateSyncAccountIfNecessary() {
// Also clear any pending request or auth errors we might have, since they // Also clear any pending request or auth errors we might have, since they
// aren't meaningful anymore. // aren't meaningful anymore.
ConnectionClosed(); ConnectionClosed();
last_auth_error_ = GoogleServiceAuthError::AuthErrorNone(); SetLastAuthError(GoogleServiceAuthError::AuthErrorNone());
account_state_changed_callback_.Run(); account_state_changed_callback_.Run();
} }
...@@ -429,7 +438,7 @@ void SyncAuthManager::AccessTokenFetched( ...@@ -429,7 +438,7 @@ void SyncAuthManager::AccessTokenFetched(
switch (error.state()) { switch (error.state()) {
case GoogleServiceAuthError::NONE: case GoogleServiceAuthError::NONE:
partial_token_status_.token_receive_time = base::Time::Now(); partial_token_status_.token_receive_time = base::Time::Now();
last_auth_error_ = GoogleServiceAuthError::AuthErrorNone(); SetLastAuthError(GoogleServiceAuthError::AuthErrorNone());
break; break;
case GoogleServiceAuthError::CONNECTION_FAILED: case GoogleServiceAuthError::CONNECTION_FAILED:
case GoogleServiceAuthError::REQUEST_CANCELED: case GoogleServiceAuthError::REQUEST_CANCELED:
...@@ -443,14 +452,22 @@ void SyncAuthManager::AccessTokenFetched( ...@@ -443,14 +452,22 @@ void SyncAuthManager::AccessTokenFetched(
ScheduleAccessTokenRequest(); ScheduleAccessTokenRequest();
break; break;
case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS:
last_auth_error_ = error; SetLastAuthError(error);
break; break;
default: default:
LOG(ERROR) << "Unexpected persistent error: " << error.ToString(); DLOG(ERROR) << "Unexpected persistent error: " << error.ToString();
last_auth_error_ = error; SetLastAuthError(error);
} }
credentials_changed_callback_.Run(); credentials_changed_callback_.Run();
} }
void SyncAuthManager::SetLastAuthError(const GoogleServiceAuthError& error) {
if (last_auth_error_ == error) {
return;
}
last_auth_error_ = error;
last_auth_error_time_ = base::Time::Now();
}
} // namespace syncer } // namespace syncer
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "components/signin/core/browser/account_info.h" #include "components/signin/core/browser/account_info.h"
#include "components/sync/driver/sync_auth_util.h" #include "components/sync/driver/sync_auth_util.h"
...@@ -66,6 +67,9 @@ class SyncAuthManager : public identity::IdentityManager::Observer { ...@@ -66,6 +67,9 @@ class SyncAuthManager : public identity::IdentityManager::Observer {
// from the Sync server or from the IdentityManager. // from the Sync server or from the IdentityManager.
GoogleServiceAuthError GetLastAuthError() const; GoogleServiceAuthError GetLastAuthError() const;
// Returns the time at which the last auth error was set.
base::Time GetLastAuthErrorTime() const;
// Returns whether we are in the "Sync paused" state. That means there is a // Returns whether we are in the "Sync paused" state. That means there is a
// primary account, but the user signed out in the content area, and so we // primary account, but the user signed out in the content area, and so we
// don't have credentials for it anymore. // don't have credentials for it anymore.
...@@ -134,9 +138,12 @@ class SyncAuthManager : public identity::IdentityManager::Observer { ...@@ -134,9 +138,12 @@ class SyncAuthManager : public identity::IdentityManager::Observer {
// we currently have is invalidated. // we currently have is invalidated.
void RequestAccessToken(); void RequestAccessToken();
// Callback for |ongoing_access_token_fetch_|.
void AccessTokenFetched(GoogleServiceAuthError error, void AccessTokenFetched(GoogleServiceAuthError error,
identity::AccessTokenInfo access_token_info); identity::AccessTokenInfo access_token_info);
void SetLastAuthError(const GoogleServiceAuthError& error);
identity::IdentityManager* const identity_manager_; identity::IdentityManager* const identity_manager_;
const AccountStateChangedCallback account_state_changed_callback_; const AccountStateChangedCallback account_state_changed_callback_;
...@@ -152,6 +159,7 @@ class SyncAuthManager : public identity::IdentityManager::Observer { ...@@ -152,6 +159,7 @@ class SyncAuthManager : public identity::IdentityManager::Observer {
// This is a cache of the last authentication response we received from // This is a cache of the last authentication response we received from
// Chrome's identity/token management system. // Chrome's identity/token management system.
GoogleServiceAuthError last_auth_error_; GoogleServiceAuthError last_auth_error_;
base::Time last_auth_error_time_;
// The current access token. This is mutually exclusive with // The current access token. This is mutually exclusive with
// |ongoing_access_token_fetch_| and |request_access_token_retry_timer_|: // |ongoing_access_token_fetch_| and |request_access_token_retry_timer_|:
......
...@@ -226,6 +226,7 @@ class SyncService : public KeyedService { ...@@ -226,6 +226,7 @@ class SyncService : public KeyedService {
// an access token), or from the Sync server. It gets cleared when the error // an access token), or from the Sync server. It gets cleared when the error
// is resolved. // is resolved.
virtual GoogleServiceAuthError GetAuthError() const = 0; virtual GoogleServiceAuthError GetAuthError() const = 0;
virtual base::Time GetAuthErrorTime() const = 0;
// Returns true if the Chrome client is too old and needs to be updated for // Returns true if the Chrome client is too old and needs to be updated for
// Sync to work. // Sync to work.
......
...@@ -149,6 +149,10 @@ GoogleServiceAuthError TestSyncService::GetAuthError() const { ...@@ -149,6 +149,10 @@ GoogleServiceAuthError TestSyncService::GetAuthError() const {
return auth_error_; return auth_error_;
} }
base::Time TestSyncService::GetAuthErrorTime() const {
return base::Time();
}
bool TestSyncService::RequiresClientUpgrade() const { bool TestSyncService::RequiresClientUpgrade() const {
return detailed_sync_status_.sync_protocol_error.action == return detailed_sync_status_.sync_protocol_error.action ==
syncer::UPGRADE_CLIENT; syncer::UPGRADE_CLIENT;
......
...@@ -58,6 +58,7 @@ class TestSyncService : public SyncService { ...@@ -58,6 +58,7 @@ class TestSyncService : public SyncService {
CoreAccountInfo GetAuthenticatedAccountInfo() const override; CoreAccountInfo GetAuthenticatedAccountInfo() const override;
bool IsAuthenticatedAccountPrimary() const override; bool IsAuthenticatedAccountPrimary() const override;
GoogleServiceAuthError GetAuthError() const override; GoogleServiceAuthError GetAuthError() const override;
base::Time GetAuthErrorTime() const override;
bool RequiresClientUpgrade() const override; bool RequiresClientUpgrade() const override;
std::unique_ptr<SyncSetupInProgressHandle> GetSetupInProgressHandle() std::unique_ptr<SyncSetupInProgressHandle> GetSetupInProgressHandle()
......
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