Commit 4d63ce68 authored by Tanmoy Mollik's avatar Tanmoy Mollik Committed by Chromium LUCI CQ

Convert components/gcm_driver/* to OnPrimaryAccountChanged()

methods OnPrimaryAccount(Set/Cleared) are deprecated. This cl changes
components/gcm_driver/* code to use OnPrimaryAccountChanged() instead.

This cl also removes OnPrimaryAccountSet method from IdentityManager.

Bug: 1158855
Change-Id: I75210065dd113eeb3646c86136236fe2b54afebf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2611722
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Auto-Submit: Tanmoy Mollik <triploblastic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843499}
parent 511082b4
...@@ -80,26 +80,29 @@ void AccountTracker::OnRefreshTokenRemovedForAccount( ...@@ -80,26 +80,29 @@ void AccountTracker::OnRefreshTokenRemovedForAccount(
UpdateSignInState(account_id, /*is_signed_in=*/false); UpdateSignInState(account_id, /*is_signed_in=*/false);
} }
void AccountTracker::OnPrimaryAccountSet( void AccountTracker::OnPrimaryAccountChanged(
const CoreAccountInfo& primary_account_info) { const signin::PrimaryAccountChangeEvent& event) {
switch (event.GetEventTypeFor(signin::ConsentLevel::kSync)) {
case signin::PrimaryAccountChangeEvent::Type::kSet: {
TRACE_EVENT0("identity", "AccountTracker::OnPrimaryAccountSet"); TRACE_EVENT0("identity", "AccountTracker::OnPrimaryAccountSet");
std::vector<CoreAccountInfo> accounts = std::vector<CoreAccountInfo> accounts =
identity_manager_->GetAccountsWithRefreshTokens(); identity_manager_->GetAccountsWithRefreshTokens();
DVLOG(1) << "LOGIN " << accounts.size() << " accounts available."; DVLOG(1) << "LOGIN " << accounts.size() << " accounts available.";
for (const CoreAccountInfo& account_info : accounts) { for (const CoreAccountInfo& account_info : accounts) {
StartTrackingAccount(account_info); StartTrackingAccount(account_info);
UpdateSignInState(account_info.account_id, /*is_signed_in=*/true); UpdateSignInState(account_info.account_id, /*is_signed_in=*/true);
} }
} break;
}
void AccountTracker::OnPrimaryAccountCleared( case signin::PrimaryAccountChangeEvent::Type::kCleared: {
const CoreAccountInfo& previous_primary_account_info) {
TRACE_EVENT0("identity", "AccountTracker::OnPrimaryAccountCleared"); TRACE_EVENT0("identity", "AccountTracker::OnPrimaryAccountCleared");
DVLOG(1) << "LOGOUT"; DVLOG(1) << "LOGOUT";
StopTrackingAllAccounts(); StopTrackingAllAccounts();
break;
}
case signin::PrimaryAccountChangeEvent::Type::kNone:
break;
}
} }
void AccountTracker::UpdateSignInState(const CoreAccountId& account_id, void AccountTracker::UpdateSignInState(const CoreAccountId& account_id,
......
...@@ -46,10 +46,8 @@ class AccountTracker : public signin::IdentityManager::Observer { ...@@ -46,10 +46,8 @@ class AccountTracker : public signin::IdentityManager::Observer {
}; };
// signin::IdentityManager::Observer implementation. // signin::IdentityManager::Observer implementation.
void OnPrimaryAccountSet( void OnPrimaryAccountChanged(
const CoreAccountInfo& primary_account_info) override; const signin::PrimaryAccountChangeEvent& event) override;
void OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) override;
void OnRefreshTokenUpdatedForAccount( void OnRefreshTokenUpdatedForAccount(
const CoreAccountInfo& account_info) override; const CoreAccountInfo& account_info) override;
void OnRefreshTokenRemovedForAccount( void OnRefreshTokenRemovedForAccount(
......
...@@ -45,12 +45,11 @@ class GCMProfileService::IdentityObserver ...@@ -45,12 +45,11 @@ class GCMProfileService::IdentityObserver
~IdentityObserver() override; ~IdentityObserver() override;
// signin::IdentityManager::Observer: // signin::IdentityManager::Observer:
void OnPrimaryAccountSet( void OnPrimaryAccountChanged(
const CoreAccountInfo& primary_account_info) override; const signin::PrimaryAccountChangeEvent& event) override;
void OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) override;
private: private:
void OnSyncPrimaryAccountSet(const CoreAccountInfo& primary_account_info);
void StartAccountTracker( void StartAccountTracker(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory); scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
...@@ -75,7 +74,7 @@ GCMProfileService::IdentityObserver::IdentityObserver( ...@@ -75,7 +74,7 @@ GCMProfileService::IdentityObserver::IdentityObserver(
: driver_(driver), identity_manager_(identity_manager) { : driver_(driver), identity_manager_(identity_manager) {
identity_manager_->AddObserver(this); identity_manager_->AddObserver(this);
OnPrimaryAccountSet(identity_manager_->GetPrimaryAccountInfo()); OnSyncPrimaryAccountSet(identity_manager_->GetPrimaryAccountInfo());
StartAccountTracker(std::move(url_loader_factory)); StartAccountTracker(std::move(url_loader_factory));
} }
...@@ -85,7 +84,24 @@ GCMProfileService::IdentityObserver::~IdentityObserver() { ...@@ -85,7 +84,24 @@ GCMProfileService::IdentityObserver::~IdentityObserver() {
identity_manager_->RemoveObserver(this); identity_manager_->RemoveObserver(this);
} }
void GCMProfileService::IdentityObserver::OnPrimaryAccountSet( void GCMProfileService::IdentityObserver::OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event) {
switch (event.GetEventTypeFor(signin::ConsentLevel::kSync)) {
case signin::PrimaryAccountChangeEvent::Type::kSet:
OnSyncPrimaryAccountSet(event.GetCurrentState().primary_account);
break;
case signin::PrimaryAccountChangeEvent::Type::kCleared:
account_id_ = CoreAccountId();
// Still need to notify GCMDriver for UMA purpose.
driver_->OnSignedOut();
break;
case signin::PrimaryAccountChangeEvent::Type::kNone:
break;
}
}
void GCMProfileService::IdentityObserver::OnSyncPrimaryAccountSet(
const CoreAccountInfo& primary_account_info) { const CoreAccountInfo& primary_account_info) {
// This might be called multiple times when the password changes. // This might be called multiple times when the password changes.
if (primary_account_info.account_id == account_id_) if (primary_account_info.account_id == account_id_)
...@@ -96,14 +112,6 @@ void GCMProfileService::IdentityObserver::OnPrimaryAccountSet( ...@@ -96,14 +112,6 @@ void GCMProfileService::IdentityObserver::OnPrimaryAccountSet(
driver_->OnSignedIn(); driver_->OnSignedIn();
} }
void GCMProfileService::IdentityObserver::OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) {
account_id_ = CoreAccountId();
// Still need to notify GCMDriver for UMA purpose.
driver_->OnSignedOut();
}
void GCMProfileService::IdentityObserver::StartAccountTracker( void GCMProfileService::IdentityObserver::StartAccountTracker(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) {
if (gcm_account_tracker_) if (gcm_account_tracker_)
......
...@@ -482,7 +482,6 @@ void IdentityManager::OnPrimaryAccountChanged( ...@@ -482,7 +482,6 @@ void IdentityManager::OnPrimaryAccountChanged(
// are converted to OnPrimaryAccountChanged(). // are converted to OnPrimaryAccountChanged().
switch (event_details.GetEventTypeFor(ConsentLevel::kSync)) { switch (event_details.GetEventTypeFor(ConsentLevel::kSync)) {
case PrimaryAccountChangeEvent::Type::kSet: case PrimaryAccountChangeEvent::Type::kSet:
FirePrimaryAccountSet(event_details);
break; break;
case PrimaryAccountChangeEvent::Type::kCleared: case PrimaryAccountChangeEvent::Type::kCleared:
FirePrimaryAccountCleared(event_details); FirePrimaryAccountCleared(event_details);
...@@ -511,15 +510,6 @@ void IdentityManager::OnPrimaryAccountChanged( ...@@ -511,15 +510,6 @@ void IdentityManager::OnPrimaryAccountChanged(
} }
} }
void IdentityManager::FirePrimaryAccountSet(
const PrimaryAccountChangeEvent& event_details) {
const CoreAccountInfo& account_info =
event_details.GetCurrentState().primary_account;
for (auto& observer : observer_list_) {
observer.OnPrimaryAccountSet(account_info);
}
}
void IdentityManager::FirePrimaryAccountCleared( void IdentityManager::FirePrimaryAccountCleared(
const PrimaryAccountChangeEvent& event_details) { const PrimaryAccountChangeEvent& event_details) {
const CoreAccountInfo& account_info = const CoreAccountInfo& account_info =
......
...@@ -80,12 +80,6 @@ class IdentityManager : public KeyedService, ...@@ -80,12 +80,6 @@ class IdentityManager : public KeyedService,
virtual void OnPrimaryAccountChanged( virtual void OnPrimaryAccountChanged(
const PrimaryAccountChangeEvent& event_details) {} const PrimaryAccountChangeEvent& event_details) {}
// Called when an account becomes the user's primary account.
// This method is not called during a reauth.
// DEPRECATED: Use OnPrimaryAccountChanged() instead.
virtual void OnPrimaryAccountSet(
const CoreAccountInfo& primary_account_info) {}
// Called when the user moves from having a primary account to no longer // Called when the user moves from having a primary account to no longer
// having a primary account (note that the user may still have an // having a primary account (note that the user may still have an
// *unconsented* primary account after this event; see./README.md). // *unconsented* primary account after this event; see./README.md).
......
...@@ -140,8 +140,7 @@ class ProfileSyncServiceStartupTest : public testing::Test { ...@@ -140,8 +140,7 @@ class ProfileSyncServiceStartupTest : public testing::Test {
std::unique_ptr<ProfileSyncService> sync_service_; std::unique_ptr<ProfileSyncService> sync_service_;
}; };
// ChromeOS does not support sign-in after startup (in particular, // ChromeOS does not support sign-in after startup
// IdentityManager::Observer::OnPrimaryAccountSet never gets called).
#if !BUILDFLAG(IS_CHROMEOS_ASH) #if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
// We've never completed startup. // We've never completed startup.
...@@ -566,8 +565,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) { ...@@ -566,8 +565,7 @@ TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) {
sync_service()->GetTransportState()); sync_service()->GetTransportState());
} }
// ChromeOS does not support sign-in after startup (in particular, // ChromeOS does not support sign-in after startup
// IdentityManager::Observer::OnPrimaryAccountSet never gets called).
#if !BUILDFLAG(IS_CHROMEOS_ASH) #if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ProfileSyncServiceStartupTest, FullStartupSequenceFirstTime) { TEST_F(ProfileSyncServiceStartupTest, FullStartupSequenceFirstTime) {
// We've never completed startup. // We've never completed startup.
......
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