| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 bool operator()(const T& form_group) { | 35 bool operator()(const T& form_group) { |
| 36 return form_group.guid() == guid_; | 36 return form_group.guid() == guid_; |
| 37 } | 37 } |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 std::string guid_; | 40 std::string guid_; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 template<typename T> | 43 template<typename T> |
| 44 class FormGroupGUIDMatchesFunctor<T *> { |
| 45 public: |
| 46 explicit FormGroupGUIDMatchesFunctor(const std::string& guid) : guid_(guid) {} |
| 47 |
| 48 bool operator()(const T* form_group) { |
| 49 return form_group->guid() == guid_; |
| 50 } |
| 51 |
| 52 private: |
| 53 std::string guid_; |
| 54 }; |
| 55 |
| 56 template<typename T> |
| 44 class DereferenceFunctor { | 57 class DereferenceFunctor { |
| 45 public: | 58 public: |
| 46 template<typename T_Iterator> | 59 template<typename T_Iterator> |
| 47 const T& operator()(const T_Iterator& iterator) { | 60 const T& operator()(const T_Iterator& iterator) { |
| 48 return *iterator; | 61 return *iterator; |
| 49 } | 62 } |
| 50 }; | 63 }; |
| 51 | 64 |
| 52 template<typename T> | 65 template<typename T> |
| 53 T* address_of(T& v) { | 66 T* address_of(T& v) { |
| 54 return &v; | 67 return &v; |
| 55 } | 68 } |
| 56 | 69 |
| 57 bool FindInProfilesByGUID(const std::vector<AutoFillProfile>& profiles, | 70 template<typename T, typename C> |
| 58 const std::string& guid) { | 71 bool FindByGUID(const C& container, const std::string& guid) { |
| 59 for (std::vector<AutoFillProfile>::const_iterator iter = profiles.begin(); | 72 return std::find_if(container.begin(), container.end(), |
| 60 iter != profiles.end(); | 73 FormGroupGUIDMatchesFunctor<T>(guid)) != container.end(); |
| 61 ++iter) { | |
| 62 if (iter->guid() == guid) | |
| 63 return true; | |
| 64 } | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 bool FindInScopedProfilesByGUID(const ScopedVector<AutoFillProfile>& profiles, | |
| 69 const std::string& guid) { | |
| 70 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); | |
| 71 iter != profiles.end(); | |
| 72 ++iter) { | |
| 73 if ((*iter)->guid() == guid) | |
| 74 return true; | |
| 75 } | |
| 76 return false; | |
| 77 } | |
| 78 | |
| 79 bool FindInCreditCardsByGUID(const std::vector<CreditCard>& credit_cards, | |
| 80 const std::string& guid) { | |
| 81 for (std::vector<CreditCard>::const_iterator iter = credit_cards.begin(); | |
| 82 iter != credit_cards.end(); | |
| 83 ++iter) { | |
| 84 if (iter->guid() == guid) | |
| 85 return true; | |
| 86 } | |
| 87 return false; | |
| 88 } | |
| 89 | |
| 90 bool FindInScopedCreditCardsByGUID( | |
| 91 const ScopedVector<CreditCard>& credit_cards, const std::string& guid) { | |
| 92 for (std::vector<CreditCard*>::const_iterator iter = | |
| 93 credit_cards.begin(); | |
| 94 iter != credit_cards.end(); | |
| 95 ++iter) { | |
| 96 if ((*iter)->guid() == guid) | |
| 97 return true; | |
| 98 } | |
| 99 return false; | |
| 100 } | 74 } |
| 101 | 75 |
| 102 } // namespace | 76 } // namespace |
| 103 | 77 |
| 104 PersonalDataManager::~PersonalDataManager() { | 78 PersonalDataManager::~PersonalDataManager() { |
| 105 CancelPendingQuery(&pending_profiles_query_); | 79 CancelPendingQuery(&pending_profiles_query_); |
| 106 CancelPendingQuery(&pending_creditcards_query_); | 80 CancelPendingQuery(&pending_creditcards_query_); |
| 107 } | 81 } |
| 108 | 82 |
| 109 void PersonalDataManager::OnWebDataServiceRequestDone( | 83 void PersonalDataManager::OnWebDataServiceRequestDone( |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 295 |
| 322 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 296 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); |
| 323 if (!wds) | 297 if (!wds) |
| 324 return; | 298 return; |
| 325 | 299 |
| 326 // Any profiles that are not in the new profile list should be removed from | 300 // Any profiles that are not in the new profile list should be removed from |
| 327 // the web database. | 301 // the web database. |
| 328 for (std::vector<AutoFillProfile*>::const_iterator iter = | 302 for (std::vector<AutoFillProfile*>::const_iterator iter = |
| 329 web_profiles_.begin(); | 303 web_profiles_.begin(); |
| 330 iter != web_profiles_.end(); ++iter) { | 304 iter != web_profiles_.end(); ++iter) { |
| 331 if (!FindInProfilesByGUID(*profiles, (*iter)->guid())) | 305 if (!FindByGUID<AutoFillProfile>(*profiles, (*iter)->guid())) |
| 332 wds->RemoveAutoFillProfileGUID((*iter)->guid()); | 306 wds->RemoveAutoFillProfileGUID((*iter)->guid()); |
| 333 } | 307 } |
| 334 | 308 |
| 335 // Update the web database with the existing profiles. | 309 // Update the web database with the existing profiles. |
| 336 for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); | 310 for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); |
| 337 iter != profiles->end(); ++iter) { | 311 iter != profiles->end(); ++iter) { |
| 338 if (FindInScopedProfilesByGUID(web_profiles_, iter->guid())) | 312 if (FindByGUID<AutoFillProfile*>(web_profiles_, iter->guid())) |
| 339 wds->UpdateAutoFillProfileGUID(*iter); | 313 wds->UpdateAutoFillProfileGUID(*iter); |
| 340 } | 314 } |
| 341 | 315 |
| 342 // Add the new profiles to the web database. | 316 // Add the new profiles to the web database. |
| 343 for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); | 317 for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); |
| 344 iter != profiles->end(); ++iter) { | 318 iter != profiles->end(); ++iter) { |
| 345 if (!FindInScopedProfilesByGUID(web_profiles_, iter->guid())) | 319 if (!FindByGUID<AutoFillProfile*>(web_profiles_, iter->guid())) |
| 346 wds->AddAutoFillProfileGUID(*iter); | 320 wds->AddAutoFillProfileGUID(*iter); |
| 347 } | 321 } |
| 348 | 322 |
| 349 // Copy in the new profiles. | 323 // Copy in the new profiles. |
| 350 web_profiles_.reset(); | 324 web_profiles_.reset(); |
| 351 for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); | 325 for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); |
| 352 iter != profiles->end(); ++iter) { | 326 iter != profiles->end(); ++iter) { |
| 353 web_profiles_.push_back(new AutoFillProfile(*iter)); | 327 web_profiles_.push_back(new AutoFillProfile(*iter)); |
| 354 } | 328 } |
| 355 | 329 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 374 SetUniqueCreditCardLabels(credit_cards); | 348 SetUniqueCreditCardLabels(credit_cards); |
| 375 | 349 |
| 376 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 350 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); |
| 377 if (!wds) | 351 if (!wds) |
| 378 return; | 352 return; |
| 379 | 353 |
| 380 // Any credit cards that are not in the new credit card list should be | 354 // Any credit cards that are not in the new credit card list should be |
| 381 // removed. | 355 // removed. |
| 382 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); | 356 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); |
| 383 iter != credit_cards_.end(); ++iter) { | 357 iter != credit_cards_.end(); ++iter) { |
| 384 if (!FindInCreditCardsByGUID(*credit_cards, (*iter)->guid())) | 358 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) |
| 385 wds->RemoveCreditCardGUID((*iter)->guid()); | 359 wds->RemoveCreditCardGUID((*iter)->guid()); |
| 386 } | 360 } |
| 387 | 361 |
| 388 // Update the web database with the existing credit cards. | 362 // Update the web database with the existing credit cards. |
| 389 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 363 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
| 390 iter != credit_cards->end(); ++iter) { | 364 iter != credit_cards->end(); ++iter) { |
| 391 if (FindInScopedCreditCardsByGUID(credit_cards_, iter->guid())) | 365 if (FindByGUID<CreditCard*>(credit_cards_, iter->guid())) |
| 392 wds->UpdateCreditCardGUID(*iter); | 366 wds->UpdateCreditCardGUID(*iter); |
| 393 } | 367 } |
| 394 | 368 |
| 395 // Add the new credit cards to the web database. | 369 // Add the new credit cards to the web database. |
| 396 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 370 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
| 397 iter != credit_cards->end(); ++iter) { | 371 iter != credit_cards->end(); ++iter) { |
| 398 if (!FindInScopedCreditCardsByGUID(credit_cards_, iter->guid())) | 372 if (!FindByGUID<CreditCard*>(credit_cards_, iter->guid())) |
| 399 wds->AddCreditCardGUID(*iter); | 373 wds->AddCreditCardGUID(*iter); |
| 400 } | 374 } |
| 401 | 375 |
| 402 // Copy in the new credit cards. | 376 // Copy in the new credit cards. |
| 403 credit_cards_.reset(); | 377 credit_cards_.reset(); |
| 404 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 378 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
| 405 iter != credit_cards->end(); ++iter) { | 379 iter != credit_cards->end(); ++iter) { |
| 406 credit_cards_.push_back(new CreditCard(*iter)); | 380 credit_cards_.push_back(new CreditCard(*iter)); |
| 407 } | 381 } |
| 408 | 382 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 } | 781 } |
| 808 | 782 |
| 809 creditcards.push_back(**iter); | 783 creditcards.push_back(**iter); |
| 810 } | 784 } |
| 811 | 785 |
| 812 if (!merged) | 786 if (!merged) |
| 813 creditcards.push_back(*imported_credit_card_); | 787 creditcards.push_back(*imported_credit_card_); |
| 814 | 788 |
| 815 SetCreditCards(&creditcards); | 789 SetCreditCards(&creditcards); |
| 816 } | 790 } |
| OLD | NEW |