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

Cleanup: Get rid of ProfileSyncService::waiting_for_auth()

Its semantics were a bit weird: It got set on initial sign-in (i.e. not
during a Chrome restart), and cleared again once we updated the auth
error state: Either to an error, if we failed to get an access token or
got an error from the sync server, or to "no error", if we successfully
connected to the sync server.
It had only a single call site, which only used it to suppress auth
errors while waiting_for_auth was true. However, according to the
above, that's an impossible state: Sync can not be in an auth error
state *before* being signed in, and the waiting_for_auth bit is cleared
when actually entering an auth error state.

Bug: 839834
Change-Id: Iefbf54a93ede54aabb2a244b3e429b5591bb9934
Reviewed-on: https://chromium-review.googlesource.com/1099162Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567250}
parent 9311dc38
...@@ -57,9 +57,8 @@ SyncStartupTracker::SyncServiceState SyncStartupTracker::GetSyncServiceState( ...@@ -57,9 +57,8 @@ SyncStartupTracker::SyncServiceState SyncStartupTracker::GetSyncServiceState(
ProfileSyncServiceFactory::GetForProfile(profile); ProfileSyncServiceFactory::GetForProfile(profile);
// If no service exists or it can't be started, treat as a startup error. // If no service exists or it can't be started, treat as a startup error.
if (!service || !service->CanSyncStart()) { if (!service || !service->CanSyncStart())
return SYNC_STARTUP_ERROR; return SYNC_STARTUP_ERROR;
}
// If the sync engine has started up, notify the callback. // If the sync engine has started up, notify the callback.
if (service->IsEngineInitialized()) if (service->IsEngineInitialized())
...@@ -69,12 +68,9 @@ SyncStartupTracker::SyncServiceState SyncStartupTracker::GetSyncServiceState( ...@@ -69,12 +68,9 @@ SyncStartupTracker::SyncServiceState SyncStartupTracker::GetSyncServiceState(
if (service->HasUnrecoverableError()) if (service->HasUnrecoverableError())
return SYNC_STARTUP_ERROR; return SYNC_STARTUP_ERROR;
// If we have an auth error and sync is not still waiting for new auth tokens // If we have an auth error, exit.
// to be fetched, exit. if (service->GetAuthError().state() != GoogleServiceAuthError::NONE)
if (!service->waiting_for_auth() &&
service->GetAuthError().state() != GoogleServiceAuthError::NONE) {
return SYNC_STARTUP_ERROR; return SYNC_STARTUP_ERROR;
}
// No error detected yet, but the sync engine hasn't started up yet, so // No error detected yet, but the sync engine hasn't started up yet, so
// we're in the pending state. // we're in the pending state.
......
...@@ -37,11 +37,13 @@ ...@@ -37,11 +37,13 @@
#include "components/signin/core/browser/signin_metrics.h" #include "components/signin/core/browser/signin_metrics.h"
#include "components/signin/core/browser/signin_pref_names.h" #include "components/signin/core/browser/signin_pref_names.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using ::testing::AtLeast; using ::testing::AtLeast;
using ::testing::Return; using ::testing::Return;
using ::testing::ReturnRef;
class DiceTurnSyncOnHelperTest; class DiceTurnSyncOnHelperTest;
...@@ -245,27 +247,20 @@ class DiceTurnSyncOnHelperTest : public testing::Test { ...@@ -245,27 +247,20 @@ class DiceTurnSyncOnHelperTest : public testing::Test {
browser_sync::ProfileSyncServiceMock* sync_service_mock = browser_sync::ProfileSyncServiceMock* sync_service_mock =
GetProfileSyncServiceMock(); GetProfileSyncServiceMock();
EXPECT_CALL(*sync_service_mock, GetSetupInProgressHandle()).Times(1); EXPECT_CALL(*sync_service_mock, GetSetupInProgressHandle()).Times(1);
EXPECT_CALL(*sync_service_mock, CanSyncStart()) ON_CALL(*sync_service_mock, CanSyncStart()).WillByDefault(Return(true));
.Times(AtLeast(0)) ON_CALL(*sync_service_mock, IsEngineInitialized())
.WillRepeatedly(Return(true)); .WillByDefault(Return(true));
EXPECT_CALL(*sync_service_mock, IsEngineInitialized())
.Times(AtLeast(0))
.WillRepeatedly(Return(true));
} }
void SetExpectationsForSyncStartupPending() { void SetExpectationsForSyncStartupPending() {
browser_sync::ProfileSyncServiceMock* sync_service_mock = browser_sync::ProfileSyncServiceMock* sync_service_mock =
GetProfileSyncServiceMock(); GetProfileSyncServiceMock();
EXPECT_CALL(*sync_service_mock, GetSetupInProgressHandle()).Times(1); EXPECT_CALL(*sync_service_mock, GetSetupInProgressHandle()).Times(1);
EXPECT_CALL(*sync_service_mock, CanSyncStart()) ON_CALL(*sync_service_mock, CanSyncStart()).WillByDefault(Return(true));
.Times(AtLeast(0)) ON_CALL(*sync_service_mock, IsEngineInitialized())
.WillRepeatedly(Return(true)); .WillByDefault(Return(false));
EXPECT_CALL(*sync_service_mock, IsEngineInitialized()) ON_CALL(*sync_service_mock, GetAuthError())
.Times(AtLeast(0)) .WillByDefault(ReturnRef(kNoAuthError));
.WillRepeatedly(Return(false));
EXPECT_CALL(*sync_service_mock, waiting_for_auth())
.Times(AtLeast(0))
.WillRepeatedly(Return(true));
} }
void CheckDelegateCalls() { void CheckDelegateCalls() {
...@@ -388,6 +383,10 @@ class DiceTurnSyncOnHelperTest : public testing::Test { ...@@ -388,6 +383,10 @@ class DiceTurnSyncOnHelperTest : public testing::Test {
std::string new_profile_username_; std::string new_profile_username_;
bool sync_confirmation_shown_ = false; bool sync_confirmation_shown_ = false;
bool sync_settings_shown_ = false; bool sync_settings_shown_ = false;
// Note: This needs to be a member variable for testing::ReturnRef.
const GoogleServiceAuthError kNoAuthError =
GoogleServiceAuthError::AuthErrorNone();
}; };
// TestDiceTurnSyncOnHelperDelegate implementation. // TestDiceTurnSyncOnHelperDelegate implementation.
......
...@@ -1307,11 +1307,6 @@ bool ProfileSyncService::ConfigurationDone() const { ...@@ -1307,11 +1307,6 @@ bool ProfileSyncService::ConfigurationDone() const {
data_type_manager_->state() == DataTypeManager::CONFIGURED; data_type_manager_->state() == DataTypeManager::CONFIGURED;
} }
bool ProfileSyncService::waiting_for_auth() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return auth_manager_->IsAuthInProgress();
}
bool ProfileSyncService::HasUnrecoverableError() const { bool ProfileSyncService::HasUnrecoverableError() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return unrecoverable_error_reason_ != ERROR_REASON_UNSET; return unrecoverable_error_reason_ != ERROR_REASON_UNSET;
......
...@@ -476,13 +476,6 @@ class ProfileSyncService : public syncer::SyncService, ...@@ -476,13 +476,6 @@ class ProfileSyncService : public syncer::SyncService,
// TODO(sync): This is only used in tests. Can we remove it? // TODO(sync): This is only used in tests. Can we remove it?
const syncer::DataTypeStatusTable& data_type_status_table() const; const syncer::DataTypeStatusTable& data_type_status_table() const;
// If true, the ProfileSyncService has detected that a new GAIA signin has
// succeeded, and is waiting for initialization to complete. This is used by
// the UI to differentiate between a new auth error (encountered as part of
// the initialization process) and a pre-existing auth error that just hasn't
// been cleared yet. Virtual for testing purposes.
virtual bool waiting_for_auth() const;
// KeyedService implementation. This must be called exactly // KeyedService implementation. This must be called exactly
// once (before this object is destroyed). // once (before this object is destroyed).
void Shutdown() override; void Shutdown() override;
......
...@@ -81,7 +81,6 @@ class ProfileSyncServiceMock : public ProfileSyncService { ...@@ -81,7 +81,6 @@ class ProfileSyncServiceMock : public ProfileSyncService {
MOCK_CONST_METHOD0(IsEngineInitialized, bool()); MOCK_CONST_METHOD0(IsEngineInitialized, bool());
MOCK_CONST_METHOD0(IsSyncRequested, bool()); MOCK_CONST_METHOD0(IsSyncRequested, bool());
MOCK_CONST_METHOD0(IsSyncConfirmationNeeded, bool()); MOCK_CONST_METHOD0(IsSyncConfirmationNeeded, bool());
MOCK_CONST_METHOD0(waiting_for_auth, bool());
MOCK_METHOD1(OnActionableError, void(const syncer::SyncProtocolError&)); MOCK_METHOD1(OnActionableError, void(const syncer::SyncProtocolError&));
MOCK_CONST_METHOD1(IsDataTypeControllerRunning, bool(syncer::ModelType)); MOCK_CONST_METHOD1(IsDataTypeControllerRunning, bool(syncer::ModelType));
......
...@@ -60,7 +60,6 @@ SyncAuthManager::SyncAuthManager( ...@@ -60,7 +60,6 @@ SyncAuthManager::SyncAuthManager(
account_state_changed_callback_(account_state_changed), account_state_changed_callback_(account_state_changed),
credentials_changed_callback_(credentials_changed), credentials_changed_callback_(credentials_changed),
registered_for_auth_notifications_(false), registered_for_auth_notifications_(false),
is_auth_in_progress_(false),
request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
DCHECK(sync_prefs_); DCHECK(sync_prefs_);
...@@ -169,7 +168,6 @@ void SyncAuthManager::ConnectionStatusChanged(syncer::ConnectionStatus status) { ...@@ -169,7 +168,6 @@ void SyncAuthManager::ConnectionStatusChanged(syncer::ConnectionStatus status) {
void SyncAuthManager::UpdateAuthErrorState( void SyncAuthManager::UpdateAuthErrorState(
const GoogleServiceAuthError& error) { const GoogleServiceAuthError& error) {
is_auth_in_progress_ = false;
last_auth_error_ = error; last_auth_error_ = error;
} }
...@@ -192,10 +190,6 @@ void SyncAuthManager::Clear() { ...@@ -192,10 +190,6 @@ void SyncAuthManager::Clear() {
void SyncAuthManager::OnPrimaryAccountSet( void SyncAuthManager::OnPrimaryAccountSet(
const AccountInfo& primary_account_info) { const AccountInfo& primary_account_info) {
// Track the fact that we're still waiting for auth to complete.
DCHECK(!is_auth_in_progress_);
is_auth_in_progress_ = true;
account_state_changed_callback_.Run(); account_state_changed_callback_.Run();
} }
...@@ -203,7 +197,6 @@ void SyncAuthManager::OnPrimaryAccountCleared( ...@@ -203,7 +197,6 @@ void SyncAuthManager::OnPrimaryAccountCleared(
const AccountInfo& previous_primary_account_info) { const AccountInfo& previous_primary_account_info) {
UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", syncer::SIGN_OUT, UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", syncer::SIGN_OUT,
syncer::STOP_SOURCE_LIMIT); syncer::STOP_SOURCE_LIMIT);
is_auth_in_progress_ = false;
account_state_changed_callback_.Run(); account_state_changed_callback_.Run();
} }
......
...@@ -62,7 +62,6 @@ class SyncAuthManager : public identity::IdentityManager::Observer { ...@@ -62,7 +62,6 @@ class SyncAuthManager : public identity::IdentityManager::Observer {
const GoogleServiceAuthError& GetLastAuthError() const { const GoogleServiceAuthError& GetLastAuthError() const {
return last_auth_error_; return last_auth_error_;
} }
bool IsAuthInProgress() const { return is_auth_in_progress_; }
// Returns the credentials to be passed to the SyncEngine. // Returns the credentials to be passed to the SyncEngine.
syncer::SyncCredentials GetCredentials() const; syncer::SyncCredentials GetCredentials() const;
...@@ -117,10 +116,6 @@ class SyncAuthManager : public identity::IdentityManager::Observer { ...@@ -117,10 +116,6 @@ class SyncAuthManager : public identity::IdentityManager::Observer {
// from the sync server or from Chrome's identity/token management system. // from the sync server or from Chrome's identity/token management system.
GoogleServiceAuthError last_auth_error_; GoogleServiceAuthError last_auth_error_;
// Set to true if a signin has completed but we're still waiting for the
// engine to refresh its credentials.
bool is_auth_in_progress_;
// 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_|:
// We either have an access token OR a pending request OR a pending retry. // We either have an access token OR a pending request OR a pending retry.
......
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