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

Unified Diff: chrome/browser/autofill/autofill_profile.cc

Issue 6877130: These changes *are* for review :) (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/autofill_profile.cc
===================================================================
--- chrome/browser/autofill/autofill_profile.cc (revision 84722)
+++ chrome/browser/autofill/autofill_profile.cc (working copy)
@@ -15,8 +15,8 @@
#include "chrome/browser/autofill/address.h"
#include "chrome/browser/autofill/autofill_type.h"
#include "chrome/browser/autofill/contact_info.h"
-#include "chrome/browser/autofill/fax_number.h"
-#include "chrome/browser/autofill/home_phone_number.h"
+#include "chrome/browser/autofill/phone_number.h"
+#include "chrome/browser/autofill/phone_number_i18n.h"
#include "chrome/common/guid.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -178,6 +178,9 @@
AutofillProfile::AutofillProfile(const std::string& guid)
: guid_(guid), name_(1), email_(1), home_number_(1), fax_number_(1) {
+ // Set the type of the phones - it is set on first SetInfo() call.
dhollowa 2011/05/13 18:55:35 Better to use the vector initializer to set the ph
GeorgeY 2011/05/18 17:41:45 Done.
+ home_number_[0].SetInfo(PHONE_HOME_WHOLE_NUMBER, string16());
+ fax_number_[0].SetInfo(PHONE_FAX_WHOLE_NUMBER, string16());
}
AutofillProfile::AutofillProfile()
@@ -186,6 +189,9 @@
email_(1),
home_number_(1),
fax_number_(1) {
+ // Set the type of the phones - it is set on first SetInfo() call.
dhollowa 2011/05/13 18:55:35 Better to use the vector initializer to set the ph
GeorgeY 2011/05/18 17:41:45 Done.
+ home_number_[0].SetInfo(PHONE_HOME_WHOLE_NUMBER, string16());
+ fax_number_[0].SetInfo(PHONE_FAX_WHOLE_NUMBER, string16());
}
AutofillProfile::AutofillProfile(const AutofillProfile& profile)
@@ -253,9 +259,15 @@
break;
case AutofillType::PHONE_HOME:
CopyValuesToItems(type, values, &home_number_);
dhollowa 2011/05/13 18:55:35 Let's keep the initialization logic cohesive withi
GeorgeY 2011/05/18 17:41:45 OK
+ // If it was cleared, set the type.
+ if (values.empty())
+ home_number_[0].SetInfo(PHONE_HOME_WHOLE_NUMBER, string16());
break;
case AutofillType::PHONE_FAX:
CopyValuesToItems(type, values, &fax_number_);
+ // If it was cleared, set the type.
+ if (values.empty())
+ fax_number_[0].SetInfo(PHONE_FAX_WHOLE_NUMBER, string16());
break;
default:
if (values.size() == 1) {
@@ -463,6 +475,22 @@
GetInfo(ADDRESS_HOME_CITY);
}
+bool AutofillProfile::NormalizePhones() {
+ // Successful either if nothing to parse, or everything is parsed correctly.
+ bool success = true;
+ for (size_t i = 0; i < home_number_.size(); ++i) {
+ home_number_[i].set_locale(CountryCode());
+ if (!home_number_[i].NormalizePhone())
+ success = false;
+ }
+ for (size_t i = 0; i < fax_number_.size(); ++i) {
+ fax_number_[i].set_locale(CountryCode());
+ if (!fax_number_[i].NormalizePhone())
+ success = false;
+ }
+ return success;
+}
+
void AutofillProfile::OverwriteWithOrAddTo(const AutofillProfile& profile) {
FieldTypeSet field_types;
profile.GetNonEmptyTypes(&field_types);
@@ -478,12 +506,33 @@
profile.GetMultiInfo(*iter, &new_values);
std::vector<string16> existing_values;
GetMultiInfo(*iter, &existing_values);
+ FieldTypeGroup group = AutofillType(*iter).group();
for (std::vector<string16>::iterator value_iter = new_values.begin();
value_iter != new_values.end(); ++value_iter) {
// Don't add duplicates.
- if (std::find(existing_values.begin(), existing_values.end(),
- *value_iter) == existing_values.end()) {
- existing_values.insert(existing_values.end(), *value_iter);
+ if (group == AutofillType::PHONE_HOME ||
dhollowa 2011/05/13 18:55:35 A few things here: (1) Let's split this logic out
GeorgeY 2011/05/18 17:41:45 Done.
+ group == AutofillType::PHONE_FAX) {
+ // Phones allow "fuzzy" matching, so "1-800-FLOWERS", "18003569377",
+ // "(800)356-9377" and "356-9377" are considered the same.
+ std::vector<string16>::const_iterator phone_iter;
+ for (phone_iter = existing_values.begin();
+ phone_iter != existing_values.end();
+ ++phone_iter) {
+ autofill_i18n::PhoneMatch match = autofill_i18n::ComparePhones(
+ *phone_iter, *value_iter, CountryCode());
+ if (match == autofill_i18n::PHONES_EQUAL ||
+ match == autofill_i18n::PHONES_SUBMATCH) {
+ break;
+ }
+ }
+ // Add phone if it does not match any other.
+ if (phone_iter == existing_values.end())
+ existing_values.insert(existing_values.end(), *value_iter);
+ } else {
+ if (std::find(existing_values.begin(), existing_values.end(),
+ *value_iter) == existing_values.end()) {
+ existing_values.insert(existing_values.end(), *value_iter);
+ }
}
}
SetMultiInfo(*iter, existing_values);

Powered by Google App Engine
This is Rietveld 408576698