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

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

Issue 16154031: Un-refcount AutofillWebData and TokenWebData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on ToT Created 7 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/autofill/browser/personal_data_manager.h" 5 #include "components/autofill/browser/personal_data_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <iterator> 9 #include <iterator>
10 10
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 app_locale_(app_locale), 139 app_locale_(app_locale),
140 metric_logger_(new AutofillMetrics), 140 metric_logger_(new AutofillMetrics),
141 has_logged_profile_count_(false) {} 141 has_logged_profile_count_(false) {}
142 142
143 void PersonalDataManager::Init(BrowserContext* browser_context) { 143 void PersonalDataManager::Init(BrowserContext* browser_context) {
144 browser_context_ = browser_context; 144 browser_context_ = browser_context;
145 145
146 if (!browser_context_->IsOffTheRecord()) 146 if (!browser_context_->IsOffTheRecord())
147 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); 147 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled());
148 148
149 scoped_refptr<AutofillWebDataService> autofill_data( 149 AutofillWebDataService* autofill_data =
150 AutofillWebDataService::FromBrowserContext(browser_context_)); 150 AutofillWebDataService::FromBrowserContext(browser_context_);
151 151
152 // WebDataService may not be available in tests. 152 // WebDataService may not be available in tests.
153 if (!autofill_data.get()) 153 if (!autofill_data)
154 return; 154 return;
155 155
156 LoadProfiles(); 156 LoadProfiles();
157 LoadCreditCards(); 157 LoadCreditCards();
158 158
159 autofill_data->AddObserver(this); 159 autofill_data->AddObserver(this);
160 } 160 }
161 161
162 PersonalDataManager::~PersonalDataManager() { 162 PersonalDataManager::~PersonalDataManager() {
163 CancelPendingQuery(&pending_profiles_query_); 163 CancelPendingQuery(&pending_profiles_query_);
164 CancelPendingQuery(&pending_creditcards_query_); 164 CancelPendingQuery(&pending_creditcards_query_);
165 165
166 if (!browser_context_) 166 if (!browser_context_)
167 return; 167 return;
168 168
169 scoped_refptr<AutofillWebDataService> autofill_data( 169 AutofillWebDataService* autofill_data =
170 AutofillWebDataService::FromBrowserContext(browser_context_)); 170 AutofillWebDataService::FromBrowserContext(browser_context_);
171 if (autofill_data.get()) 171 if (autofill_data)
172 autofill_data->RemoveObserver(this); 172 autofill_data->RemoveObserver(this);
173 } 173 }
174 174
175 void PersonalDataManager::OnWebDataServiceRequestDone( 175 void PersonalDataManager::OnWebDataServiceRequestDone(
176 WebDataServiceBase::Handle h, 176 WebDataServiceBase::Handle h,
177 const WDTypedResult* result) { 177 const WDTypedResult* result) {
178 DCHECK(pending_profiles_query_ || pending_creditcards_query_); 178 DCHECK(pending_profiles_query_ || pending_creditcards_query_);
179 179
180 if (!result) { 180 if (!result) {
181 // Error from the web database. 181 // Error from the web database.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 if (browser_context_->IsOffTheRecord()) 368 if (browser_context_->IsOffTheRecord())
369 return; 369 return;
370 370
371 if (profile.IsEmpty(app_locale_)) 371 if (profile.IsEmpty(app_locale_))
372 return; 372 return;
373 373
374 // Don't add an existing profile. 374 // Don't add an existing profile.
375 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) 375 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
376 return; 376 return;
377 377
378 scoped_refptr<AutofillWebDataService> autofill_data( 378 AutofillWebDataService* autofill_data =
379 AutofillWebDataService::FromBrowserContext(browser_context_)); 379 AutofillWebDataService::FromBrowserContext(browser_context_);
380 if (!autofill_data.get()) 380 if (!autofill_data)
381 return; 381 return;
382 382
383 // Don't add a duplicate. 383 // Don't add a duplicate.
384 if (FindByContents(web_profiles_, profile)) 384 if (FindByContents(web_profiles_, profile))
385 return; 385 return;
386 386
387 // Add the new profile to the web database. 387 // Add the new profile to the web database.
388 autofill_data->AddAutofillProfile(profile); 388 autofill_data->AddAutofillProfile(profile);
389 389
390 // Refresh our local cache and send notifications to observers. 390 // Refresh our local cache and send notifications to observers.
(...skipping 10 matching lines...) Expand all
401 401
402 // Don't overwrite the origin for a profile that is already stored. 402 // Don't overwrite the origin for a profile that is already stored.
403 if (existing_profile->Compare(profile) == 0) 403 if (existing_profile->Compare(profile) == 0)
404 return; 404 return;
405 405
406 if (profile.IsEmpty(app_locale_)) { 406 if (profile.IsEmpty(app_locale_)) {
407 RemoveByGUID(profile.guid()); 407 RemoveByGUID(profile.guid());
408 return; 408 return;
409 } 409 }
410 410
411 scoped_refptr<AutofillWebDataService> autofill_data( 411 AutofillWebDataService* autofill_data =
412 AutofillWebDataService::FromBrowserContext(browser_context_)); 412 AutofillWebDataService::FromBrowserContext(browser_context_);
413 if (!autofill_data.get()) 413 if (!autofill_data)
414 return; 414 return;
415 415
416 // Make the update. 416 // Make the update.
417 autofill_data->UpdateAutofillProfile(profile); 417 autofill_data->UpdateAutofillProfile(profile);
418 418
419 // Refresh our local cache and send notifications to observers. 419 // Refresh our local cache and send notifications to observers.
420 Refresh(); 420 Refresh();
421 } 421 }
422 422
423 AutofillProfile* PersonalDataManager::GetProfileByGUID( 423 AutofillProfile* PersonalDataManager::GetProfileByGUID(
(...skipping 10 matching lines...) Expand all
434 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { 434 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) {
435 if (browser_context_->IsOffTheRecord()) 435 if (browser_context_->IsOffTheRecord())
436 return; 436 return;
437 437
438 if (credit_card.IsEmpty(app_locale_)) 438 if (credit_card.IsEmpty(app_locale_))
439 return; 439 return;
440 440
441 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) 441 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
442 return; 442 return;
443 443
444 scoped_refptr<AutofillWebDataService> autofill_data( 444 AutofillWebDataService* autofill_data =
445 AutofillWebDataService::FromBrowserContext(browser_context_)); 445 AutofillWebDataService::FromBrowserContext(browser_context_);
446 if (!autofill_data.get()) 446 if (!autofill_data)
447 return; 447 return;
448 448
449 // Don't add a duplicate. 449 // Don't add a duplicate.
450 if (FindByContents(credit_cards_, credit_card)) 450 if (FindByContents(credit_cards_, credit_card))
451 return; 451 return;
452 452
453 // Add the new credit card to the web database. 453 // Add the new credit card to the web database.
454 autofill_data->AddCreditCard(credit_card); 454 autofill_data->AddCreditCard(credit_card);
455 455
456 // Refresh our local cache and send notifications to observers. 456 // Refresh our local cache and send notifications to observers.
(...skipping 10 matching lines...) Expand all
467 467
468 // Don't overwrite the origin for a credit card that is already stored. 468 // Don't overwrite the origin for a credit card that is already stored.
469 if (existing_credit_card->Compare(credit_card) == 0) 469 if (existing_credit_card->Compare(credit_card) == 0)
470 return; 470 return;
471 471
472 if (credit_card.IsEmpty(app_locale_)) { 472 if (credit_card.IsEmpty(app_locale_)) {
473 RemoveByGUID(credit_card.guid()); 473 RemoveByGUID(credit_card.guid());
474 return; 474 return;
475 } 475 }
476 476
477 scoped_refptr<AutofillWebDataService> autofill_data( 477 AutofillWebDataService* autofill_data =
478 AutofillWebDataService::FromBrowserContext(browser_context_)); 478 AutofillWebDataService::FromBrowserContext(browser_context_);
479 if (!autofill_data.get()) 479 if (!autofill_data)
480 return; 480 return;
481 481
482 // Make the update. 482 // Make the update.
483 autofill_data->UpdateCreditCard(credit_card); 483 autofill_data->UpdateCreditCard(credit_card);
484 484
485 // Refresh our local cache and send notifications to observers. 485 // Refresh our local cache and send notifications to observers.
486 Refresh(); 486 Refresh();
487 } 487 }
488 488
489 void PersonalDataManager::RemoveByGUID(const std::string& guid) { 489 void PersonalDataManager::RemoveByGUID(const std::string& guid) {
490 if (browser_context_->IsOffTheRecord()) 490 if (browser_context_->IsOffTheRecord())
491 return; 491 return;
492 492
493 bool is_credit_card = FindByGUID<CreditCard>(credit_cards_, guid); 493 bool is_credit_card = FindByGUID<CreditCard>(credit_cards_, guid);
494 bool is_profile = !is_credit_card && 494 bool is_profile = !is_credit_card &&
495 FindByGUID<AutofillProfile>(web_profiles_, guid); 495 FindByGUID<AutofillProfile>(web_profiles_, guid);
496 if (!is_credit_card && !is_profile) 496 if (!is_credit_card && !is_profile)
497 return; 497 return;
498 498
499 scoped_refptr<AutofillWebDataService> autofill_data( 499 AutofillWebDataService* autofill_data =
500 AutofillWebDataService::FromBrowserContext(browser_context_)); 500 AutofillWebDataService::FromBrowserContext(browser_context_);
501 if (!autofill_data.get()) 501 if (!autofill_data)
502 return; 502 return;
503 503
504 if (is_credit_card) 504 if (is_credit_card)
505 autofill_data->RemoveCreditCard(guid); 505 autofill_data->RemoveCreditCard(guid);
506 else 506 else
507 autofill_data->RemoveAutofillProfile(guid); 507 autofill_data->RemoveAutofillProfile(guid);
508 508
509 // Refresh our local cache and send notifications to observers. 509 // Refresh our local cache and send notifications to observers.
510 Refresh(); 510 Refresh();
511 } 511 }
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 777
778 // Ensure that profile labels are up to date. Currently, sync relies on 778 // Ensure that profile labels are up to date. Currently, sync relies on
779 // labels to identify a profile. 779 // labels to identify a profile.
780 // TODO(dhollowa): We need to deprecate labels and update the way sync 780 // TODO(dhollowa): We need to deprecate labels and update the way sync
781 // identifies profiles. 781 // identifies profiles.
782 std::vector<AutofillProfile*> profile_pointers(profiles->size()); 782 std::vector<AutofillProfile*> profile_pointers(profiles->size());
783 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), 783 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(),
784 address_of<AutofillProfile>); 784 address_of<AutofillProfile>);
785 AutofillProfile::AdjustInferredLabels(&profile_pointers); 785 AutofillProfile::AdjustInferredLabels(&profile_pointers);
786 786
787 scoped_refptr<AutofillWebDataService> autofill_data( 787 AutofillWebDataService* autofill_data =
788 AutofillWebDataService::FromBrowserContext(browser_context_)); 788 AutofillWebDataService::FromBrowserContext(browser_context_);
789 if (!autofill_data.get()) 789 if (!autofill_data)
790 return; 790 return;
791 791
792 // Any profiles that are not in the new profile list should be removed from 792 // Any profiles that are not in the new profile list should be removed from
793 // the web database. 793 // the web database.
794 for (std::vector<AutofillProfile*>::const_iterator iter = 794 for (std::vector<AutofillProfile*>::const_iterator iter =
795 web_profiles_.begin(); 795 web_profiles_.begin();
796 iter != web_profiles_.end(); ++iter) { 796 iter != web_profiles_.end(); ++iter) {
797 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) 797 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid()))
798 autofill_data->RemoveAutofillProfile((*iter)->guid()); 798 autofill_data->RemoveAutofillProfile((*iter)->guid());
799 } 799 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 831
832 // Remove empty credit cards from input. 832 // Remove empty credit cards from input.
833 for (std::vector<CreditCard>::iterator it = credit_cards->begin(); 833 for (std::vector<CreditCard>::iterator it = credit_cards->begin();
834 it != credit_cards->end();) { 834 it != credit_cards->end();) {
835 if (it->IsEmpty(app_locale_)) 835 if (it->IsEmpty(app_locale_))
836 credit_cards->erase(it); 836 credit_cards->erase(it);
837 else 837 else
838 it++; 838 it++;
839 } 839 }
840 840
841 scoped_refptr<AutofillWebDataService> autofill_data( 841 AutofillWebDataService* autofill_data =
842 AutofillWebDataService::FromBrowserContext(browser_context_)); 842 AutofillWebDataService::FromBrowserContext(browser_context_);
843 if (!autofill_data.get()) 843 if (!autofill_data)
844 return; 844 return;
845 845
846 // Any credit cards that are not in the new credit card list should be 846 // Any credit cards that are not in the new credit card list should be
847 // removed. 847 // removed.
848 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); 848 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin();
849 iter != credit_cards_.end(); ++iter) { 849 iter != credit_cards_.end(); ++iter) {
850 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) 850 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid()))
851 autofill_data->RemoveCreditCard((*iter)->guid()); 851 autofill_data->RemoveCreditCard((*iter)->guid());
852 } 852 }
853 853
(...skipping 17 matching lines...) Expand all
871 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); 871 for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
872 iter != credit_cards->end(); ++iter) { 872 iter != credit_cards->end(); ++iter) {
873 credit_cards_.push_back(new CreditCard(*iter)); 873 credit_cards_.push_back(new CreditCard(*iter));
874 } 874 }
875 875
876 // Refresh our local cache and send notifications to observers. 876 // Refresh our local cache and send notifications to observers.
877 Refresh(); 877 Refresh();
878 } 878 }
879 879
880 void PersonalDataManager::LoadProfiles() { 880 void PersonalDataManager::LoadProfiles() {
881 scoped_refptr<AutofillWebDataService> autofill_data( 881 AutofillWebDataService* autofill_data =
882 AutofillWebDataService::FromBrowserContext(browser_context_)); 882 AutofillWebDataService::FromBrowserContext(browser_context_);
883 if (!autofill_data.get()) { 883 if (!autofill_data) {
884 NOTREACHED(); 884 NOTREACHED();
885 return; 885 return;
886 } 886 }
887 887
888 CancelPendingQuery(&pending_profiles_query_); 888 CancelPendingQuery(&pending_profiles_query_);
889 889
890 pending_profiles_query_ = autofill_data->GetAutofillProfiles(this); 890 pending_profiles_query_ = autofill_data->GetAutofillProfiles(this);
891 } 891 }
892 892
893 // Win and Linux implementations do nothing. Mac and Android implementations 893 // Win and Linux implementations do nothing. Mac and Android implementations
894 // fill in the contents of |auxiliary_profiles_|. 894 // fill in the contents of |auxiliary_profiles_|.
895 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) 895 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
896 void PersonalDataManager::LoadAuxiliaryProfiles() { 896 void PersonalDataManager::LoadAuxiliaryProfiles() {
897 } 897 }
898 #endif 898 #endif
899 899
900 void PersonalDataManager::LoadCreditCards() { 900 void PersonalDataManager::LoadCreditCards() {
901 scoped_refptr<AutofillWebDataService> autofill_data( 901 AutofillWebDataService* autofill_data =
902 AutofillWebDataService::FromBrowserContext(browser_context_)); 902 AutofillWebDataService::FromBrowserContext(browser_context_);
903 if (!autofill_data.get()) { 903 if (!autofill_data) {
904 NOTREACHED(); 904 NOTREACHED();
905 return; 905 return;
906 } 906 }
907 907
908 CancelPendingQuery(&pending_creditcards_query_); 908 CancelPendingQuery(&pending_creditcards_query_);
909 909
910 pending_creditcards_query_ = autofill_data->GetCreditCards(this); 910 pending_creditcards_query_ = autofill_data->GetCreditCards(this);
911 } 911 }
912 912
913 void PersonalDataManager::ReceiveLoadedProfiles(WebDataServiceBase::Handle h, 913 void PersonalDataManager::ReceiveLoadedProfiles(WebDataServiceBase::Handle h,
(...skipping 28 matching lines...) Expand all
942 std::vector<CreditCard*> credit_cards = r->GetValue(); 942 std::vector<CreditCard*> credit_cards = r->GetValue();
943 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); 943 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin();
944 iter != credit_cards.end(); ++iter) { 944 iter != credit_cards.end(); ++iter) {
945 credit_cards_.push_back(*iter); 945 credit_cards_.push_back(*iter);
946 } 946 }
947 } 947 }
948 948
949 void PersonalDataManager::CancelPendingQuery( 949 void PersonalDataManager::CancelPendingQuery(
950 WebDataServiceBase::Handle* handle) { 950 WebDataServiceBase::Handle* handle) {
951 if (*handle) { 951 if (*handle) {
952 scoped_refptr<AutofillWebDataService> autofill_data( 952 AutofillWebDataService* autofill_data =
953 AutofillWebDataService::FromBrowserContext(browser_context_)); 953 AutofillWebDataService::FromBrowserContext(browser_context_);
954 if (!autofill_data.get()) { 954 if (!autofill_data) {
955 NOTREACHED(); 955 NOTREACHED();
956 return; 956 return;
957 } 957 }
958 autofill_data->CancelRequest(*handle); 958 autofill_data->CancelRequest(*handle);
959 } 959 }
960 *handle = 0; 960 *handle = 0;
961 } 961 }
962 962
963 void PersonalDataManager::SaveImportedProfile( 963 void PersonalDataManager::SaveImportedProfile(
964 const AutofillProfile& imported_profile) { 964 const AutofillProfile& imported_profile) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 const AutofillMetrics* metric_logger) { 1022 const AutofillMetrics* metric_logger) {
1023 metric_logger_.reset(metric_logger); 1023 metric_logger_.reset(metric_logger);
1024 } 1024 }
1025 1025
1026 void PersonalDataManager::set_browser_context( 1026 void PersonalDataManager::set_browser_context(
1027 content::BrowserContext* context) { 1027 content::BrowserContext* context) {
1028 browser_context_ = context; 1028 browser_context_ = context;
1029 } 1029 }
1030 1030
1031 } // namespace autofill 1031 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698