Commit 76be69b8 authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Chromium LUCI CQ

Convert ios/chrome/* code to OnPrimaryAccountChanged()

Methods OnPrimaryAccountSet/Cleared are deprecated. This CL changes
these calls to OnPrimaryAccountChanged().

As on iOS, the user cannot be signed with a primary account at
ConsentLevel::kNotRequired (on iOS, setting a primary account requires
the user to go through the sync consent), the migration is defensive
and DCHECKs that the OnPrimaryAccountChanged() are always fired for
primary account changes at sync level.

Bug: 1158855

Change-Id: I071545f01f2a984a365d563997997873d75fd86d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2617881
Auto-Submit: Mihai Sardarescu <msarda@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842020}
parent 78ea2c1b
......@@ -42,10 +42,8 @@ class CredentialProviderService
void Shutdown() override;
// IdentityManager::Observer.
void OnPrimaryAccountSet(
const CoreAccountInfo& primary_account_info) override;
void OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) override;
void OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event) override;
private:
// Request all the credentials to sync them. Before adding the fresh ones,
......
......@@ -267,13 +267,13 @@ void CredentialProviderService::OnGetPasswordStoreResults(
}
}
void CredentialProviderService::OnPrimaryAccountSet(
const CoreAccountInfo& primary_account_info) {
RequestSyncAllCredentials();
}
void CredentialProviderService::OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event) {
DCHECK_NE(signin::PrimaryAccountChangeEvent::Type::kNone,
event.GetEventTypeFor(signin::ConsentLevel::kSync))
<< "ConsentLevel::kNotRequired is not yet supported on iOS. This code "
"needs to be updated when it is supported.";
void CredentialProviderService::OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) {
RequestSyncAllCredentials();
}
......
......@@ -5,6 +5,7 @@
#include "ios/chrome/browser/credential_provider/credential_provider_service.h"
#include "base/files/scoped_temp_dir.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "components/password_manager/core/browser/password_form.h"
......@@ -172,7 +173,15 @@ TEST_F(CredentialProviderServiceTest, AccountChange) {
ASSERT_TRUE(auth_service_->GetAuthenticatedIdentity());
ASSERT_TRUE(auth_service_->IsAuthenticatedIdentityManaged());
credential_provider_service_->OnPrimaryAccountSet(CoreAccountInfo());
CoreAccountInfo account = CoreAccountInfo();
account.email = base::SysNSStringToUTF8(identity.userEmail);
account.gaia = base::SysNSStringToUTF8(identity.gaiaID);
credential_provider_service_->OnPrimaryAccountChanged(
signin::PrimaryAccountChangeEvent(
signin::PrimaryAccountChangeEvent::State(
CoreAccountInfo(), signin::ConsentLevel::kNotRequired),
signin::PrimaryAccountChangeEvent::State(
account, signin::ConsentLevel::kSync)));
ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForFileOperationTimeout, ^{
base::RunLoop().RunUntilIdle();
......@@ -183,7 +192,13 @@ TEST_F(CredentialProviderServiceTest, AccountChange) {
auth_service_->SignOut(signin_metrics::SIGNOUT_TEST,
/*force_clear_browsing_data=*/false, nil);
credential_provider_service_->OnPrimaryAccountCleared(CoreAccountInfo());
credential_provider_service_->OnPrimaryAccountChanged(
signin::PrimaryAccountChangeEvent(
signin::PrimaryAccountChangeEvent::State(account,
signin::ConsentLevel::kSync),
signin::PrimaryAccountChangeEvent::State(
CoreAccountInfo(), signin::ConsentLevel::kNotRequired)));
ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForFileOperationTimeout, ^{
base::RunLoop().RunUntilIdle();
......
......@@ -30,10 +30,8 @@ class DiscoverFeedService : public KeyedService,
private:
// IdentityManager::Observer.
void OnPrimaryAccountSet(
const CoreAccountInfo& primary_account_info) override;
void OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) override;
void OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event) override;
// Identity manager to observe.
signin::IdentityManager* identity_manager_;
......
......@@ -46,12 +46,11 @@ void DiscoverFeedService::Shutdown() {
}
}
void DiscoverFeedService::OnPrimaryAccountSet(
const CoreAccountInfo& primary_account_info) {
discover_feed_provider_->UpdateFeedForAccountChange();
}
void DiscoverFeedService::OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) {
void DiscoverFeedService::OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event) {
DCHECK_NE(signin::PrimaryAccountChangeEvent::Type::kNone,
event.GetEventTypeFor(signin::ConsentLevel::kSync))
<< "ConsentLevel::kNotRequired is not yet supported on iOS. This code "
"needs to be updated when it is supported.";
discover_feed_provider_->UpdateFeedForAccountChange();
}
......@@ -36,10 +36,8 @@ class SigninBrowserStateInfoUpdater : public KeyedService,
void OnErrorChanged() override;
// IdentityManager::Observer:
void OnPrimaryAccountSet(
const CoreAccountInfo& primary_account_info) override;
void OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) override;
void OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event) override;
signin::IdentityManager* identity_manager_ = nullptr;
SigninErrorController* signin_error_controller_ = nullptr;
......
......@@ -77,12 +77,11 @@ void SigninBrowserStateInfoUpdater::OnErrorChanged() {
index, signin_error_controller_->HasError());
}
void SigninBrowserStateInfoUpdater::OnPrimaryAccountSet(
const CoreAccountInfo& primary_account_info) {
UpdateBrowserStateInfo();
}
void SigninBrowserStateInfoUpdater::OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) {
void SigninBrowserStateInfoUpdater::OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event) {
DCHECK_NE(signin::PrimaryAccountChangeEvent::Type::kNone,
event.GetEventTypeFor(signin::ConsentLevel::kSync))
<< "ConsentLevel::kNotRequired is not yet supported on iOS. This code "
"needs to be updated when it is supported.";
UpdateBrowserStateInfo();
}
......@@ -35,8 +35,8 @@ class SyncedSessionsObserverBridge : public signin::IdentityManager::Observer {
ChromeBrowserState* browserState);
~SyncedSessionsObserverBridge() override;
// signin::IdentityManager::Observer implementation.
void OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) override;
void OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event) override;
// Returns true if user is signed in.
bool IsSignedIn();
......
......@@ -41,9 +41,20 @@ SyncedSessionsObserverBridge::~SyncedSessionsObserverBridge() {}
#pragma mark - signin::IdentityManager::Observer
void SyncedSessionsObserverBridge::OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) {
[owner_ reloadSessions];
void SyncedSessionsObserverBridge::OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event) {
switch (event.GetEventTypeFor(signin::ConsentLevel::kSync)) {
case signin::PrimaryAccountChangeEvent::Type::kSet:
// Ignored.
break;
case signin::PrimaryAccountChangeEvent::Type::kCleared:
[owner_ reloadSessions];
break;
case signin::PrimaryAccountChangeEvent::Type::kNone:
NOTREACHED() << "ConsentLevel::kNotRequired is not yet supported on iOS. "
"This code needs to be updated when it is supported.";
break;
}
}
#pragma mark - Signin and syncing status
......
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