Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Side by Side Diff: components/autofill/core/browser/autofill_manager.cc

Issue 2146823003: Autofill Credit Card Signin Promo: Put behind Feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initial Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 download_manager_.reset(new AutofillDownloadManager(driver, this)); 215 download_manager_.reset(new AutofillDownloadManager(driver, this));
216 } 216 }
217 CountryNames::SetLocaleString(app_locale_); 217 CountryNames::SetLocaleString(app_locale_);
218 } 218 }
219 219
220 AutofillManager::~AutofillManager() {} 220 AutofillManager::~AutofillManager() {}
221 221
222 // static 222 // static
223 void AutofillManager::RegisterProfilePrefs( 223 void AutofillManager::RegisterProfilePrefs(
224 user_prefs::PrefRegistrySyncable* registry) { 224 user_prefs::PrefRegistrySyncable* registry) {
225 // This pref is not synced because it's for a signin promo, which by
226 // definition will not be synced.
227 registry->RegisterIntegerPref(
228 prefs::kAutofillCreditCardSigninPromoImpressionCount, 0);
225 registry->RegisterBooleanPref( 229 registry->RegisterBooleanPref(
226 prefs::kAutofillEnabled, 230 prefs::kAutofillEnabled,
227 true, 231 true,
228 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 232 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
229 registry->RegisterBooleanPref( 233 registry->RegisterBooleanPref(
230 prefs::kAutofillProfileUseDatesFixed, false, 234 prefs::kAutofillProfileUseDatesFixed, false,
231 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 235 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
232 registry->RegisterIntegerPref( 236 registry->RegisterIntegerPref(
233 prefs::kAutofillLastVersionDeduped, 0, 237 prefs::kAutofillLastVersionDeduped, 0,
234 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 238 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 272
269 static const int kShowScanCreditCardMaxValueLength = 6; 273 static const int kShowScanCreditCardMaxValueLength = 6;
270 return field.value.size() <= kShowScanCreditCardMaxValueLength && 274 return field.value.size() <= kShowScanCreditCardMaxValueLength &&
271 base::ContainsOnlyChars(CreditCard::StripSeparators(field.value), 275 base::ContainsOnlyChars(CreditCard::StripSeparators(field.value),
272 base::ASCIIToUTF16("0123456789")); 276 base::ASCIIToUTF16("0123456789"));
273 } 277 }
274 278
275 bool AutofillManager::ShouldShowCreditCardSigninPromo( 279 bool AutofillManager::ShouldShowCreditCardSigninPromo(
276 const FormData& form, 280 const FormData& form,
277 const FormFieldData& field) { 281 const FormFieldData& field) {
282 if (!IsAutofillCreditCardSigninPromoEnabled())
283 return false;
284
278 // Check whether we are dealing with a credit card field and whether it's 285 // Check whether we are dealing with a credit card field and whether it's
279 // appropriate to show the promo (e.g. the platform is supported). 286 // appropriate to show the promo (e.g. the platform is supported).
280 AutofillField* autofill_field = GetAutofillField(form, field); 287 AutofillField* autofill_field = GetAutofillField(form, field);
281 return autofill_field && autofill_field->Type().group() == CREDIT_CARD && 288 if (!autofill_field || autofill_field->Type().group() != CREDIT_CARD ||
282 client_->ShouldShowSigninPromo(); 289 !client_->ShouldShowSigninPromo())
290 return false;
291
292 // The last step is checking if we are under the limit of impressions (a limit
293 // of 0 means there is no limit);
294 int impression_limit = GetCreditCardSigninPromoImpressionLimit();
295 int impression_count = client_->GetPrefs()->GetInteger(
296 prefs::kAutofillCreditCardSigninPromoImpressionCount);
297 if (impression_limit == 0 || impression_count < impression_limit) {
298 // 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.
299 client_->GetPrefs()->SetInteger(
300 prefs::kAutofillCreditCardSigninPromoImpressionCount,
301 impression_count + 1);
302 return true;
303 }
304
305 return false;
283 } 306 }
284 307
285 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, 308 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms,
286 const TimeTicks& timestamp) { 309 const TimeTicks& timestamp) {
287 if (!IsValidFormDataVector(forms)) 310 if (!IsValidFormDataVector(forms))
288 return; 311 return;
289 312
290 if (!driver_->RendererIsAvailable()) 313 if (!driver_->RendererIsAvailable())
291 return; 314 return;
292 315
(...skipping 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 if (i > 0) 2053 if (i > 0)
2031 fputs("Next oldest form:\n", file); 2054 fputs("Next oldest form:\n", file);
2032 } 2055 }
2033 fputs("\n", file); 2056 fputs("\n", file);
2034 2057
2035 fclose(file); 2058 fclose(file);
2036 } 2059 }
2037 #endif // ENABLE_FORM_DEBUG_DUMP 2060 #endif // ENABLE_FORM_DEBUG_DUMP
2038 2061
2039 } // namespace autofill 2062 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698