summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-26 23:03:38 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-26 23:03:38 +0000
commit1b5557e98c07abd93c5b022135dfcbd3cb5f644f (patch)
tree7a32fe8e5cb878703cc83b8e68d58dc480794fb6 /chrome/browser/autofill
parent6730b450fb21fbb7560091b1943ed3be1c757852 (diff)
downloadchromium_src-1b5557e98c07abd93c5b022135dfcbd3cb5f644f.zip
chromium_src-1b5557e98c07abd93c5b022135dfcbd3cb5f644f.tar.gz
chromium_src-1b5557e98c07abd93c5b022135dfcbd3cb5f644f.tar.bz2
DOMUI: Implement adding an AutoFill address.
BUG=49094 TEST=none Review URL: http://codereview.chromium.org/3174037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57599 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r--chrome/browser/autofill/autofill_common_unittest.cc4
-rw-r--r--chrome/browser/autofill/autofill_profile.cc1
-rw-r--r--chrome/browser/autofill/personal_data_manager.cc100
-rw-r--r--chrome/browser/autofill/personal_data_manager.h4
-rw-r--r--chrome/browser/autofill/personal_data_manager_unittest.cc72
5 files changed, 57 insertions, 124 deletions
diff --git a/chrome/browser/autofill/autofill_common_unittest.cc b/chrome/browser/autofill/autofill_common_unittest.cc
index 441379b..de14413 100644
--- a/chrome/browser/autofill/autofill_common_unittest.cc
+++ b/chrome/browser/autofill/autofill_common_unittest.cc
@@ -32,7 +32,9 @@ void SetProfileInfo(AutoFillProfile* profile,
const char* address1, const char* address2, const char* city,
const char* state, const char* zipcode, const char* country,
const char* phone, const char* fax) {
- profile->set_label(ASCIIToUTF16(label));
+ // TODO(jhawkins): Remove |label|.
+ if (label)
+ profile->set_label(ASCIIToUTF16(label));
check_and_set(profile, NAME_FIRST, first_name);
check_and_set(profile, NAME_MIDDLE, middle_name);
check_and_set(profile, NAME_LAST, last_name);
diff --git a/chrome/browser/autofill/autofill_profile.cc b/chrome/browser/autofill/autofill_profile.cc
index f12b0f8..4150e69 100644
--- a/chrome/browser/autofill/autofill_profile.cc
+++ b/chrome/browser/autofill/autofill_profile.cc
@@ -462,7 +462,6 @@ string16 AutoFillProfile::ConstructInferredLabel(
return label;
}
-
// So we can compare AutoFillProfiles with EXPECT_EQ().
std::ostream& operator<<(std::ostream& os, const AutoFillProfile& profile) {
return os
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
index 8fbfae4..e9838aa 100644
--- a/chrome/browser/autofill/personal_data_manager.cc
+++ b/chrome/browser/autofill/personal_data_manager.cc
@@ -246,8 +246,6 @@ void PersonalDataManager::SetProfiles(std::vector<AutoFillProfile>* profiles) {
std::mem_fun_ref(&AutoFillProfile::IsEmpty)),
profiles->end());
- SetUniqueProfileLabels(profiles);
-
WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
if (!wds)
return;
@@ -386,6 +384,44 @@ void PersonalDataManager::SetCreditCards(
FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged());
}
+// TODO(jhawkins): Refactor SetProfiles so this isn't so hacky.
+void PersonalDataManager::AddProfile(const AutoFillProfile& profile) {
+ // Set to true if |profile| is merged into the profile list.
+ bool merged = false;
+
+ // Don't save a web profile if the data in the profile is a subset of an
+ // auxiliary profile.
+ for (std::vector<AutoFillProfile*>::const_iterator iter =
+ auxiliary_profiles_.begin();
+ iter != auxiliary_profiles_.end(); ++iter) {
+ if (profile.IsSubsetOf(**iter))
+ return;
+ }
+
+ std::vector<AutoFillProfile> profiles;
+ for (std::vector<AutoFillProfile*>::const_iterator iter =
+ web_profiles_.begin();
+ iter != web_profiles_.end(); ++iter) {
+ if (profile.IsSubsetOf(**iter)) {
+ // In this case, the existing profile already contains all of the data
+ // in |profile|, so consider the profiles already merged.
+ merged = true;
+ } else if ((*iter)->IntersectionOfTypesHasEqualValues(profile)) {
+ // |profile| contains all of the data in this profile, plus
+ // more.
+ merged = true;
+ (*iter)->MergeWith(profile);
+ }
+
+ profiles.push_back(**iter);
+ }
+
+ if (!merged)
+ profiles.push_back(profile);
+
+ SetProfiles(&profiles);
+}
+
void PersonalDataManager::RemoveProfile(int unique_id) {
// TODO(jhawkins): Refactor SetProfiles so this isn't so hacky.
std::vector<AutoFillProfile> profiles(web_profiles_.size());
@@ -617,28 +653,6 @@ void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) {
*handle = 0;
}
-void PersonalDataManager::SetUniqueProfileLabels(
- std::vector<AutoFillProfile>* profiles) {
- std::map<string16, std::vector<AutoFillProfile*> > label_map;
- for (std::vector<AutoFillProfile>::iterator iter = profiles->begin();
- iter != profiles->end(); ++iter) {
- label_map[iter->Label()].push_back(&(*iter));
- }
-
- for (std::map<string16, std::vector<AutoFillProfile*> >::iterator iter =
- label_map.begin();
- iter != label_map.end(); ++iter) {
- // Start at the second element because the first label should not be
- // renamed. The appended label number starts at 2, because the first label
- // has an implicit index of 1.
- for (size_t i = 1; i < iter->second.size(); ++i) {
- string16 newlabel = iter->second[i]->Label() +
- base::UintToString16(static_cast<unsigned int>(i + 1));
- iter->second[i]->set_label(newlabel);
- }
- }
-}
-
void PersonalDataManager::SetUniqueCreditCardLabels(
std::vector<CreditCard>* credit_cards) {
std::map<string16, std::vector<CreditCard*> > label_map;
@@ -668,43 +682,7 @@ void PersonalDataManager::SaveImportedProfile() {
if (!imported_profile_.get())
return;
- // Set to true if |imported_profile_| is merged into the profile list.
- bool merged = false;
-
- imported_profile_->set_label(ASCIIToUTF16(kUnlabeled));
-
- // Don't save a web profile if the data in the profile is a subset of an
- // auxiliary profile.
- for (std::vector<AutoFillProfile*>::const_iterator iter =
- auxiliary_profiles_.begin();
- iter != auxiliary_profiles_.end(); ++iter) {
- if (imported_profile_->IsSubsetOf(**iter))
- return;
- }
-
- std::vector<AutoFillProfile> profiles;
- for (std::vector<AutoFillProfile*>::const_iterator iter =
- web_profiles_.begin();
- iter != web_profiles_.end(); ++iter) {
- if (imported_profile_->IsSubsetOf(**iter)) {
- // In this case, the existing profile already contains all of the data
- // in |imported_profile_|, so consider the profiles already merged.
- merged = true;
- } else if ((*iter)->IntersectionOfTypesHasEqualValues(
- *imported_profile_)) {
- // |imported_profile| contains all of the data in this profile, plus
- // more.
- merged = true;
- (*iter)->MergeWith(*imported_profile_);
- }
-
- profiles.push_back(**iter);
- }
-
- if (!merged)
- profiles.push_back(*imported_profile_);
-
- SetProfiles(&profiles);
+ AddProfile(*imported_profile_);
}
// TODO(jhawkins): Refactor and merge this with SaveImportedProfile.
diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h
index e3c9e92..53a2674 100644
--- a/chrome/browser/autofill/personal_data_manager.h
+++ b/chrome/browser/autofill/personal_data_manager.h
@@ -100,6 +100,9 @@ class PersonalDataManager
// ID of newly-added profiles.
void SetCreditCards(std::vector<CreditCard>* credit_cards);
+ // Adds |profile| to the web database.
+ void AddProfile(const AutoFillProfile& profile);
+
// Removes the profile represented by |unique_id|.
void RemoveProfile(int unique_id);
@@ -203,7 +206,6 @@ class PersonalDataManager
// to the end of non-unique labels.
// TODO(jhawkins): Create a new interface for labeled entities and turn these
// two methods into one.
- void SetUniqueProfileLabels(std::vector<AutoFillProfile>* profiles);
void SetUniqueCreditCardLabels(std::vector<CreditCard>* credit_cards);
// Saves |imported_profile_| to the WebDB if it exists.
diff --git a/chrome/browser/autofill/personal_data_manager_unittest.cc b/chrome/browser/autofill/personal_data_manager_unittest.cc
index 5520653..76ff2b8 100644
--- a/chrome/browser/autofill/personal_data_manager_unittest.cc
+++ b/chrome/browser/autofill/personal_data_manager_unittest.cc
@@ -575,8 +575,8 @@ TEST_F(PersonalDataManagerTest, ImportFormData) {
MessageLoop::current()->Run();
- AutoFillProfile expected(ASCIIToUTF16("Unlabeled"), 1);
- autofill_unittest::SetProfileInfo(&expected, "Unlabeled", "George", NULL,
+ AutoFillProfile expected(string16(), 1);
+ autofill_unittest::SetProfileInfo(&expected, NULL, "George", NULL,
"Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL);
const std::vector<AutoFillProfile*>& results = personal_data_->profiles();
@@ -584,54 +584,6 @@ TEST_F(PersonalDataManagerTest, ImportFormData) {
EXPECT_EQ(expected, *results[0]);
}
-TEST_F(PersonalDataManagerTest, SetUniqueProfileLabels) {
- AutoFillProfile profile0(ASCIIToUTF16("Home"), 0);
- profile0.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("John"));
- AutoFillProfile profile1(ASCIIToUTF16("Home"), 0);
- profile1.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Paul"));
- AutoFillProfile profile2(ASCIIToUTF16("Home"), 0);
- profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Ringo"));
- AutoFillProfile profile3(ASCIIToUTF16("NotHome"), 0);
- profile3.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Other"));
- AutoFillProfile profile4(ASCIIToUTF16("Work"), 0);
- profile4.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Ozzy"));
- AutoFillProfile profile5(ASCIIToUTF16("Work"), 0);
- profile5.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Dio"));
-
- // This will verify that the web database has been loaded and the notification
- // sent out.
- EXPECT_CALL(personal_data_observer_,
- OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
-
- // The message loop will exit when the mock observer is notified.
- MessageLoop::current()->Run();
-
- // Add the test profiles to the database.
- std::vector<AutoFillProfile> update;
- update.push_back(profile0);
- update.push_back(profile1);
- update.push_back(profile2);
- update.push_back(profile3);
- update.push_back(profile4);
- update.push_back(profile5);
- personal_data_->SetProfiles(&update);
-
- // And wait for the refresh.
- EXPECT_CALL(personal_data_observer_,
- OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
-
- MessageLoop::current()->Run();
-
- const std::vector<AutoFillProfile*>& results = personal_data_->profiles();
- ASSERT_EQ(6U, results.size());
- EXPECT_EQ(ASCIIToUTF16("Home"), results[0]->Label());
- EXPECT_EQ(ASCIIToUTF16("Home2"), results[1]->Label());
- EXPECT_EQ(ASCIIToUTF16("Home3"), results[2]->Label());
- EXPECT_EQ(ASCIIToUTF16("NotHome"), results[3]->Label());
- EXPECT_EQ(ASCIIToUTF16("Work"), results[4]->Label());
- EXPECT_EQ(ASCIIToUTF16("Work2"), results[5]->Label());
-}
-
TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) {
CreditCard credit_card0(ASCIIToUTF16("Home"), 0);
credit_card0.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("John"));
@@ -701,8 +653,8 @@ TEST_F(PersonalDataManagerTest, AggregateProfileData) {
MessageLoop::current()->Run();
scoped_ptr<AutoFillProfile> expected(
- new AutoFillProfile(ASCIIToUTF16("Unlabeled"), 1));
- autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled", "George", NULL,
+ new AutoFillProfile(string16(), 1));
+ autofill_unittest::SetProfileInfo(expected.get(), NULL, "George", NULL,
"Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL);
const std::vector<AutoFillProfile*>& results = personal_data_->profiles();
@@ -735,14 +687,14 @@ TEST_F(PersonalDataManagerTest, AggregateProfileData) {
const std::vector<AutoFillProfile*>& results2 = personal_data_->profiles();
ASSERT_EQ(2U, results2.size());
- expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled"), 1));
- autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled", "George", NULL,
+ expected.reset(new AutoFillProfile(string16(), 1));
+ autofill_unittest::SetProfileInfo(expected.get(), NULL, "George", NULL,
"Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL);
EXPECT_EQ(*expected, *results2[0]);
- expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled2"), 2));
- autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled2", "John", NULL,
+ expected.reset(new AutoFillProfile(string16(), 2));
+ autofill_unittest::SetProfileInfo(expected.get(), NULL, "John", NULL,
"Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
EXPECT_EQ(*expected, *results2[1]);
@@ -782,14 +734,14 @@ TEST_F(PersonalDataManagerTest, AggregateProfileData) {
const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles();
ASSERT_EQ(2U, results3.size());
- expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled"), 1));
- autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled", "George", NULL,
+ expected.reset(new AutoFillProfile(string16(), 1));
+ autofill_unittest::SetProfileInfo(expected.get(), NULL, "George", NULL,
"Washington", "theprez@gmail.com", NULL, "190 High Street", NULL,
"Philadelphia", "Pennsylvania", "19106", NULL, NULL, NULL);
EXPECT_EQ(*expected, *results3[0]);
- expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled2"), 2));
- autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled2", "John", NULL,
+ expected.reset(new AutoFillProfile(string16(), 2));
+ autofill_unittest::SetProfileInfo(expected.get(), NULL, "John", NULL,
"Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
EXPECT_EQ(*expected, *results3[1]);