summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-04 01:44:50 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-04 01:44:50 +0000
commit8654c77d7660cbd4ca5b5bd5fbd0b64ad45f6e29 (patch)
treed1d309d8ab115fa1bbd2a92c073dcc558e9d18d2 /chrome/browser/autofill
parentf5051be746f756b72cbc47a2e9bdbdac889af3a1 (diff)
downloadchromium_src-8654c77d7660cbd4ca5b5bd5fbd0b64ad45f6e29.zip
chromium_src-8654c77d7660cbd4ca5b5bd5fbd0b64ad45f6e29.tar.gz
chromium_src-8654c77d7660cbd4ca5b5bd5fbd0b64ad45f6e29.tar.bz2
A bit of STL-ified cleanup in the PersonalDataManager code
BUG=none TEST=none (just refactoring) Review URL: http://codereview.chromium.org/5593002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68265 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r--chrome/browser/autofill/personal_data_manager.cc72
1 files changed, 23 insertions, 49 deletions
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
index 894fa6b..a4475cb 100644
--- a/chrome/browser/autofill/personal_data_manager.cc
+++ b/chrome/browser/autofill/personal_data_manager.cc
@@ -41,6 +41,19 @@ class FormGroupGUIDMatchesFunctor {
};
template<typename T>
+class FormGroupGUIDMatchesFunctor<T *> {
+ public:
+ explicit FormGroupGUIDMatchesFunctor(const std::string& guid) : guid_(guid) {}
+
+ bool operator()(const T* form_group) {
+ return form_group->guid() == guid_;
+ }
+
+ private:
+ std::string guid_;
+};
+
+template<typename T>
class DereferenceFunctor {
public:
template<typename T_Iterator>
@@ -54,49 +67,10 @@ T* address_of(T& v) {
return &v;
}
-bool FindInProfilesByGUID(const std::vector<AutoFillProfile>& profiles,
- const std::string& guid) {
- for (std::vector<AutoFillProfile>::const_iterator iter = profiles.begin();
- iter != profiles.end();
- ++iter) {
- if (iter->guid() == guid)
- return true;
- }
- return false;
-}
-
-bool FindInScopedProfilesByGUID(const ScopedVector<AutoFillProfile>& profiles,
- const std::string& guid) {
- for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin();
- iter != profiles.end();
- ++iter) {
- if ((*iter)->guid() == guid)
- return true;
- }
- return false;
-}
-
-bool FindInCreditCardsByGUID(const std::vector<CreditCard>& credit_cards,
- const std::string& guid) {
- for (std::vector<CreditCard>::const_iterator iter = credit_cards.begin();
- iter != credit_cards.end();
- ++iter) {
- if (iter->guid() == guid)
- return true;
- }
- return false;
-}
-
-bool FindInScopedCreditCardsByGUID(
- const ScopedVector<CreditCard>& credit_cards, const std::string& guid) {
- for (std::vector<CreditCard*>::const_iterator iter =
- credit_cards.begin();
- iter != credit_cards.end();
- ++iter) {
- if ((*iter)->guid() == guid)
- return true;
- }
- return false;
+template<typename T, typename C>
+bool FindByGUID(const C& container, const std::string& guid) {
+ return std::find_if(container.begin(), container.end(),
+ FormGroupGUIDMatchesFunctor<T>(guid)) != container.end();
}
} // namespace
@@ -328,21 +302,21 @@ void PersonalDataManager::SetProfiles(std::vector<AutoFillProfile>* profiles) {
for (std::vector<AutoFillProfile*>::const_iterator iter =
web_profiles_.begin();
iter != web_profiles_.end(); ++iter) {
- if (!FindInProfilesByGUID(*profiles, (*iter)->guid()))
+ if (!FindByGUID<AutoFillProfile>(*profiles, (*iter)->guid()))
wds->RemoveAutoFillProfileGUID((*iter)->guid());
}
// Update the web database with the existing profiles.
for (std::vector<AutoFillProfile>::iterator iter = profiles->begin();
iter != profiles->end(); ++iter) {
- if (FindInScopedProfilesByGUID(web_profiles_, iter->guid()))
+ if (FindByGUID<AutoFillProfile*>(web_profiles_, iter->guid()))
wds->UpdateAutoFillProfileGUID(*iter);
}
// Add the new profiles to the web database.
for (std::vector<AutoFillProfile>::iterator iter = profiles->begin();
iter != profiles->end(); ++iter) {
- if (!FindInScopedProfilesByGUID(web_profiles_, iter->guid()))
+ if (!FindByGUID<AutoFillProfile*>(web_profiles_, iter->guid()))
wds->AddAutoFillProfileGUID(*iter);
}
@@ -381,21 +355,21 @@ void PersonalDataManager::SetCreditCards(
// removed.
for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin();
iter != credit_cards_.end(); ++iter) {
- if (!FindInCreditCardsByGUID(*credit_cards, (*iter)->guid()))
+ if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid()))
wds->RemoveCreditCardGUID((*iter)->guid());
}
// Update the web database with the existing credit cards.
for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
iter != credit_cards->end(); ++iter) {
- if (FindInScopedCreditCardsByGUID(credit_cards_, iter->guid()))
+ if (FindByGUID<CreditCard*>(credit_cards_, iter->guid()))
wds->UpdateCreditCardGUID(*iter);
}
// Add the new credit cards to the web database.
for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
iter != credit_cards->end(); ++iter) {
- if (!FindInScopedCreditCardsByGUID(credit_cards_, iter->guid()))
+ if (!FindByGUID<CreditCard*>(credit_cards_, iter->guid()))
wds->AddCreditCardGUID(*iter);
}