OLD | NEW |
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 is_data_loaded_(false), | 114 is_data_loaded_(false), |
115 pending_profiles_query_(0), | 115 pending_profiles_query_(0), |
116 pending_creditcards_query_(0), | 116 pending_creditcards_query_(0), |
117 metric_logger_(new AutofillMetrics), | 117 metric_logger_(new AutofillMetrics), |
118 has_logged_profile_count_(false) {} | 118 has_logged_profile_count_(false) {} |
119 | 119 |
120 void PersonalDataManager::Init(BrowserContext* browser_context) { | 120 void PersonalDataManager::Init(BrowserContext* browser_context) { |
121 browser_context_ = browser_context; | 121 browser_context_ = browser_context; |
122 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); | 122 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); |
123 | 123 |
124 scoped_ptr<AutofillWebDataService> autofill_data( | 124 scoped_refptr<AutofillWebDataService> autofill_data( |
125 AutofillWebDataService::FromBrowserContext(browser_context_)); | 125 AutofillWebDataService::FromBrowserContext(browser_context_)); |
126 | 126 |
127 // WebDataService may not be available in tests. | 127 // WebDataService may not be available in tests. |
128 if (!autofill_data.get()) | 128 if (!autofill_data.get()) |
129 return; | 129 return; |
130 | 130 |
131 LoadProfiles(); | 131 LoadProfiles(); |
132 LoadCreditCards(); | 132 LoadCreditCards(); |
133 | 133 |
134 notification_registrar_.Add( | 134 notification_registrar_.Add( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 PersonalDataManagerObserver* observer) { | 190 PersonalDataManagerObserver* observer) { |
191 observers_.RemoveObserver(observer); | 191 observers_.RemoveObserver(observer); |
192 } | 192 } |
193 | 193 |
194 void PersonalDataManager::Observe(int type, | 194 void PersonalDataManager::Observe(int type, |
195 const content::NotificationSource& source, | 195 const content::NotificationSource& source, |
196 const content::NotificationDetails& details) { | 196 const content::NotificationDetails& details) { |
197 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); | 197 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); |
198 | 198 |
199 if (DCHECK_IS_ON()) { | 199 if (DCHECK_IS_ON()) { |
200 scoped_ptr<AutofillWebDataService> autofill_data( | 200 scoped_refptr<AutofillWebDataService> autofill_data( |
201 AutofillWebDataService::FromBrowserContext(browser_context_)); | 201 AutofillWebDataService::FromBrowserContext(browser_context_)); |
202 | 202 |
203 DCHECK(autofill_data.get() && | 203 DCHECK(autofill_data.get() && |
204 autofill_data->GetNotificationSource() == source); | 204 autofill_data->GetNotificationSource() == source); |
205 } | 205 } |
206 | 206 |
207 Refresh(); | 207 Refresh(); |
208 } | 208 } |
209 | 209 |
210 bool PersonalDataManager::ImportFormData( | 210 bool PersonalDataManager::ImportFormData( |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 if (browser_context_->IsOffTheRecord()) | 330 if (browser_context_->IsOffTheRecord()) |
331 return; | 331 return; |
332 | 332 |
333 if (profile.IsEmpty()) | 333 if (profile.IsEmpty()) |
334 return; | 334 return; |
335 | 335 |
336 // Don't add an existing profile. | 336 // Don't add an existing profile. |
337 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) | 337 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
338 return; | 338 return; |
339 | 339 |
340 scoped_ptr<AutofillWebDataService> autofill_data( | 340 scoped_refptr<AutofillWebDataService> autofill_data( |
341 AutofillWebDataService::FromBrowserContext(browser_context_)); | 341 AutofillWebDataService::FromBrowserContext(browser_context_)); |
342 if (!autofill_data.get()) | 342 if (!autofill_data.get()) |
343 return; | 343 return; |
344 | 344 |
345 // Don't add a duplicate. | 345 // Don't add a duplicate. |
346 if (FindByContents(web_profiles_, profile)) | 346 if (FindByContents(web_profiles_, profile)) |
347 return; | 347 return; |
348 | 348 |
349 // Add the new profile to the web database. | 349 // Add the new profile to the web database. |
350 autofill_data->AddAutofillProfile(profile); | 350 autofill_data->AddAutofillProfile(profile); |
351 | 351 |
352 // Refresh our local cache and send notifications to observers. | 352 // Refresh our local cache and send notifications to observers. |
353 Refresh(); | 353 Refresh(); |
354 } | 354 } |
355 | 355 |
356 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { | 356 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { |
357 if (browser_context_->IsOffTheRecord()) | 357 if (browser_context_->IsOffTheRecord()) |
358 return; | 358 return; |
359 | 359 |
360 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) | 360 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
361 return; | 361 return; |
362 | 362 |
363 if (profile.IsEmpty()) { | 363 if (profile.IsEmpty()) { |
364 RemoveByGUID(profile.guid()); | 364 RemoveByGUID(profile.guid()); |
365 return; | 365 return; |
366 } | 366 } |
367 | 367 |
368 scoped_ptr<AutofillWebDataService> autofill_data( | 368 scoped_refptr<AutofillWebDataService> autofill_data( |
369 AutofillWebDataService::FromBrowserContext(browser_context_)); | 369 AutofillWebDataService::FromBrowserContext(browser_context_)); |
370 if (!autofill_data.get()) | 370 if (!autofill_data.get()) |
371 return; | 371 return; |
372 | 372 |
373 // Make the update. | 373 // Make the update. |
374 autofill_data->UpdateAutofillProfile(profile); | 374 autofill_data->UpdateAutofillProfile(profile); |
375 | 375 |
376 // Refresh our local cache and send notifications to observers. | 376 // Refresh our local cache and send notifications to observers. |
377 Refresh(); | 377 Refresh(); |
378 } | 378 } |
(...skipping 12 matching lines...) Expand all Loading... |
391 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { | 391 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { |
392 if (browser_context_->IsOffTheRecord()) | 392 if (browser_context_->IsOffTheRecord()) |
393 return; | 393 return; |
394 | 394 |
395 if (credit_card.IsEmpty()) | 395 if (credit_card.IsEmpty()) |
396 return; | 396 return; |
397 | 397 |
398 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) | 398 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
399 return; | 399 return; |
400 | 400 |
401 scoped_ptr<AutofillWebDataService> autofill_data( | 401 scoped_refptr<AutofillWebDataService> autofill_data( |
402 AutofillWebDataService::FromBrowserContext(browser_context_)); | 402 AutofillWebDataService::FromBrowserContext(browser_context_)); |
403 if (!autofill_data.get()) | 403 if (!autofill_data.get()) |
404 return; | 404 return; |
405 | 405 |
406 // Don't add a duplicate. | 406 // Don't add a duplicate. |
407 if (FindByContents(credit_cards_, credit_card)) | 407 if (FindByContents(credit_cards_, credit_card)) |
408 return; | 408 return; |
409 | 409 |
410 // Add the new credit card to the web database. | 410 // Add the new credit card to the web database. |
411 autofill_data->AddCreditCard(credit_card); | 411 autofill_data->AddCreditCard(credit_card); |
412 | 412 |
413 // Refresh our local cache and send notifications to observers. | 413 // Refresh our local cache and send notifications to observers. |
414 Refresh(); | 414 Refresh(); |
415 } | 415 } |
416 | 416 |
417 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { | 417 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { |
418 if (browser_context_->IsOffTheRecord()) | 418 if (browser_context_->IsOffTheRecord()) |
419 return; | 419 return; |
420 | 420 |
421 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) | 421 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
422 return; | 422 return; |
423 | 423 |
424 if (credit_card.IsEmpty()) { | 424 if (credit_card.IsEmpty()) { |
425 RemoveByGUID(credit_card.guid()); | 425 RemoveByGUID(credit_card.guid()); |
426 return; | 426 return; |
427 } | 427 } |
428 | 428 |
429 scoped_ptr<AutofillWebDataService> autofill_data( | 429 scoped_refptr<AutofillWebDataService> autofill_data( |
430 AutofillWebDataService::FromBrowserContext(browser_context_)); | 430 AutofillWebDataService::FromBrowserContext(browser_context_)); |
431 if (!autofill_data.get()) | 431 if (!autofill_data.get()) |
432 return; | 432 return; |
433 | 433 |
434 // Make the update. | 434 // Make the update. |
435 autofill_data->UpdateCreditCard(credit_card); | 435 autofill_data->UpdateCreditCard(credit_card); |
436 | 436 |
437 // Refresh our local cache and send notifications to observers. | 437 // Refresh our local cache and send notifications to observers. |
438 Refresh(); | 438 Refresh(); |
439 } | 439 } |
440 | 440 |
441 void PersonalDataManager::RemoveByGUID(const std::string& guid) { | 441 void PersonalDataManager::RemoveByGUID(const std::string& guid) { |
442 if (browser_context_->IsOffTheRecord()) | 442 if (browser_context_->IsOffTheRecord()) |
443 return; | 443 return; |
444 | 444 |
445 bool is_credit_card = FindByGUID<CreditCard>(credit_cards_, guid); | 445 bool is_credit_card = FindByGUID<CreditCard>(credit_cards_, guid); |
446 bool is_profile = !is_credit_card && | 446 bool is_profile = !is_credit_card && |
447 FindByGUID<AutofillProfile>(web_profiles_, guid); | 447 FindByGUID<AutofillProfile>(web_profiles_, guid); |
448 if (!is_credit_card && !is_profile) | 448 if (!is_credit_card && !is_profile) |
449 return; | 449 return; |
450 | 450 |
451 scoped_ptr<AutofillWebDataService> autofill_data( | 451 scoped_refptr<AutofillWebDataService> autofill_data( |
452 AutofillWebDataService::FromBrowserContext(browser_context_)); | 452 AutofillWebDataService::FromBrowserContext(browser_context_)); |
453 if (!autofill_data.get()) | 453 if (!autofill_data.get()) |
454 return; | 454 return; |
455 | 455 |
456 if (is_credit_card) | 456 if (is_credit_card) |
457 autofill_data->RemoveCreditCard(guid); | 457 autofill_data->RemoveCreditCard(guid); |
458 else | 458 else |
459 autofill_data->RemoveAutofillProfile(guid); | 459 autofill_data->RemoveAutofillProfile(guid); |
460 | 460 |
461 // Refresh our local cache and send notifications to observers. | 461 // Refresh our local cache and send notifications to observers. |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 | 713 |
714 // Ensure that profile labels are up to date. Currently, sync relies on | 714 // Ensure that profile labels are up to date. Currently, sync relies on |
715 // labels to identify a profile. | 715 // labels to identify a profile. |
716 // TODO(dhollowa): We need to deprecate labels and update the way sync | 716 // TODO(dhollowa): We need to deprecate labels and update the way sync |
717 // identifies profiles. | 717 // identifies profiles. |
718 std::vector<AutofillProfile*> profile_pointers(profiles->size()); | 718 std::vector<AutofillProfile*> profile_pointers(profiles->size()); |
719 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), | 719 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), |
720 address_of<AutofillProfile>); | 720 address_of<AutofillProfile>); |
721 AutofillProfile::AdjustInferredLabels(&profile_pointers); | 721 AutofillProfile::AdjustInferredLabels(&profile_pointers); |
722 | 722 |
723 scoped_ptr<AutofillWebDataService> autofill_data( | 723 scoped_refptr<AutofillWebDataService> autofill_data( |
724 AutofillWebDataService::FromBrowserContext(browser_context_)); | 724 AutofillWebDataService::FromBrowserContext(browser_context_)); |
725 if (!autofill_data.get()) | 725 if (!autofill_data.get()) |
726 return; | 726 return; |
727 | 727 |
728 // Any profiles that are not in the new profile list should be removed from | 728 // Any profiles that are not in the new profile list should be removed from |
729 // the web database. | 729 // the web database. |
730 for (std::vector<AutofillProfile*>::const_iterator iter = | 730 for (std::vector<AutofillProfile*>::const_iterator iter = |
731 web_profiles_.begin(); | 731 web_profiles_.begin(); |
732 iter != web_profiles_.end(); ++iter) { | 732 iter != web_profiles_.end(); ++iter) { |
733 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) | 733 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 if (browser_context_->IsOffTheRecord()) | 765 if (browser_context_->IsOffTheRecord()) |
766 return; | 766 return; |
767 | 767 |
768 // Remove empty credit cards from input. | 768 // Remove empty credit cards from input. |
769 credit_cards->erase( | 769 credit_cards->erase( |
770 std::remove_if( | 770 std::remove_if( |
771 credit_cards->begin(), credit_cards->end(), | 771 credit_cards->begin(), credit_cards->end(), |
772 std::mem_fun_ref(&CreditCard::IsEmpty)), | 772 std::mem_fun_ref(&CreditCard::IsEmpty)), |
773 credit_cards->end()); | 773 credit_cards->end()); |
774 | 774 |
775 scoped_ptr<AutofillWebDataService> autofill_data( | 775 scoped_refptr<AutofillWebDataService> autofill_data( |
776 AutofillWebDataService::FromBrowserContext(browser_context_)); | 776 AutofillWebDataService::FromBrowserContext(browser_context_)); |
777 if (!autofill_data.get()) | 777 if (!autofill_data.get()) |
778 return; | 778 return; |
779 | 779 |
780 // Any credit cards that are not in the new credit card list should be | 780 // Any credit cards that are not in the new credit card list should be |
781 // removed. | 781 // removed. |
782 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); | 782 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); |
783 iter != credit_cards_.end(); ++iter) { | 783 iter != credit_cards_.end(); ++iter) { |
784 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) | 784 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) |
785 autofill_data->RemoveCreditCard((*iter)->guid()); | 785 autofill_data->RemoveCreditCard((*iter)->guid()); |
(...skipping 19 matching lines...) Expand all Loading... |
805 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 805 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
806 iter != credit_cards->end(); ++iter) { | 806 iter != credit_cards->end(); ++iter) { |
807 credit_cards_.push_back(new CreditCard(*iter)); | 807 credit_cards_.push_back(new CreditCard(*iter)); |
808 } | 808 } |
809 | 809 |
810 // Refresh our local cache and send notifications to observers. | 810 // Refresh our local cache and send notifications to observers. |
811 Refresh(); | 811 Refresh(); |
812 } | 812 } |
813 | 813 |
814 void PersonalDataManager::LoadProfiles() { | 814 void PersonalDataManager::LoadProfiles() { |
815 scoped_ptr<AutofillWebDataService> autofill_data( | 815 scoped_refptr<AutofillWebDataService> autofill_data( |
816 AutofillWebDataService::FromBrowserContext(browser_context_)); | 816 AutofillWebDataService::FromBrowserContext(browser_context_)); |
817 if (!autofill_data.get()) { | 817 if (!autofill_data.get()) { |
818 NOTREACHED(); | 818 NOTREACHED(); |
819 return; | 819 return; |
820 } | 820 } |
821 | 821 |
822 CancelPendingQuery(&pending_profiles_query_); | 822 CancelPendingQuery(&pending_profiles_query_); |
823 | 823 |
824 pending_profiles_query_ = autofill_data->GetAutofillProfiles(this); | 824 pending_profiles_query_ = autofill_data->GetAutofillProfiles(this); |
825 } | 825 } |
826 | 826 |
827 // Win and Linux implementations do nothing. Mac implementation fills in the | 827 // Win and Linux implementations do nothing. Mac implementation fills in the |
828 // contents of |auxiliary_profiles_|. | 828 // contents of |auxiliary_profiles_|. |
829 #if !defined(OS_MACOSX) | 829 #if !defined(OS_MACOSX) |
830 void PersonalDataManager::LoadAuxiliaryProfiles() { | 830 void PersonalDataManager::LoadAuxiliaryProfiles() { |
831 } | 831 } |
832 #endif | 832 #endif |
833 | 833 |
834 void PersonalDataManager::LoadCreditCards() { | 834 void PersonalDataManager::LoadCreditCards() { |
835 scoped_ptr<AutofillWebDataService> autofill_data( | 835 scoped_refptr<AutofillWebDataService> autofill_data( |
836 AutofillWebDataService::FromBrowserContext(browser_context_)); | 836 AutofillWebDataService::FromBrowserContext(browser_context_)); |
837 if (!autofill_data.get()) { | 837 if (!autofill_data.get()) { |
838 NOTREACHED(); | 838 NOTREACHED(); |
839 return; | 839 return; |
840 } | 840 } |
841 | 841 |
842 CancelPendingQuery(&pending_creditcards_query_); | 842 CancelPendingQuery(&pending_creditcards_query_); |
843 | 843 |
844 pending_creditcards_query_ = autofill_data->GetCreditCards(this); | 844 pending_creditcards_query_ = autofill_data->GetCreditCards(this); |
845 } | 845 } |
(...skipping 30 matching lines...) Expand all Loading... |
876 std::vector<CreditCard*> credit_cards = r->GetValue(); | 876 std::vector<CreditCard*> credit_cards = r->GetValue(); |
877 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); | 877 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); |
878 iter != credit_cards.end(); ++iter) { | 878 iter != credit_cards.end(); ++iter) { |
879 credit_cards_.push_back(*iter); | 879 credit_cards_.push_back(*iter); |
880 } | 880 } |
881 } | 881 } |
882 | 882 |
883 void PersonalDataManager::CancelPendingQuery( | 883 void PersonalDataManager::CancelPendingQuery( |
884 WebDataServiceBase::Handle* handle) { | 884 WebDataServiceBase::Handle* handle) { |
885 if (*handle) { | 885 if (*handle) { |
886 scoped_ptr<AutofillWebDataService> autofill_data( | 886 scoped_refptr<AutofillWebDataService> autofill_data( |
887 AutofillWebDataService::FromBrowserContext(browser_context_)); | 887 AutofillWebDataService::FromBrowserContext(browser_context_)); |
888 if (!autofill_data.get()) { | 888 if (!autofill_data.get()) { |
889 NOTREACHED(); | 889 NOTREACHED(); |
890 return; | 890 return; |
891 } | 891 } |
892 autofill_data->CancelRequest(*handle); | 892 autofill_data->CancelRequest(*handle); |
893 } | 893 } |
894 *handle = 0; | 894 *handle = 0; |
895 } | 895 } |
896 | 896 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 | 963 |
964 void PersonalDataManager::set_metric_logger( | 964 void PersonalDataManager::set_metric_logger( |
965 const AutofillMetrics* metric_logger) { | 965 const AutofillMetrics* metric_logger) { |
966 metric_logger_.reset(metric_logger); | 966 metric_logger_.reset(metric_logger); |
967 } | 967 } |
968 | 968 |
969 void PersonalDataManager::set_browser_context( | 969 void PersonalDataManager::set_browser_context( |
970 content::BrowserContext* context) { | 970 content::BrowserContext* context) { |
971 browser_context_ = context; | 971 browser_context_ = context; |
972 } | 972 } |
OLD | NEW |