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

Side by Side Diff: chrome/browser/autofill/personal_data_manager.cc

Issue 7892048: Autofill: Remove fax number completely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fix. Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/autofill/personal_data_manager.h" 5 #include "chrome/browser/autofill/personal_data_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 // Return true if the |field_type| and |value| are valid within the context 97 // Return true if the |field_type| and |value| are valid within the context
98 // of importing a form. 98 // of importing a form.
99 bool IsValidFieldTypeAndValue(const std::set<AutofillFieldType>& types_seen, 99 bool IsValidFieldTypeAndValue(const std::set<AutofillFieldType>& types_seen,
100 AutofillFieldType field_type, 100 AutofillFieldType field_type,
101 const string16& value) { 101 const string16& value) {
102 // Abandon the import if two fields of the same type are encountered. 102 // Abandon the import if two fields of the same type are encountered.
103 // This indicates ambiguous data or miscategorization of types. 103 // This indicates ambiguous data or miscategorization of types.
104 // Make an exception for PHONE_HOME_NUMBER however as both prefix and 104 // Make an exception for PHONE_HOME_NUMBER however as both prefix and
105 // suffix are stored against this type. 105 // suffix are stored against this type.
106 if (types_seen.count(field_type) && 106 if (types_seen.count(field_type) && field_type != PHONE_HOME_NUMBER)
107 field_type != PHONE_HOME_NUMBER &&
108 field_type != PHONE_FAX_NUMBER) {
109 return false; 107 return false;
110 }
111 108
112 // Abandon the import if an email address value shows up in a field that is 109 // Abandon the import if an email address value shows up in a field that is
113 // not an email address. 110 // not an email address.
114 if (field_type != EMAIL_ADDRESS && IsValidEmail(value)) 111 if (field_type != EMAIL_ADDRESS && IsValidEmail(value))
115 return false; 112 return false;
116 113
117 return true; 114 return true;
118 } 115 }
119 116
120 } // namespace 117 } // namespace
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // Parse the form and construct a profile based on the information that is 207 // Parse the form and construct a profile based on the information that is
211 // possible to import. 208 // possible to import.
212 int importable_credit_card_fields = 0; 209 int importable_credit_card_fields = 0;
213 std::vector<const FormStructure*>::const_iterator iter; 210 std::vector<const FormStructure*>::const_iterator iter;
214 211
215 // Detect and discard forms with multiple fields of the same type. 212 // Detect and discard forms with multiple fields of the same type.
216 std::set<AutofillFieldType> types_seen; 213 std::set<AutofillFieldType> types_seen;
217 214
218 // We only set complete phone, so aggregate phone parts in these vars and set 215 // We only set complete phone, so aggregate phone parts in these vars and set
219 // complete at the end. 216 // complete at the end.
220 PhoneNumber::PhoneCombineHelper home(AutofillType::PHONE_HOME); 217 PhoneNumber::PhoneCombineHelper home;
221 PhoneNumber::PhoneCombineHelper fax(AutofillType::PHONE_FAX);
222 218
223 for (size_t i = 0; i < form.field_count(); ++i) { 219 for (size_t i = 0; i < form.field_count(); ++i) {
224 const AutofillField* field = form.field(i); 220 const AutofillField* field = form.field(i);
225 string16 value = CollapseWhitespace(field->value, false); 221 string16 value = CollapseWhitespace(field->value, false);
226 222
227 // If we don't know the type of the field, or the user hasn't entered any 223 // If we don't know the type of the field, or the user hasn't entered any
228 // information into the field, then skip it. 224 // information into the field, then skip it.
229 if (!field->IsFieldFillable() || value.empty()) 225 if (!field->IsFieldFillable() || value.empty())
230 continue; 226 continue;
231 227
(...skipping 14 matching lines...) Expand all
246 if (LowerCaseEqualsASCII(field->form_control_type, "month")) { 242 if (LowerCaseEqualsASCII(field->form_control_type, "month")) {
247 DCHECK_EQ(CREDIT_CARD_EXP_MONTH, field_type); 243 DCHECK_EQ(CREDIT_CARD_EXP_MONTH, field_type);
248 local_imported_credit_card->SetInfoForMonthInputType(value); 244 local_imported_credit_card->SetInfoForMonthInputType(value);
249 } else { 245 } else {
250 local_imported_credit_card->SetCanonicalizedInfo(field_type, value); 246 local_imported_credit_card->SetCanonicalizedInfo(field_type, value);
251 } 247 }
252 ++importable_credit_card_fields; 248 ++importable_credit_card_fields;
253 } else { 249 } else {
254 // We need to store phone data in the variables, before building the whole 250 // We need to store phone data in the variables, before building the whole
255 // number at the end. The rest of the fields are set "as is". 251 // number at the end. The rest of the fields are set "as is".
256 // If the fields are not the phone fields in question both home.SetInfo() 252 // If the fields are not the phone fields in question home.SetInfo() is
257 // and fax.SetInfo() are going to return false. 253 // going to return false.
258 if (!home.SetInfo(field_type, value) && !fax.SetInfo(field_type, value)) 254 if (!home.SetInfo(field_type, value))
259 imported_profile->SetCanonicalizedInfo(field_type, value); 255 imported_profile->SetCanonicalizedInfo(field_type, value);
260 256
261 // Reject profiles with invalid country information. 257 // Reject profiles with invalid country information.
262 if (field_type == ADDRESS_HOME_COUNTRY && 258 if (field_type == ADDRESS_HOME_COUNTRY &&
263 !value.empty() && imported_profile->CountryCode().empty()) { 259 !value.empty() && imported_profile->CountryCode().empty()) {
264 imported_profile.reset(); 260 imported_profile.reset();
265 break; 261 break;
266 } 262 }
267 } 263 }
268 } 264 }
269 265
270 // Construct the phone and fax numbers. Reject the profile if either number 266 // Construct the phone number. Reject the profile if the number is invalid.
271 // is invalid.
272 if (imported_profile.get() && !home.IsEmpty()) { 267 if (imported_profile.get() && !home.IsEmpty()) {
273 string16 constructed_number; 268 string16 constructed_number;
274 if (!home.ParseNumber(imported_profile->CountryCode(), 269 if (!home.ParseNumber(imported_profile->CountryCode(),
275 &constructed_number) || 270 &constructed_number) ||
276 !imported_profile->SetCanonicalizedInfo(PHONE_HOME_WHOLE_NUMBER, 271 !imported_profile->SetCanonicalizedInfo(PHONE_HOME_WHOLE_NUMBER,
277 constructed_number)) { 272 constructed_number)) {
278 imported_profile.reset(); 273 imported_profile.reset();
279 } 274 }
280 } 275 }
281 if (imported_profile.get() && !fax.IsEmpty()) {
282 string16 constructed_number;
283 if (!fax.ParseNumber(imported_profile->CountryCode(),
284 &constructed_number) ||
285 !imported_profile->SetCanonicalizedInfo(PHONE_FAX_WHOLE_NUMBER,
286 constructed_number)) {
287 imported_profile.reset();
288 }
289 }
290 276
291 // Reject the profile if minimum address and validation requirements are not 277 // Reject the profile if minimum address and validation requirements are not
292 // met. 278 // met.
293 if (imported_profile.get() && !IsValidLearnableProfile(*imported_profile)) 279 if (imported_profile.get() && !IsValidLearnableProfile(*imported_profile))
294 imported_profile.reset(); 280 imported_profile.reset();
295 281
296 // Reject the credit card if we did not detect enough filled credit card 282 // Reject the credit card if we did not detect enough filled credit card
297 // fields or if the credit card number does not seem to be valid. 283 // fields or if the credit card number does not seem to be valid.
298 if (local_imported_credit_card.get() && 284 if (local_imported_credit_card.get() &&
299 !local_imported_credit_card->IsComplete()) { 285 !local_imported_credit_card->IsComplete()) {
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 } 906 }
921 907
922 const AutofillMetrics* PersonalDataManager::metric_logger() const { 908 const AutofillMetrics* PersonalDataManager::metric_logger() const {
923 return metric_logger_.get(); 909 return metric_logger_.get();
924 } 910 }
925 911
926 void PersonalDataManager::set_metric_logger( 912 void PersonalDataManager::set_metric_logger(
927 const AutofillMetrics* metric_logger) { 913 const AutofillMetrics* metric_logger) {
928 metric_logger_.reset(metric_logger); 914 metric_logger_.reset(metric_logger);
929 } 915 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/home_phone_number.cc ('k') | chrome/browser/autofill/personal_data_manager_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698