diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-21 07:38:56 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-21 07:38:56 +0000 |
commit | fc9c33ae67005fdbc7905da4803ca5f02cfea6c3 (patch) | |
tree | ccd3b663b044df95204799b9d0f043a7d6418547 /chrome/browser/autofill | |
parent | 740fe1eb708c775001dda1758ffab6232831febc (diff) | |
download | chromium_src-fc9c33ae67005fdbc7905da4803ca5f02cfea6c3.zip chromium_src-fc9c33ae67005fdbc7905da4803ca5f02cfea6c3.tar.gz chromium_src-fc9c33ae67005fdbc7905da4803ca5f02cfea6c3.tar.bz2 |
Make AutofillManager::GetProfileSuggestions use PersonalDataManager::GetProfileSuggestions
BUG=none
TEST=AutofillManager unit tests
Review URL: https://chromiumcodereview.appspot.com/11644034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174355 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r-- | chrome/browser/autofill/autofill_manager.cc | 89 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager.h | 22 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_manager_unittest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_metrics_unittest.cc | 5 | ||||
-rw-r--r-- | chrome/browser/autofill/personal_data_manager.h | 1 |
5 files changed, 27 insertions, 93 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index efb9b33..8559b92 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -63,6 +63,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/gfx/rect.h" +typedef PersonalDataManager::GUIDPair GUIDPair; using base::TimeTicks; using content::BrowserThread; using content::RenderViewHost; @@ -1129,83 +1130,19 @@ void AutofillManager::GetProfileSuggestions( std::vector<string16>* labels, std::vector<string16>* icons, std::vector<int>* unique_ids) const { - const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); - const std::string app_locale = AutofillCountry::ApplicationLocale(); - if (!field.is_autofilled) { - std::vector<AutofillProfile*> matched_profiles; - for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin(); - iter != profiles.end(); ++iter) { - AutofillProfile* profile = *iter; - - // The value of the stored data for this field type in the |profile|. - std::vector<string16> multi_values; - profile->GetMultiInfo(type, app_locale, &multi_values); - - for (size_t i = 0; i < multi_values.size(); ++i) { - if (!multi_values[i].empty() && - StartsWith(multi_values[i], field.value, false)) { - matched_profiles.push_back(profile); - values->push_back(multi_values[i]); - unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), - GUIDPair(profile->guid(), i))); - } - } - } - - std::vector<AutofillFieldType> form_fields; - form_fields.reserve(form->field_count()); - for (std::vector<AutofillField*>::const_iterator iter = form->begin(); - iter != form->end(); ++iter) { - form_fields.push_back((*iter)->type()); - } - - AutofillProfile::CreateInferredLabels(&matched_profiles, &form_fields, - type, 1, labels); - - // No icons for profile suggestions. - icons->resize(values->size()); - } else { - for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin(); - iter != profiles.end(); ++iter) { - AutofillProfile* profile = *iter; - - // The value of the stored data for this field type in the |profile|. - std::vector<string16> multi_values; - profile->GetMultiInfo(type, app_locale, &multi_values); - - for (size_t i = 0; i < multi_values.size(); ++i) { - if (multi_values[i].empty()) - continue; - string16 profile_value_lower_case(StringToLowerASCII(multi_values[i])); - string16 field_value_lower_case(StringToLowerASCII(field.value)); - // Phone numbers could be split in US forms, so field value could be - // either prefix or suffix of the phone. - bool matched_phones = false; - if (type == PHONE_HOME_NUMBER && !field_value_lower_case.empty() && - (profile_value_lower_case.find(field_value_lower_case) != - string16::npos)) { - matched_phones = true; - } - if (matched_phones || - profile_value_lower_case == field_value_lower_case) { - for (size_t j = 0; j < multi_values.size(); ++j) { - if (!multi_values[j].empty()) { - values->push_back(multi_values[j]); - unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), - GUIDPair(profile->guid(), j))); - } - } - // We've added all the values for this profile so move on to the next. - break; - } - } - } + std::vector<AutofillFieldType> field_types(form->field_count()); + for (size_t i = 0; i < form->field_count(); ++i) { + field_types[i] = form->field(i)->type(); + } + std::vector<GUIDPair> guid_pairs; - // No labels for previously filled fields. - labels->resize(values->size()); + personal_data_->GetProfileSuggestions( + type, field.value, field.is_autofilled, field_types, + values, labels, icons, &guid_pairs); - // No icons for profile suggestions. - icons->resize(values->size()); + for (size_t i = 0; i < guid_pairs.size(); ++i) { + unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), + guid_pairs[i])); } } @@ -1302,7 +1239,7 @@ int AutofillManager::GUIDToID(const GUIDPair& guid) const { } } -const AutofillManager::GUIDPair AutofillManager::IDToGUID(int id) const { +const GUIDPair AutofillManager::IDToGUID(int id) const { if (id == 0) return GUIDPair(std::string(), 0); diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h index dd625b1..d175ce2 100644 --- a/chrome/browser/autofill/autofill_manager.h +++ b/chrome/browser/autofill/autofill_manager.h @@ -25,6 +25,7 @@ #include "chrome/browser/autofill/autofill_download.h" #include "chrome/browser/autofill/field_types.h" #include "chrome/browser/autofill/form_structure.h" +#include "chrome/browser/autofill/personal_data_manager.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/common/ssl_status.h" @@ -35,7 +36,6 @@ class AutofillMetrics; class CreditCard; class FormGroup; class GURL; -class PersonalDataManager; class PrefService; class ProfileSyncService; @@ -113,11 +113,6 @@ class AutofillManager : public content::WebContentsObserver, autofill::AutofillManagerDelegate* delegate); virtual ~AutofillManager(); - // The string/int pair is composed of the guid string and variant index - // respectively. The variant index is an index into the multi-valued item - // (where applicable). - typedef std::pair<std::string, size_t> GUIDPair; - // Test code should prefer to use this constructor. AutofillManager(content::WebContents* web_contents, autofill::AutofillManagerDelegate* delegate, @@ -148,13 +143,16 @@ class AutofillManager : public content::WebContentsObserver, // Maps GUIDs to and from IDs that are used to identify profiles and credit // cards sent to and from the renderer process. - virtual int GUIDToID(const GUIDPair& guid) const; - virtual const GUIDPair IDToGUID(int id) const; + virtual int GUIDToID(const PersonalDataManager::GUIDPair& guid) const; + virtual const PersonalDataManager::GUIDPair IDToGUID(int id) const; // Methods for packing and unpacking credit card and profile IDs for sending // and receiving to and from the renderer process. - int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const; - void UnpackGUIDs(int id, GUIDPair* cc_guid, GUIDPair* profile_guid) const; + int PackGUIDs(const PersonalDataManager::GUIDPair& cc_guid, + const PersonalDataManager::GUIDPair& profile_guid) const; + void UnpackGUIDs(int id, + PersonalDataManager::GUIDPair* cc_guid, + PersonalDataManager::GUIDPair* profile_guid) const; const AutofillMetrics* metric_logger() const { return metric_logger_.get(); } void set_metric_logger(const AutofillMetrics* metric_logger); @@ -366,8 +364,8 @@ class AutofillManager : public content::WebContentsObserver, ScopedVector<FormStructure> form_structures_; // GUID to ID mapping. We keep two maps to convert back and forth. - mutable std::map<GUIDPair, int> guid_id_map_; - mutable std::map<int, GUIDPair> id_guid_map_; + mutable std::map<PersonalDataManager::GUIDPair, int> guid_id_map_; + mutable std::map<int, PersonalDataManager::GUIDPair> id_guid_map_; // Delegate to perform external processing (display, selection) on // our behalf. Weak. diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc index 111d2cb..6c03030 100644 --- a/chrome/browser/autofill/autofill_manager_unittest.cc +++ b/chrome/browser/autofill/autofill_manager_unittest.cc @@ -51,6 +51,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/gfx/rect.h" +typedef PersonalDataManager::GUIDPair GUIDPair; using content::BrowserThread; using content::WebContents; using testing::_; @@ -607,8 +608,6 @@ class TestAutofillManager : public AutofillManager { class AutofillManagerTest : public ChromeRenderViewHostTestHarness { public: - typedef AutofillManager::GUIDPair GUIDPair; - AutofillManagerTest() : ChromeRenderViewHostTestHarness(), ui_thread_(BrowserThread::UI, &message_loop_), diff --git a/chrome/browser/autofill/autofill_metrics_unittest.cc b/chrome/browser/autofill/autofill_metrics_unittest.cc index 3471b5c2..c0e1cc9 100644 --- a/chrome/browser/autofill/autofill_metrics_unittest.cc +++ b/chrome/browser/autofill/autofill_metrics_unittest.cc @@ -1429,8 +1429,9 @@ TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { EXPECT_CALL(*autofill_manager_->metric_logger(), LogUserHappinessMetric( AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE)); - AutofillManager::GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); - AutofillManager::GUIDPair empty(std::string(), 0); + PersonalDataManager::GUIDPair guid( + "00000000-0000-0000-0000-000000000001", 0); + PersonalDataManager::GUIDPair empty(std::string(), 0); autofill_manager_->OnFillAutofillFormData( 0, form, form.fields.front(), autofill_manager_->PackGUIDs(empty, guid)); diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h index 3de0cae..2cd73eec 100644 --- a/chrome/browser/autofill/personal_data_manager.h +++ b/chrome/browser/autofill/personal_data_manager.h @@ -133,7 +133,6 @@ class PersonalDataManager // part the user has already typed. |field_is_autofilled| is true if the field // has already been autofilled. |other_field_types| represents the rest of // form. Identifying info is loaded into the last four outparams. - // TODO(estade): port AutofillManager and its test to use this function. void GetProfileSuggestions( AutofillFieldType type, const string16& field_contents, |