OLD | NEW |
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "components/autofill/core/common/autofill_data_validation.h" | 51 #include "components/autofill/core/common/autofill_data_validation.h" |
52 #include "components/autofill/core/common/autofill_pref_names.h" | 52 #include "components/autofill/core/common/autofill_pref_names.h" |
53 #include "components/autofill/core/common/autofill_switches.h" | 53 #include "components/autofill/core/common/autofill_switches.h" |
54 #include "components/autofill/core/common/autofill_util.h" | 54 #include "components/autofill/core/common/autofill_util.h" |
55 #include "components/autofill/core/common/form_data.h" | 55 #include "components/autofill/core/common/form_data.h" |
56 #include "components/autofill/core/common/form_data_predictions.h" | 56 #include "components/autofill/core/common/form_data_predictions.h" |
57 #include "components/autofill/core/common/form_field_data.h" | 57 #include "components/autofill/core/common/form_field_data.h" |
58 #include "components/autofill/core/common/password_form_fill_data.h" | 58 #include "components/autofill/core/common/password_form_fill_data.h" |
59 #include "components/pref_registry/pref_registry_syncable.h" | 59 #include "components/pref_registry/pref_registry_syncable.h" |
60 #include "components/prefs/pref_service.h" | 60 #include "components/prefs/pref_service.h" |
| 61 #include "components/rappor/rappor_utils.h" |
61 #include "google_apis/gaia/identity_provider.h" | 62 #include "google_apis/gaia/identity_provider.h" |
62 #include "grit/components_strings.h" | 63 #include "grit/components_strings.h" |
63 #include "ui/base/l10n/l10n_util.h" | 64 #include "ui/base/l10n/l10n_util.h" |
64 #include "ui/gfx/geometry/rect.h" | 65 #include "ui/gfx/geometry/rect.h" |
65 #include "url/gurl.h" | 66 #include "url/gurl.h" |
66 | 67 |
67 #if defined(OS_IOS) | 68 #if defined(OS_IOS) |
68 #include "components/autofill/core/browser/autofill_field_trial_ios.h" | 69 #include "components/autofill/core/browser/autofill_field_trial_ios.h" |
69 #include "components/autofill/core/browser/keyboard_accessory_metrics_logger.h" | 70 #include "components/autofill/core/browser/keyboard_accessory_metrics_logger.h" |
70 #endif | 71 #endif |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 for (const AutofillField* field : submitted_form) { | 1070 for (const AutofillField* field : submitted_form) { |
1070 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE && | 1071 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE && |
1071 base::StringToInt(field->value, &cvc)) { | 1072 base::StringToInt(field->value, &cvc)) { |
1072 upload_request_.cvc = field->value; | 1073 upload_request_.cvc = field->value; |
1073 break; | 1074 break; |
1074 } | 1075 } |
1075 } | 1076 } |
1076 if (upload_request_.cvc.empty()) { | 1077 if (upload_request_.cvc.empty()) { |
1077 AutofillMetrics::LogCardUploadDecisionMetric( | 1078 AutofillMetrics::LogCardUploadDecisionMetric( |
1078 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); | 1079 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); |
| 1080 CollectRapportSample(submitted_form.source_url(), |
| 1081 "Autofill.CardUploadNotOfferedNoCvc"); |
1079 return; | 1082 return; |
1080 } | 1083 } |
1081 | 1084 |
1082 // Upload also requires recently used or modified addresses that meet the | 1085 // Upload also requires recently used or modified addresses that meet the |
1083 // client-side validation rules. | 1086 // client-side validation rules. |
1084 if (!GetProfilesForCreditCardUpload(*imported_credit_card, | 1087 if (!GetProfilesForCreditCardUpload(*imported_credit_card, |
1085 &upload_request_.profiles)) { | 1088 &upload_request_.profiles, |
| 1089 submitted_form.source_url())) { |
1086 return; | 1090 return; |
1087 } | 1091 } |
1088 | 1092 |
1089 // All required data is available, start the upload process. | 1093 // All required data is available, start the upload process. |
1090 payments_client_->GetUploadDetails(app_locale_); | 1094 payments_client_->GetUploadDetails(app_locale_); |
1091 } | 1095 } |
1092 } | 1096 } |
1093 | 1097 |
1094 bool AutofillManager::GetProfilesForCreditCardUpload( | 1098 bool AutofillManager::GetProfilesForCreditCardUpload( |
1095 const CreditCard& card, | 1099 const CreditCard& card, |
1096 std::vector<AutofillProfile>* profiles) const { | 1100 std::vector<AutofillProfile>* profiles, |
| 1101 const GURL& source_url) const { |
1097 std::vector<AutofillProfile> candidate_profiles; | 1102 std::vector<AutofillProfile> candidate_profiles; |
1098 const base::Time now = base::Time::Now(); | 1103 const base::Time now = base::Time::Now(); |
1099 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15); | 1104 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15); |
1100 | 1105 |
1101 // First, collect all of the addresses used recently. | 1106 // First, collect all of the addresses used recently. |
1102 for (AutofillProfile* profile : personal_data_->GetProfiles()) { | 1107 for (AutofillProfile* profile : personal_data_->GetProfiles()) { |
1103 if ((now - profile->use_date()) < fifteen_minutes || | 1108 if ((now - profile->use_date()) < fifteen_minutes || |
1104 (now - profile->modification_date()) < fifteen_minutes) { | 1109 (now - profile->modification_date()) < fifteen_minutes) { |
1105 candidate_profiles.push_back(*profile); | 1110 candidate_profiles.push_back(*profile); |
1106 } | 1111 } |
1107 } | 1112 } |
1108 if (candidate_profiles.empty()) { | 1113 if (candidate_profiles.empty()) { |
1109 AutofillMetrics::LogCardUploadDecisionMetric( | 1114 AutofillMetrics::LogCardUploadDecisionMetric( |
1110 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS); | 1115 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS); |
| 1116 CollectRapportSample(source_url, "Autofill.CardUploadNotOfferedNoAddress"); |
1111 return false; | 1117 return false; |
1112 } | 1118 } |
1113 | 1119 |
1114 // If any of the names on the card or the addresses don't match (where | 1120 // If any of the names on the card or the addresses don't match (where |
1115 // matching is case insensitive and ignores middle initials if present), the | 1121 // matching is case insensitive and ignores middle initials if present), the |
1116 // candidate set is invalid. This matches the rules for name matching applied | 1122 // candidate set is invalid. This matches the rules for name matching applied |
1117 // server-side by Google Payments and ensures that we don't send upload | 1123 // server-side by Google Payments and ensures that we don't send upload |
1118 // requests that are guaranteed to fail. | 1124 // requests that are guaranteed to fail. |
1119 base::string16 verified_name; | 1125 base::string16 verified_name; |
1120 base::string16 card_name = | 1126 base::string16 card_name = |
1121 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); | 1127 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); |
1122 if (!card_name.empty()) { | 1128 if (!card_name.empty()) { |
1123 verified_name = RemoveMiddleInitial(card_name); | 1129 verified_name = RemoveMiddleInitial(card_name); |
1124 } | 1130 } |
1125 for (const AutofillProfile& profile : candidate_profiles) { | 1131 for (const AutofillProfile& profile : candidate_profiles) { |
1126 base::string16 address_name = | 1132 base::string16 address_name = |
1127 profile.GetInfo(AutofillType(NAME_FULL), app_locale_); | 1133 profile.GetInfo(AutofillType(NAME_FULL), app_locale_); |
1128 if (!address_name.empty()) { | 1134 if (!address_name.empty()) { |
1129 if (verified_name.empty()) { | 1135 if (verified_name.empty()) { |
1130 verified_name = RemoveMiddleInitial(address_name); | 1136 verified_name = RemoveMiddleInitial(address_name); |
1131 } else { | 1137 } else { |
1132 // TODO(crbug.com/590307): We only use ASCII case insensitivity here | 1138 // TODO(crbug.com/590307): We only use ASCII case insensitivity here |
1133 // because the feature is launching US-only and middle initials only | 1139 // because the feature is launching US-only and middle initials only |
1134 // make sense for Western-style names anyway. As we launch in more | 1140 // make sense for Western-style names anyway. As we launch in more |
1135 // countries, we'll need to make the name comparison more sophisticated. | 1141 // countries, we'll need to make the name comparison more sophisticated. |
1136 if (!base::EqualsCaseInsensitiveASCII( | 1142 if (!base::EqualsCaseInsensitiveASCII( |
1137 verified_name, RemoveMiddleInitial(address_name))) { | 1143 verified_name, RemoveMiddleInitial(address_name))) { |
1138 AutofillMetrics::LogCardUploadDecisionMetric( | 1144 AutofillMetrics::LogCardUploadDecisionMetric( |
1139 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES); | 1145 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES); |
| 1146 CollectRapportSample(source_url, |
| 1147 "Autofill.CardUploadNotOfferedConflictingNames"); |
1140 return false; | 1148 return false; |
1141 } | 1149 } |
1142 } | 1150 } |
1143 } | 1151 } |
1144 } | 1152 } |
1145 // If neither the card nor any of the addresses have a name associated with | 1153 // If neither the card nor any of the addresses have a name associated with |
1146 // them, the candidate set is invalid. | 1154 // them, the candidate set is invalid. |
1147 if (verified_name.empty()) { | 1155 if (verified_name.empty()) { |
1148 AutofillMetrics::LogCardUploadDecisionMetric( | 1156 AutofillMetrics::LogCardUploadDecisionMetric( |
1149 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME); | 1157 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME); |
| 1158 CollectRapportSample(source_url, "Autofill.CardUploadNotOfferedNoName"); |
1150 return false; | 1159 return false; |
1151 } | 1160 } |
1152 | 1161 |
1153 // If any of the candidate addresses have a non-empty zip that doesn't match | 1162 // If any of the candidate addresses have a non-empty zip that doesn't match |
1154 // any other non-empty zip, then the candidate set is invalid. | 1163 // any other non-empty zip, then the candidate set is invalid. |
1155 base::string16 verified_zip; | 1164 base::string16 verified_zip; |
1156 for (const AutofillProfile& profile : candidate_profiles) { | 1165 for (const AutofillProfile& profile : candidate_profiles) { |
1157 // TODO(jdonnelly): Use GetInfo instead of GetRawInfo once zip codes are | 1166 // TODO(jdonnelly): Use GetInfo instead of GetRawInfo once zip codes are |
1158 // canonicalized. See http://crbug.com/587465. | 1167 // canonicalized. See http://crbug.com/587465. |
1159 base::string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); | 1168 base::string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); |
(...skipping 25 matching lines...) Expand all Loading... |
1185 if (verified_zip.empty()) { | 1194 if (verified_zip.empty()) { |
1186 AutofillMetrics::LogCardUploadDecisionMetric( | 1195 AutofillMetrics::LogCardUploadDecisionMetric( |
1187 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); | 1196 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); |
1188 return false; | 1197 return false; |
1189 } | 1198 } |
1190 | 1199 |
1191 profiles->assign(candidate_profiles.begin(), candidate_profiles.end()); | 1200 profiles->assign(candidate_profiles.begin(), candidate_profiles.end()); |
1192 return true; | 1201 return true; |
1193 } | 1202 } |
1194 | 1203 |
| 1204 void AutofillManager::CollectRapportSample(const GURL& source_url, |
| 1205 const char* metric_name) const { |
| 1206 if (source_url.is_valid() && client_->GetRapporService()) { |
| 1207 rappor::SampleDomainAndRegistryFromGURL(client_->GetRapporService(), |
| 1208 metric_name, source_url); |
| 1209 } |
| 1210 } |
| 1211 |
1195 // Note that |submitted_form| is passed as a pointer rather than as a reference | 1212 // Note that |submitted_form| is passed as a pointer rather than as a reference |
1196 // so that we can get memory management right across threads. Note also that we | 1213 // so that we can get memory management right across threads. Note also that we |
1197 // explicitly pass in all the time stamps of interest, as the cached ones might | 1214 // explicitly pass in all the time stamps of interest, as the cached ones might |
1198 // get reset before this method executes. | 1215 // get reset before this method executes. |
1199 void AutofillManager::UploadFormDataAsyncCallback( | 1216 void AutofillManager::UploadFormDataAsyncCallback( |
1200 const FormStructure* submitted_form, | 1217 const FormStructure* submitted_form, |
1201 const TimeTicks& load_time, | 1218 const TimeTicks& load_time, |
1202 const TimeTicks& interaction_time, | 1219 const TimeTicks& interaction_time, |
1203 const TimeTicks& submission_time, | 1220 const TimeTicks& submission_time, |
1204 bool observed_submission) { | 1221 bool observed_submission) { |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 if (i > 0) | 2016 if (i > 0) |
2000 fputs("Next oldest form:\n", file); | 2017 fputs("Next oldest form:\n", file); |
2001 } | 2018 } |
2002 fputs("\n", file); | 2019 fputs("\n", file); |
2003 | 2020 |
2004 fclose(file); | 2021 fclose(file); |
2005 } | 2022 } |
2006 #endif // ENABLE_FORM_DEBUG_DUMP | 2023 #endif // ENABLE_FORM_DEBUG_DUMP |
2007 | 2024 |
2008 } // namespace autofill | 2025 } // namespace autofill |
OLD | NEW |