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

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

Issue 1392623002: [Autofill] Add metric for profile action on form submitted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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_profile.h" 5 #include "components/autofill/core/browser/autofill_profile.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <map> 9 #include <map>
10 #include <ostream> 10 #include <ostream>
11 #include <set> 11 #include <set>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/guid.h" 14 #include "base/guid.h"
15 #include "base/i18n/case_conversion.h" 15 #include "base/i18n/case_conversion.h"
16 #include "base/i18n/char_iterator.h" 16 #include "base/i18n/char_iterator.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/sha1.h" 18 #include "base/sha1.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversion_utils.h" 20 #include "base/strings/utf_string_conversion_utils.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "components/autofill/core/browser/address.h" 22 #include "components/autofill/core/browser/address.h"
23 #include "components/autofill/core/browser/address_i18n.h" 23 #include "components/autofill/core/browser/address_i18n.h"
24 #include "components/autofill/core/browser/autofill_country.h" 24 #include "components/autofill/core/browser/autofill_country.h"
25 #include "components/autofill/core/browser/autofill_field.h" 25 #include "components/autofill/core/browser/autofill_field.h"
26 #include "components/autofill/core/browser/autofill_metrics.h"
26 #include "components/autofill/core/browser/autofill_type.h" 27 #include "components/autofill/core/browser/autofill_type.h"
27 #include "components/autofill/core/browser/contact_info.h" 28 #include "components/autofill/core/browser/contact_info.h"
28 #include "components/autofill/core/browser/phone_number.h" 29 #include "components/autofill/core/browser/phone_number.h"
29 #include "components/autofill/core/browser/phone_number_i18n.h" 30 #include "components/autofill/core/browser/phone_number_i18n.h"
30 #include "components/autofill/core/browser/validation.h" 31 #include "components/autofill/core/browser/validation.h"
31 #include "components/autofill/core/common/autofill_l10n_util.h" 32 #include "components/autofill/core/common/autofill_l10n_util.h"
32 #include "components/autofill/core/common/form_field_data.h" 33 #include "components/autofill/core/common/form_field_data.h"
33 #include "grit/components_strings.h" 34 #include "grit/components_strings.h"
34 #include "third_party/icu/source/common/unicode/uchar.h" 35 #include "third_party/icu/source/common/unicode/uchar.h"
35 #include "third_party/libaddressinput/chromium/addressinput_util.h" 36 #include "third_party/libaddressinput/chromium/addressinput_util.h"
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 // user-input parse of the name. 503 // user-input parse of the name.
503 NameInfo heuristically_parsed_name; 504 NameInfo heuristically_parsed_name;
504 heuristically_parsed_name.SetInfo(type, full_name, app_locale); 505 heuristically_parsed_name.SetInfo(type, full_name, app_locale);
505 if (imported_name.ParsedNamesAreEqual(heuristically_parsed_name)) 506 if (imported_name.ParsedNamesAreEqual(heuristically_parsed_name))
506 return; 507 return;
507 } 508 }
508 509
509 name_ = imported_name; 510 name_ = imported_name;
510 } 511 }
511 512
512 void AutofillProfile::OverwriteWith(const AutofillProfile& profile, 513 bool AutofillProfile::OverwriteWith(const AutofillProfile& profile,
513 const std::string& app_locale) { 514 const std::string& app_locale) {
514 // Verified profiles should never be overwritten with unverified data. 515 // Verified profiles should never be overwritten with unverified data.
515 DCHECK(!IsVerified() || profile.IsVerified()); 516 DCHECK(!IsVerified() || profile.IsVerified());
516 set_origin(profile.origin()); 517 set_origin(profile.origin());
517 set_language_code(profile.language_code()); 518 set_language_code(profile.language_code());
518 set_use_count(profile.use_count() + use_count()); 519 set_use_count(profile.use_count() + use_count());
519 if (profile.use_date() > use_date()) 520 if (profile.use_date() > use_date())
520 set_use_date(profile.use_date()); 521 set_use_date(profile.use_date());
521 522
522 ServerFieldTypeSet field_types; 523 ServerFieldTypeSet field_types;
(...skipping 15 matching lines...) Expand all
538 // previous value should not be replaced with an empty string in that case. 539 // previous value should not be replaced with an empty string in that case.
539 if (compare.StringsEqual( 540 if (compare.StringsEqual(
540 CanonicalizeProfileString( 541 CanonicalizeProfileString(
541 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)), 542 profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)),
542 CanonicalizeProfileString(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS))) && 543 CanonicalizeProfileString(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS))) &&
543 profile.GetRawInfo(ADDRESS_HOME_LINE2) == base::UTF8ToUTF16("")) { 544 profile.GetRawInfo(ADDRESS_HOME_LINE2) == base::UTF8ToUTF16("")) {
544 field_types.erase(ADDRESS_HOME_LINE1); 545 field_types.erase(ADDRESS_HOME_LINE1);
545 field_types.erase(ADDRESS_HOME_LINE2); 546 field_types.erase(ADDRESS_HOME_LINE2);
546 } 547 }
547 548
549 bool did_overwrite = false;
550
548 for (ServerFieldTypeSet::const_iterator iter = field_types.begin(); 551 for (ServerFieldTypeSet::const_iterator iter = field_types.begin();
549 iter != field_types.end(); ++iter) { 552 iter != field_types.end(); ++iter) {
550 FieldTypeGroup group = AutofillType(*iter).group(); 553 FieldTypeGroup group = AutofillType(*iter).group();
551 // Special case names. 554 // Special case names.
552 if (group == NAME) { 555 if (group == NAME) {
553 OverwriteName(profile.name_, app_locale); 556 OverwriteName(profile.name_, app_locale);
Evan Stade 2015/10/06 21:01:01 this doesn't count?
sebsg 2015/10/08 14:55:06 Done.
554 continue; 557 continue;
555 } 558 }
556 559
557 base::string16 new_value = profile.GetRawInfo(*iter); 560 base::string16 new_value = profile.GetRawInfo(*iter);
558 if (!compare.StringsEqual(GetRawInfo(*iter), new_value)) 561 if (!compare.StringsEqual(GetRawInfo(*iter), new_value)) {
559 SetRawInfo(*iter, new_value); 562 SetRawInfo(*iter, new_value);
563 did_overwrite = true;
564 }
560 } 565 }
566
567 return did_overwrite;
561 } 568 }
562 569
563 bool AutofillProfile::SaveAdditionalInfo(const AutofillProfile& profile, 570 bool AutofillProfile::SaveAdditionalInfo(const AutofillProfile& profile,
564 const std::string& app_locale) { 571 const std::string& app_locale) {
565 ServerFieldTypeSet field_types, other_field_types; 572 ServerFieldTypeSet field_types, other_field_types;
566 GetNonEmptyTypes(app_locale, &field_types); 573 GetNonEmptyTypes(app_locale, &field_types);
567 profile.GetNonEmptyTypes(app_locale, &other_field_types); 574 profile.GetNonEmptyTypes(app_locale, &other_field_types);
568 // The address needs to be compared line by line to take into account the 575 // The address needs to be compared line by line to take into account the
569 // logic for empty fields implemented in the loop. 576 // logic for empty fields implemented in the loop.
570 field_types.erase(ADDRESS_HOME_STREET_ADDRESS); 577 field_types.erase(ADDRESS_HOME_STREET_ADDRESS);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 } 613 }
607 continue; 614 continue;
608 } 615 }
609 if (!compare.StringsEqual(profile.GetRawInfo(field_type), 616 if (!compare.StringsEqual(profile.GetRawInfo(field_type),
610 GetRawInfo(field_type))) { 617 GetRawInfo(field_type))) {
611 return false; 618 return false;
612 } 619 }
613 } 620 }
614 } 621 }
615 622
616 if (!IsVerified() || profile.IsVerified()) 623 if (!IsVerified() || profile.IsVerified()) {
617 OverwriteWith(profile, app_locale); 624 if (OverwriteWith(profile, app_locale)) {
625 AutofillMetrics::LogProfileActionOnFormSubmitted(
626 AutofillMetrics::EXISTING_PROFILE_UPDATED);
627 } else {
628 AutofillMetrics::LogProfileActionOnFormSubmitted(
629 AutofillMetrics::EXISTING_PROFILE_USED);
630 }
631 }
618 return true; 632 return true;
619 } 633 }
620 634
621 // static 635 // static
622 bool AutofillProfile::SupportsMultiValue(ServerFieldType type) { 636 bool AutofillProfile::SupportsMultiValue(ServerFieldType type) {
623 FieldTypeGroup group = AutofillType(type).group(); 637 FieldTypeGroup group = AutofillType(type).group();
624 return group == NAME || 638 return group == NAME ||
625 group == NAME_BILLING || 639 group == NAME_BILLING ||
626 group == EMAIL || 640 group == EMAIL ||
627 group == PHONE_HOME || 641 group == PHONE_HOME ||
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " " 1007 << " " << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) << " "
994 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " " 1008 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) << " "
995 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " " 1009 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) << " "
996 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " " 1010 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) << " "
997 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " " 1011 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) << " "
998 << profile.language_code() << " " 1012 << profile.language_code() << " "
999 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 1013 << UTF16ToUTF8(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
1000 } 1014 }
1001 1015
1002 } // namespace autofill 1016 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698