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

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

Issue 970403002: Don't suggest autofill profiles that are subsets of other profiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_profile.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // The rate for positive/negative matches potentially could be different. 60 // The rate for positive/negative matches potentially could be different.
61 const double kAutofillPositiveUploadRateDefaultValue = 0.20; 61 const double kAutofillPositiveUploadRateDefaultValue = 0.20;
62 const double kAutofillNegativeUploadRateDefaultValue = 0.20; 62 const double kAutofillNegativeUploadRateDefaultValue = 0.20;
63 63
64 const size_t kMaxRecentFormSignaturesToRemember = 3; 64 const size_t kMaxRecentFormSignaturesToRemember = 3;
65 65
66 // Set a conservative upper bound on the number of forms we are willing to 66 // Set a conservative upper bound on the number of forms we are willing to
67 // cache, simply to prevent unbounded memory consumption. 67 // cache, simply to prevent unbounded memory consumption.
68 const size_t kMaxFormCacheSize = 100; 68 const size_t kMaxFormCacheSize = 100;
69 69
70 // Removes duplicate suggestions whilst preserving their original order.
71 void RemoveDuplicateSuggestions(std::vector<Suggestion>* suggestions) {
72 std::set<std::pair<base::string16, base::string16>> seen_suggestions;
73
74 for (int i = 0; i < static_cast<int>(suggestions->size()); ++i) {
75 if (!seen_suggestions.insert(std::make_pair(
76 (*suggestions)[i].value, (*suggestions)[i].label)).second) {
77 // Duplicate found, delete it.
78 suggestions->erase(suggestions->begin() + i);
79 i--;
80 }
81 }
82 }
83
84 // Precondition: |form_structure| and |form| should correspond to the same 70 // Precondition: |form_structure| and |form| should correspond to the same
85 // logical form. Returns true if any field in the given |section| within |form| 71 // logical form. Returns true if any field in the given |section| within |form|
86 // is auto-filled. 72 // is auto-filled.
87 bool SectionIsAutofilled(const FormStructure& form_structure, 73 bool SectionIsAutofilled(const FormStructure& form_structure,
88 const FormData& form, 74 const FormData& form,
89 const std::string& section) { 75 const std::string& section) {
90 DCHECK_EQ(form_structure.field_count(), form.fields.size()); 76 DCHECK_EQ(form_structure.field_count(), form.fields.size());
91 for (size_t i = 0; i < form_structure.field_count(); ++i) { 77 for (size_t i = 0; i < form_structure.field_count(); ++i) {
92 if (form_structure.field(i)->section() == section && 78 if (form_structure.field(i)->section() == section &&
93 form.fields[i].is_autofilled) { 79 form.fields[i].is_autofilled) {
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 // If the relevant section is auto-filled and the renderer is querying 513 // If the relevant section is auto-filled and the renderer is querying
528 // for suggestions, then the user is editing the value of a field. 514 // for suggestions, then the user is editing the value of a field.
529 // In this case, mimic autocomplete: don't display labels or icons, 515 // In this case, mimic autocomplete: don't display labels or icons,
530 // as that information is redundant. 516 // as that information is redundant.
531 for (size_t i = 0; i < suggestions.size(); i++) { 517 for (size_t i = 0; i < suggestions.size(); i++) {
532 suggestions[i].label = base::string16(); 518 suggestions[i].label = base::string16();
533 suggestions[i].icon = base::string16(); 519 suggestions[i].icon = base::string16();
534 } 520 }
535 } 521 }
536 522
537 // When filling credit card suggestions, the values and labels are
538 // typically obfuscated, which makes detecting duplicates hard. Since
539 // duplicates only tend to be a problem when filling address forms
540 // anyway, only don't de-dup credit card suggestions.
541 if (!is_filling_credit_card)
542 RemoveDuplicateSuggestions(&suggestions);
543
544 // The first time we show suggestions on this page, log the number of 523 // The first time we show suggestions on this page, log the number of
545 // suggestions available. 524 // suggestions available.
546 // TODO(mathp): Differentiate between number of suggestions available 525 // TODO(mathp): Differentiate between number of suggestions available
547 // (current metric) and number shown to the user. 526 // (current metric) and number shown to the user.
548 if (!has_logged_address_suggestions_count_ && !section_is_autofilled) { 527 if (!has_logged_address_suggestions_count_ && !section_is_autofilled) {
549 AutofillMetrics::LogAddressSuggestionsCount(suggestions.size()); 528 AutofillMetrics::LogAddressSuggestionsCount(suggestions.size());
550 has_logged_address_suggestions_count_ = true; 529 has_logged_address_suggestions_count_ = true;
551 } 530 }
552 } 531 }
553 } 532 }
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 return false; 1442 return false;
1464 1443
1465 // Disregard forms that we wouldn't ever autofill in the first place. 1444 // Disregard forms that we wouldn't ever autofill in the first place.
1466 if (!form.ShouldBeParsed()) 1445 if (!form.ShouldBeParsed())
1467 return false; 1446 return false;
1468 1447
1469 return true; 1448 return true;
1470 } 1449 }
1471 1450
1472 } // namespace autofill 1451 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698