Commit 0a3600c1 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Reland "Sync: Use IdentityManager instead of SigninManager"

This reverts commit fd8a3a1f.

Reason for revert: The depended-on CL has been relanded as https://crrev.com/c/1030451

Original change's description:
> Revert "Sync: Use IdentityManager instead of SigninManager"
> 
> This reverts commit aab57914.
> 
> Reason for revert: Depends on crrev.com/c/1025898 which was reverted
> 
> Original change's description:
> > Sync: Use IdentityManager instead of SigninManager
> > 
> > This CL migrates ProfileSyncService to IdentityManager for getting
> > info on the primary account. This includes switching from
> > SigninManagerBase::Observer to IdentityManager::Observer.
> > The only remaining use of SigninManager within PSS it to call
> > SignOut() which isn't exposed by IdentityManager yet.
> > 
> > Bug: 825190
> > Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
> > Change-Id: Icf9398d63794cab03cb559adba5c767e18c31c0a
> > Reviewed-on: https://chromium-review.googlesource.com/983914
> > Commit-Queue: Marc Treib <treib@chromium.org>
> > Reviewed-by: Mikel Astiz <mastiz@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#553973}
> 
> TBR=blundell@chromium.org,treib@chromium.org,mastiz@chromium.org
> 
> Change-Id: Ib40dbff0f1c8e5fba95cb9881681361abec5aeec
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 825190, 837201
> Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
> Reviewed-on: https://chromium-review.googlesource.com/1030372
> Reviewed-by: Marc Treib <treib@chromium.org>
> Commit-Queue: Marc Treib <treib@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#553997}

TBR=blundell@chromium.org,treib@chromium.org,mastiz@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 825190, 837201
Change-Id: If6858f033ac8390acfc904379afbf9726a6301c2
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Reviewed-on: https://chromium-review.googlesource.com/1043885Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556026}
parent 75912714
...@@ -176,9 +176,7 @@ bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes, ...@@ -176,9 +176,7 @@ bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes,
IdentityManagerFactory::GetForProfile(profile_); IdentityManagerFactory::GetForProfile(profile_);
identity_manager->SetPrimaryAccountSynchronouslyForTests( identity_manager->SetPrimaryAccountSynchronouslyForTests(
gaia_id_, username_, GenerateFakeOAuth2RefreshTokenString()); gaia_id_, username_, GenerateFakeOAuth2RefreshTokenString());
std::string account_id = service()->OnPrimaryAccountSet(identity_manager->GetPrimaryAccountInfo());
identity_manager->GetPrimaryAccountInfo().account_id;
service()->GoogleSigninSucceeded(account_id, username_);
} else { } else {
LOG(ERROR) << "Unsupported profile signin type."; LOG(ERROR) << "Unsupported profile signin type.";
} }
...@@ -284,8 +282,7 @@ bool ProfileSyncServiceHarness::StartSyncService() { ...@@ -284,8 +282,7 @@ bool ProfileSyncServiceHarness::StartSyncService() {
void ProfileSyncServiceHarness::SignoutSyncService() { void ProfileSyncServiceHarness::SignoutSyncService() {
DCHECK(!username_.empty()); DCHECK(!username_.empty());
service()->GoogleSignedOut( service()->OnPrimaryAccountCleared(service()->GetAuthenticatedAccountInfo());
service()->GetAuthenticatedAccountInfo().account_id, username_);
} }
bool ProfileSyncServiceHarness::HasUnsyncedItems() { bool ProfileSyncServiceHarness::HasUnsyncedItems() {
......
...@@ -345,13 +345,13 @@ void ProfileSyncService::RegisterAuthNotifications() { ...@@ -345,13 +345,13 @@ void ProfileSyncService::RegisterAuthNotifications() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
oauth2_token_service_->AddObserver(this); oauth2_token_service_->AddObserver(this);
if (signin_) if (signin_)
signin_->GetSigninManager()->AddObserver(this); signin_->GetIdentityManager()->AddObserver(this);
} }
void ProfileSyncService::UnregisterAuthNotifications() { void ProfileSyncService::UnregisterAuthNotifications() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (signin_) if (signin_)
signin_->GetSigninManager()->RemoveObserver(this); signin_->GetIdentityManager()->RemoveObserver(this);
if (oauth2_token_service_) if (oauth2_token_service_)
oauth2_token_service_->RemoveObserver(this); oauth2_token_service_->RemoveObserver(this);
} }
...@@ -1921,8 +1921,8 @@ void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { ...@@ -1921,8 +1921,8 @@ void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
} }
} }
void ProfileSyncService::GoogleSigninSucceeded(const std::string& account_id, void ProfileSyncService::OnPrimaryAccountSet(
const std::string& username) { const AccountInfo& primary_account_info) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (!IsEngineInitialized() || if (!IsEngineInitialized() ||
GetAuthError().state() != GoogleServiceAuthError::NONE) { GetAuthError().state() != GoogleServiceAuthError::NONE) {
...@@ -1930,12 +1930,14 @@ void ProfileSyncService::GoogleSigninSucceeded(const std::string& account_id, ...@@ -1930,12 +1930,14 @@ void ProfileSyncService::GoogleSigninSucceeded(const std::string& account_id,
is_auth_in_progress_ = true; is_auth_in_progress_ = true;
} }
if (oauth2_token_service_->RefreshTokenIsAvailable(account_id)) if (oauth2_token_service_->RefreshTokenIsAvailable(
OnRefreshTokenAvailable(account_id); primary_account_info.account_id)) {
OnRefreshTokenAvailable(primary_account_info.account_id);
}
} }
void ProfileSyncService::GoogleSignedOut(const std::string& account_id, void ProfileSyncService::OnPrimaryAccountCleared(
const std::string& username) { const AccountInfo& previous_primary_account_info) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
sync_disabled_by_admin_ = false; sync_disabled_by_admin_ = false;
UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", syncer::SIGN_OUT, UMA_HISTOGRAM_ENUMERATION("Sync.StopSource", syncer::SIGN_OUT,
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/signin/core/browser/gaia_cookie_manager_service.h" #include "components/signin/core/browser/gaia_cookie_manager_service.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "components/sync/base/experiments.h" #include "components/sync/base/experiments.h"
#include "components/sync/base/model_type.h" #include "components/sync/base/model_type.h"
#include "components/sync/base/sync_prefs.h" #include "components/sync/base/sync_prefs.h"
...@@ -44,6 +43,7 @@ ...@@ -44,6 +43,7 @@
#include "google_apis/gaia/google_service_auth_error.h" #include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_token_service.h" #include "google_apis/gaia/oauth2_token_service.h"
#include "net/base/backoff_entry.h" #include "net/base/backoff_entry.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "url/gurl.h" #include "url/gurl.h"
class ProfileOAuth2TokenService; class ProfileOAuth2TokenService;
...@@ -168,7 +168,7 @@ class ProfileSyncService : public syncer::SyncServiceBase, ...@@ -168,7 +168,7 @@ class ProfileSyncService : public syncer::SyncServiceBase,
public syncer::DataTypeManagerObserver, public syncer::DataTypeManagerObserver,
public syncer::UnrecoverableErrorHandler, public syncer::UnrecoverableErrorHandler,
public OAuth2TokenService::Observer, public OAuth2TokenService::Observer,
public SigninManagerBase::Observer, public identity::IdentityManager::Observer,
public GaiaCookieManagerService::Observer { public GaiaCookieManagerService::Observer {
public: public:
using Status = syncer::SyncStatus; using Status = syncer::SyncStatus;
...@@ -381,11 +381,10 @@ class ProfileSyncService : public syncer::SyncServiceBase, ...@@ -381,11 +381,10 @@ class ProfileSyncService : public syncer::SyncServiceBase,
bool IsPassphraseRequired() const override; bool IsPassphraseRequired() const override;
syncer::ModelTypeSet GetEncryptedDataTypes() const override; syncer::ModelTypeSet GetEncryptedDataTypes() const override;
// SigninManagerBase::Observer implementation. // identity::IdentityManager::Observer implementation.
void GoogleSigninSucceeded(const std::string& account_id, void OnPrimaryAccountSet(const AccountInfo& primary_account_info) override;
const std::string& username) override; void OnPrimaryAccountCleared(
void GoogleSignedOut(const std::string& account_id, const AccountInfo& previous_primary_account_info) override;
const std::string& username) override;
// GaiaCookieManagerService::Observer implementation. // GaiaCookieManagerService::Observer implementation.
void OnGaiaAccountsInCookieUpdated( void OnGaiaAccountsInCookieUpdated(
......
...@@ -560,6 +560,8 @@ TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) { ...@@ -560,6 +560,8 @@ TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) {
signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST, signin_manager()->SignOut(signin_metrics::SIGNOUT_TEST,
signin_metrics::SignoutDelete::IGNORE_METRIC); signin_metrics::SignoutDelete::IGNORE_METRIC);
// Wait for PSS to be notified that the primary account has gone away.
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(service()->IsSyncActive()); EXPECT_FALSE(service()->IsSyncActive());
} }
#endif // !defined(OS_CHROMEOS) #endif // !defined(OS_CHROMEOS)
...@@ -727,8 +729,8 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) { ...@@ -727,8 +729,8 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) {
std::string primary_account_id = std::string primary_account_id =
signin_manager()->GetAuthenticatedAccountId(); signin_manager()->GetAuthenticatedAccountId();
auth_service()->LoadCredentials(primary_account_id); auth_service()->LoadCredentials(primary_account_id);
// Wait for PSS to be notified of the loaded credentials and send an access // Wait for ProfileSyncService to be notified of the loaded credentials and
// token request. // send an access token request.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
auth_service()->IssueAllTokensForAccount(primary_account_id, "access token", auth_service()->IssueAllTokensForAccount(primary_account_id, "access token",
base::Time::Max()); base::Time::Max());
...@@ -738,7 +740,7 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) { ...@@ -738,7 +740,7 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorReturned) {
// Emulate Chrome receiving a new, invalid LST. This happens when the user // Emulate Chrome receiving a new, invalid LST. This happens when the user
// signs out of the content area. // signs out of the content area.
auth_service()->UpdateCredentials(primary_account_id, "not a valid token"); auth_service()->UpdateCredentials(primary_account_id, "not a valid token");
// Again, wait for PSS to be notified. // Again, wait for ProfileSyncService to be notified.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
auth_service()->IssueErrorForAllPendingRequests( auth_service()->IssueErrorForAllPendingRequests(
GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
...@@ -772,8 +774,8 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) { ...@@ -772,8 +774,8 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) {
std::string primary_account_id = std::string primary_account_id =
signin_manager()->GetAuthenticatedAccountId(); signin_manager()->GetAuthenticatedAccountId();
auth_service()->LoadCredentials(primary_account_id); auth_service()->LoadCredentials(primary_account_id);
// Wait for PSS to be notified of the loaded credentials and send an access // Wait for ProfileSyncService to be notified of the loaded credentials and
// token request. // send an access token request.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
auth_service()->IssueAllTokensForAccount(primary_account_id, "access token", auth_service()->IssueAllTokensForAccount(primary_account_id, "access token",
base::Time::Max()); base::Time::Max());
...@@ -783,8 +785,8 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) { ...@@ -783,8 +785,8 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) {
// Emulate Chrome receiving a new, invalid LST. This happens when the user // Emulate Chrome receiving a new, invalid LST. This happens when the user
// signs out of the content area. // signs out of the content area.
auth_service()->UpdateCredentials(primary_account_id, "not a valid token"); auth_service()->UpdateCredentials(primary_account_id, "not a valid token");
// Wait for PSS to be notified of the changed credentials and send a new // Wait for ProfileSyncService to be notified of the changed credentials and
// access token request. // send a new access token request.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
auth_service()->IssueErrorForAllPendingRequests( auth_service()->IssueErrorForAllPendingRequests(
GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
...@@ -795,7 +797,7 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) { ...@@ -795,7 +797,7 @@ TEST_F(ProfileSyncServiceTest, CredentialErrorClearsOnNewToken) {
// Now emulate Chrome receiving a new, valid LST. // Now emulate Chrome receiving a new, valid LST.
auth_service()->UpdateCredentials(primary_account_id, "totally valid token"); auth_service()->UpdateCredentials(primary_account_id, "totally valid token");
// Again, wait for PSS to be notified. // Again, wait for ProfileSyncService to be notified.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
auth_service()->IssueTokenForAllPendingRequests( auth_service()->IssueTokenForAllPendingRequests(
"this one works", base::Time::Now() + base::TimeDelta::FromDays(10)); "this one works", base::Time::Now() + base::TimeDelta::FromDays(10));
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "components/sync/driver/signin_manager_wrapper.h" #include "components/sync/driver/signin_manager_wrapper.h"
#include "components/signin/core/browser/signin_manager_base.h" #include "services/identity/public/cpp/identity_manager.h"
SigninManagerWrapper::SigninManagerWrapper( SigninManagerWrapper::SigninManagerWrapper(
identity::IdentityManager* identity_manager, identity::IdentityManager* identity_manager,
...@@ -22,9 +22,9 @@ SigninManagerBase* SigninManagerWrapper::GetSigninManager() { ...@@ -22,9 +22,9 @@ SigninManagerBase* SigninManagerWrapper::GetSigninManager() {
} }
std::string SigninManagerWrapper::GetEffectiveUsername() const { std::string SigninManagerWrapper::GetEffectiveUsername() const {
return signin_manager_->GetAuthenticatedAccountInfo().email; return identity_manager_->GetPrimaryAccountInfo().email;
} }
std::string SigninManagerWrapper::GetAccountIdToUse() const { std::string SigninManagerWrapper::GetAccountIdToUse() const {
return signin_manager_->GetAuthenticatedAccountId(); return identity_manager_->GetPrimaryAccountInfo().account_id;
} }
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
#include "base/syslog_logging.h" #include "base/syslog_logging.h"
#include "components/invalidation/public/invalidation_service.h" #include "components/invalidation/public/invalidation_service.h"
#include "components/signin/core/browser/account_info.h" #include "components/signin/core/browser/account_info.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "components/sync/base/report_unrecoverable_error.h" #include "components/sync/base/report_unrecoverable_error.h"
#include "components/sync/device_info/local_device_info_provider.h" #include "components/sync/device_info/local_device_info_provider.h"
#include "components/sync/driver/sync_driver_switches.h" #include "components/sync/driver/sync_driver_switches.h"
#include "components/sync/engine/engine_components_factory_impl.h" #include "components/sync/engine/engine_components_factory_impl.h"
#include "components/sync/engine/polling_constants.h" #include "components/sync/engine/polling_constants.h"
#include "services/identity/public/cpp/identity_manager.h"
namespace syncer { namespace syncer {
...@@ -86,7 +86,7 @@ bool SyncServiceBase::HasObserver(const SyncServiceObserver* observer) const { ...@@ -86,7 +86,7 @@ bool SyncServiceBase::HasObserver(const SyncServiceObserver* observer) const {
AccountInfo SyncServiceBase::GetAuthenticatedAccountInfo() const { AccountInfo SyncServiceBase::GetAuthenticatedAccountInfo() const {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
return signin_ ? signin_->GetSigninManager()->GetAuthenticatedAccountInfo() return signin_ ? signin_->GetIdentityManager()->GetPrimaryAccountInfo()
: AccountInfo(); : AccountInfo();
} }
......
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