Commit 228afd48 authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

[b4p] Add counter/incrementer of # of times the move bubble is refused

This CL introduces a per Gaia-account pref that keeps track of how many
times a non-opted-in user has refused or ignored the bubble to move a
password to the account. The pref is cleared when the user opts in.

Bug: 1082152
Change-Id: I5b99f872ce30a86b65afd083c5a7f0e2285049f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340966
Commit-Queue: Victor Vianna <victorvianna@google.com>
Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796319}
parent 561352a1
...@@ -72,6 +72,8 @@ PasswordForm::Store PasswordStoreFromInt(int value) { ...@@ -72,6 +72,8 @@ PasswordForm::Store PasswordStoreFromInt(int value) {
const char kAccountStorageOptedInKey[] = "opted_in"; const char kAccountStorageOptedInKey[] = "opted_in";
const char kAccountStorageDefaultStoreKey[] = "default_store"; const char kAccountStorageDefaultStoreKey[] = "default_store";
const char kMoveToAccountStoreRefusedCountKey[] =
"move_to_account_store_refused_count";
// Returns the total number of accounts for which an opt-in to the account // Returns the total number of accounts for which an opt-in to the account
// storage exists. Used for metrics. // storage exists. Used for metrics.
...@@ -115,6 +117,13 @@ class AccountStorageSettingsReader { ...@@ -115,6 +117,13 @@ class AccountStorageSettingsReader {
return PasswordStoreFromInt(*value); return PasswordStoreFromInt(*value);
} }
int GetMoveToAccountRefusedCount() const {
if (!account_settings_)
return 0;
return account_settings_->FindIntKey(kMoveToAccountStoreRefusedCountKey)
.value_or(0);
}
private: private:
// May be null, if no settings for this account were saved yet. // May be null, if no settings for this account were saved yet.
const base::Value* account_settings_ = nullptr; const base::Value* account_settings_ = nullptr;
...@@ -142,6 +151,8 @@ class ScopedAccountStorageSettingsUpdate { ...@@ -142,6 +151,8 @@ class ScopedAccountStorageSettingsUpdate {
void SetOptedIn() { void SetOptedIn() {
base::Value* account_settings = GetOrCreateAccountSettings(); base::Value* account_settings = GetOrCreateAccountSettings();
// The count of refusals is only tracked when the user is not opted-in.
account_settings->RemoveKey(kMoveToAccountStoreRefusedCountKey);
account_settings->SetBoolKey(kAccountStorageOptedInKey, true); account_settings->SetBoolKey(kAccountStorageOptedInKey, true);
} }
...@@ -151,6 +162,13 @@ class ScopedAccountStorageSettingsUpdate { ...@@ -151,6 +162,13 @@ class ScopedAccountStorageSettingsUpdate {
static_cast<int>(default_store)); static_cast<int>(default_store));
} }
void IncrementMovePasswordToAccountBubble() {
base::Value* account_settings = GetOrCreateAccountSettings();
int count = account_settings->FindIntKey(kMoveToAccountStoreRefusedCountKey)
.value_or(0);
account_settings->SetIntKey(kMoveToAccountStoreRefusedCountKey, ++count);
}
void ClearAllSettings() { update_->RemoveKey(account_hash_); } void ClearAllSettings() { update_->RemoveKey(account_hash_); }
private: private:
...@@ -432,5 +450,32 @@ PasswordAccountStorageUsageLevel ComputePasswordAccountStorageUsageLevel( ...@@ -432,5 +450,32 @@ PasswordAccountStorageUsageLevel ComputePasswordAccountStorageUsageLevel(
} }
} }
void IncrementMoveToAccountRefusedCount(
PrefService* pref_service,
const syncer::SyncService* sync_service) {
DCHECK(pref_service);
DCHECK(sync_service);
std::string gaia_id = sync_service->GetAuthenticatedAccountInfo().gaia;
DCHECK(!gaia_id.empty());
DCHECK(!AccountStorageSettingsReader(pref_service,
GaiaIdHash::FromGaiaId(gaia_id))
.IsOptedIn());
ScopedAccountStorageSettingsUpdate(pref_service,
GaiaIdHash::FromGaiaId(gaia_id))
.IncrementMovePasswordToAccountBubble();
}
int GetMoveToAccountRefusedCount(const PrefService* pref_service,
const syncer::SyncService* sync_service) {
DCHECK(pref_service);
DCHECK(sync_service);
std::string gaia_id = sync_service->GetAuthenticatedAccountInfo().gaia;
DCHECK(!gaia_id.empty());
AccountStorageSettingsReader reader(pref_service,
GaiaIdHash::FromGaiaId(gaia_id));
DCHECK(!reader.IsOptedIn());
return reader.GetMoveToAccountRefusedCount();
}
} // namespace features_util } // namespace features_util
} // namespace password_manager } // namespace password_manager
...@@ -128,6 +128,23 @@ ComputePasswordAccountStorageUsageLevel( ...@@ -128,6 +128,23 @@ ComputePasswordAccountStorageUsageLevel(
const PrefService* pref_service, const PrefService* pref_service,
const syncer::SyncService* sync_service); const syncer::SyncService* sync_service);
// Increases the count of how many times Chrome automatically offered to move a
// password to the account and the user refused this, e.g. by ignoring the
// bubble that's shown after successful sign-in with a device password. Should
// only be called if the user is signed-in and not opted-in. |pref_service| and
// |sync_service| should be non-null.
void IncrementMoveToAccountRefusedCount(
PrefService* pref_service,
const syncer::SyncService* sync_service);
// Gets the count of how many times Chrome automatically offered to move a
// password to the account and the user refused this, e.g. by ignoring the
// bubble that's shown after successful sign-in with a device password. Should
// only be called if the user is signed-in and not opted-in. |pref_service| and
// |sync_service| should be non-null.
int GetMoveToAccountRefusedCount(const PrefService* pref_service,
const syncer::SyncService* sync_service);
} // namespace features_util } // namespace features_util
} // namespace password_manager } // namespace password_manager
......
...@@ -506,5 +506,28 @@ TEST(PasswordFeatureManagerUtil, OptInOutHistograms) { ...@@ -506,5 +506,28 @@ TEST(PasswordFeatureManagerUtil, OptInOutHistograms) {
"PasswordManager.AccountStorage.ClearedOptInForAllAccounts", 1, 1); "PasswordManager.AccountStorage.ClearedOptInForAllAccounts", 1, 1);
} }
TEST(PasswordFeatureManagerUtil, MovePasswordToAccountStoreRefusedCount) {
// Set up a user signed-in, not syncing and not opted-in.
base::test::ScopedFeatureList features;
features.InitAndEnableFeature(features::kEnablePasswordsAccountStorage);
TestingPrefServiceSimple pref_service;
pref_service.registry()->RegisterDictionaryPref(
prefs::kAccountStoragePerAccountSettings);
CoreAccountInfo account;
account.email = "name@account.com";
account.gaia = "name";
account.account_id = CoreAccountId::FromGaiaId(account.gaia);
syncer::TestSyncService sync_service;
sync_service.SetAuthenticatedAccountInfo(account);
sync_service.SetIsAuthenticatedAccountPrimary(false);
ASSERT_FALSE(IsOptedInForAccountStorage(&pref_service, &sync_service));
EXPECT_EQ(0, GetMoveToAccountRefusedCount(&pref_service, &sync_service));
IncrementMoveToAccountRefusedCount(&pref_service, &sync_service);
EXPECT_EQ(1, GetMoveToAccountRefusedCount(&pref_service, &sync_service));
IncrementMoveToAccountRefusedCount(&pref_service, &sync_service);
EXPECT_EQ(2, GetMoveToAccountRefusedCount(&pref_service, &sync_service));
}
} // namespace features_util } // namespace features_util
} // namespace password_manager } // namespace password_manager
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