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

Side by Side Diff: chrome/browser/autofill/personal_data_manager.cc

Issue 6903091: Autofill Multi-Value: Additional profiles with same name and address not added to DOM UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 iter != credit_cards->end(); ++iter) { 443 iter != credit_cards->end(); ++iter) {
444 credit_cards_.push_back(new CreditCard(*iter)); 444 credit_cards_.push_back(new CreditCard(*iter));
445 } 445 }
446 446
447 // Read our writes to ensure consistency with the database. 447 // Read our writes to ensure consistency with the database.
448 Refresh(); 448 Refresh();
449 449
450 FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged()); 450 FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged());
451 } 451 }
452 452
453 // TODO(jhawkins): Refactor SetProfiles so this isn't so hacky. 453 // TODO(dhollowa): Refactor to eliminate batch update of |SetProfiles|.
454 // http://crbug.com/73068
454 void PersonalDataManager::AddProfile(const AutofillProfile& profile) { 455 void PersonalDataManager::AddProfile(const AutofillProfile& profile) {
455 // Don't save a web profile if the data in the profile is a subset of an 456 std::vector<AutofillProfile> profiles(web_profiles_.size());
456 // auxiliary profile. 457 std::transform(web_profiles_.begin(), web_profiles_.end(),
457 for (std::vector<AutofillProfile*>::const_iterator iter = 458 profiles.begin(),
458 auxiliary_profiles_.begin(); 459 DereferenceFunctor<AutofillProfile>());
459 iter != auxiliary_profiles_.end(); ++iter) {
460 if (profile.IsSubsetOf(**iter))
461 return;
462 }
463 460
464 std::vector<AutofillProfile> profiles; 461 profiles.push_back(profile);
465 MergeProfile(profile, web_profiles_.get(), &profiles);
466 SetProfiles(&profiles); 462 SetProfiles(&profiles);
467 } 463 }
468 464
469 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { 465 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) {
470 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 466 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
471 if (!wds) 467 if (!wds)
472 return; 468 return;
473 469
474 // Update the cached profile. 470 // Update the cached profile.
475 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_->begin(); 471 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_->begin();
476 iter != web_profiles_->end(); ++iter) { 472 iter != web_profiles_->end(); ++iter) {
477 if ((*iter)->guid() == profile.guid()) { 473 if ((*iter)->guid() == profile.guid()) {
478 delete *iter; 474 delete *iter;
479 *iter = new AutofillProfile(profile); 475 *iter = new AutofillProfile(profile);
480 break; 476 break;
481 } 477 }
482 } 478 }
483 479
484 // Ensure that profile labels are up to date. 480 // Ensure that profile labels are up to date.
485 AutofillProfile::AdjustInferredLabels(&web_profiles_.get()); 481 AutofillProfile::AdjustInferredLabels(&web_profiles_.get());
486 482
487 wds->UpdateAutofillProfile(profile); 483 wds->UpdateAutofillProfile(profile);
488 FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged()); 484 FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged());
489 } 485 }
490 486
487 // TODO(dhollowa): Refactor to eliminate batch update of |SetProfiles|.
488 // http://crbug.com/73068
491 void PersonalDataManager::RemoveProfile(const std::string& guid) { 489 void PersonalDataManager::RemoveProfile(const std::string& guid) {
492 // TODO(jhawkins): Refactor SetProfiles so this isn't so hacky.
493 std::vector<AutofillProfile> profiles(web_profiles_.size()); 490 std::vector<AutofillProfile> profiles(web_profiles_.size());
494 std::transform(web_profiles_.begin(), web_profiles_.end(), 491 std::transform(web_profiles_.begin(), web_profiles_.end(),
495 profiles.begin(), 492 profiles.begin(),
496 DereferenceFunctor<AutofillProfile>()); 493 DereferenceFunctor<AutofillProfile>());
497 494
498 // Remove the profile that matches |guid|. 495 // Remove the profile that matches |guid|.
499 profiles.erase( 496 profiles.erase(
500 std::remove_if(profiles.begin(), profiles.end(), 497 std::remove_if(profiles.begin(), profiles.end(),
501 FormGroupMatchesByGUIDFunctor<AutofillProfile>(guid)), 498 FormGroupMatchesByGUIDFunctor<AutofillProfile>(guid)),
502 profiles.end()); 499 profiles.end());
503 500
504 SetProfiles(&profiles); 501 SetProfiles(&profiles);
505 } 502 }
506 503
507 AutofillProfile* PersonalDataManager::GetProfileByGUID( 504 AutofillProfile* PersonalDataManager::GetProfileByGUID(
508 const std::string& guid) { 505 const std::string& guid) {
509 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_->begin(); 506 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_->begin();
510 iter != web_profiles_->end(); ++iter) { 507 iter != web_profiles_->end(); ++iter) {
511 if ((*iter)->guid() == guid) 508 if ((*iter)->guid() == guid)
512 return *iter; 509 return *iter;
513 } 510 }
514 return NULL; 511 return NULL;
515 } 512 }
516 513
517 // TODO(jhawkins): Refactor SetCreditCards so this isn't so hacky. 514 // TODO(dhollowa): Refactor to eliminate batch update of |SetCreditCards|.
515 // http://crbug.com/73068
518 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { 516 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) {
519 std::vector<CreditCard> credit_cards(credit_cards_.size()); 517 std::vector<CreditCard> credit_cards(credit_cards_.size());
520 std::transform(credit_cards_.begin(), credit_cards_.end(), 518 std::transform(credit_cards_.begin(), credit_cards_.end(),
521 credit_cards.begin(), 519 credit_cards.begin(),
522 DereferenceFunctor<CreditCard>()); 520 DereferenceFunctor<CreditCard>());
523 521
524 credit_cards.push_back(credit_card); 522 credit_cards.push_back(credit_card);
525 SetCreditCards(&credit_cards); 523 SetCreditCards(&credit_cards);
526 } 524 }
527 525
528 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { 526 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) {
529 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 527 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
530 if (!wds) 528 if (!wds)
531 return; 529 return;
532 530
533 // Update the cached credit card. 531 // Update the cached credit card.
534 for (std::vector<CreditCard*>::iterator iter = credit_cards_->begin(); 532 for (std::vector<CreditCard*>::iterator iter = credit_cards_->begin();
535 iter != credit_cards_->end(); ++iter) { 533 iter != credit_cards_->end(); ++iter) {
536 if ((*iter)->guid() == credit_card.guid()) { 534 if ((*iter)->guid() == credit_card.guid()) {
537 delete *iter; 535 delete *iter;
538 *iter = new CreditCard(credit_card); 536 *iter = new CreditCard(credit_card);
539 break; 537 break;
540 } 538 }
541 } 539 }
542 540
543 wds->UpdateCreditCard(credit_card); 541 wds->UpdateCreditCard(credit_card);
544 FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged()); 542 FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged());
545 } 543 }
546 544
545 // TODO(dhollowa): Refactor to eliminate batch update of |SetCreditCards|.
546 // http://crbug.com/73068
547 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { 547 void PersonalDataManager::RemoveCreditCard(const std::string& guid) {
548 // TODO(jhawkins): Refactor SetCreditCards so this isn't so hacky.
549 std::vector<CreditCard> credit_cards(credit_cards_.size()); 548 std::vector<CreditCard> credit_cards(credit_cards_.size());
550 std::transform(credit_cards_.begin(), credit_cards_.end(), 549 std::transform(credit_cards_.begin(), credit_cards_.end(),
551 credit_cards.begin(), 550 credit_cards.begin(),
552 DereferenceFunctor<CreditCard>()); 551 DereferenceFunctor<CreditCard>());
553 552
554 // Remove the credit card that matches |guid|. 553 // Remove the credit card that matches |guid|.
555 credit_cards.erase( 554 credit_cards.erase(
556 std::remove_if(credit_cards.begin(), credit_cards.end(), 555 std::remove_if(credit_cards.begin(), credit_cards.end(),
557 FormGroupMatchesByGUIDFunctor<CreditCard>(guid)), 556 FormGroupMatchesByGUIDFunctor<CreditCard>(guid)),
558 credit_cards.end()); 557 credit_cards.end());
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 web_data_service->CancelRequest(*handle); 831 web_data_service->CancelRequest(*handle);
833 } 832 }
834 *handle = 0; 833 *handle = 0;
835 } 834 }
836 835
837 void PersonalDataManager::SaveImportedProfile( 836 void PersonalDataManager::SaveImportedProfile(
838 const AutofillProfile& imported_profile) { 837 const AutofillProfile& imported_profile) {
839 if (profile_->IsOffTheRecord()) 838 if (profile_->IsOffTheRecord())
840 return; 839 return;
841 840
842 AddProfile(imported_profile); 841 // Don't save a web profile if the data in the profile is a subset of an
842 // auxiliary profile.
843 for (std::vector<AutofillProfile*>::const_iterator iter =
844 auxiliary_profiles_.begin();
845 iter != auxiliary_profiles_.end(); ++iter) {
846 if (imported_profile.IsSubsetOf(**iter))
847 return;
848 }
849
850 std::vector<AutofillProfile> profiles;
851 MergeProfile(imported_profile, web_profiles_.get(), &profiles);
852 SetProfiles(&profiles);
843 } 853 }
844 854
845 855
846 void PersonalDataManager::SaveImportedCreditCard( 856 void PersonalDataManager::SaveImportedCreditCard(
847 const CreditCard& imported_credit_card) { 857 const CreditCard& imported_credit_card) {
848 if (profile_->IsOffTheRecord()) 858 if (profile_->IsOffTheRecord())
849 return; 859 return;
850 860
851 // Set to true if |imported_credit_card| is merged into the credit card list. 861 // Set to true if |imported_credit_card| is merged into the credit card list.
852 bool merged = false; 862 bool merged = false;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 } 926 }
917 927
918 const AutofillMetrics* PersonalDataManager::metric_logger() const { 928 const AutofillMetrics* PersonalDataManager::metric_logger() const {
919 return metric_logger_.get(); 929 return metric_logger_.get();
920 } 930 }
921 931
922 void PersonalDataManager::set_metric_logger( 932 void PersonalDataManager::set_metric_logger(
923 const AutofillMetrics* metric_logger) { 933 const AutofillMetrics* metric_logger) {
924 metric_logger_.reset(metric_logger); 934 metric_logger_.reset(metric_logger);
925 } 935 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/credit_card.cc ('k') | chrome/browser/autofill/personal_data_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698