Chromium Code Reviews| Index: components/autofill/core/browser/autofill_manager.cc |
| diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc |
| index 04650708eb405ab020c84a21e309541af5932329..45bc868b8bbceebd0a3ff27f6e31bd648e6eca89 100644 |
| --- a/components/autofill/core/browser/autofill_manager.cc |
| +++ b/components/autofill/core/browser/autofill_manager.cc |
| @@ -222,6 +222,10 @@ AutofillManager::~AutofillManager() {} |
| // static |
| void AutofillManager::RegisterProfilePrefs( |
| user_prefs::PrefRegistrySyncable* registry) { |
| + // This pref is not synced because it's for a signin promo, which by |
| + // definition will not be synced. |
| + registry->RegisterIntegerPref( |
| + prefs::kAutofillCreditCardSigninPromoImpressionCount, 0); |
| registry->RegisterBooleanPref( |
| prefs::kAutofillEnabled, |
| true, |
| @@ -275,11 +279,30 @@ bool AutofillManager::ShouldShowScanCreditCard(const FormData& form, |
| bool AutofillManager::ShouldShowCreditCardSigninPromo( |
| const FormData& form, |
| const FormFieldData& field) { |
| + if (!IsAutofillCreditCardSigninPromoEnabled()) |
| + return false; |
| + |
| // Check whether we are dealing with a credit card field and whether it's |
| // appropriate to show the promo (e.g. the platform is supported). |
| AutofillField* autofill_field = GetAutofillField(form, field); |
| - return autofill_field && autofill_field->Type().group() == CREDIT_CARD && |
| - client_->ShouldShowSigninPromo(); |
| + if (!autofill_field || autofill_field->Type().group() != CREDIT_CARD || |
| + !client_->ShouldShowSigninPromo()) |
| + return false; |
| + |
| + // The last step is checking if we are under the limit of impressions (a limit |
| + // of 0 means there is no limit); |
| + int impression_limit = GetCreditCardSigninPromoImpressionLimit(); |
| + int impression_count = client_->GetPrefs()->GetInteger( |
| + prefs::kAutofillCreditCardSigninPromoImpressionCount); |
| + if (impression_limit == 0 || impression_count < impression_limit) { |
| + // The promo is guaranteed to be shown. Increment the impression count. |
|
sebsg
2016/07/14 15:32:13
Nit: I'm not sure about the phrasing. From what I
Mathieu
2016/07/14 21:51:44
Done.
|
| + client_->GetPrefs()->SetInteger( |
| + prefs::kAutofillCreditCardSigninPromoImpressionCount, |
| + impression_count + 1); |
| + return true; |
| + } |
| + |
| + return false; |
| } |
| void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, |