OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/core/browser/personal_data_manager.h" | 5 #include "components/autofill/core/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 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "components/autofill/core/browser/autofill-inl.h" | 17 #include "components/autofill/core/browser/autofill-inl.h" |
18 #include "components/autofill/core/browser/autofill_country.h" | 18 #include "components/autofill/core/browser/autofill_country.h" |
19 #include "components/autofill/core/browser/autofill_field.h" | 19 #include "components/autofill/core/browser/autofill_field.h" |
20 #include "components/autofill/core/browser/autofill_metrics.h" | 20 #include "components/autofill/core/browser/autofill_metrics.h" |
21 #include "components/autofill/core/browser/form_structure.h" | 21 #include "components/autofill/core/browser/form_structure.h" |
22 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 22 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
23 #include "components/autofill/core/browser/phone_number.h" | 23 #include "components/autofill/core/browser/phone_number.h" |
24 #include "components/autofill/core/browser/phone_number_i18n.h" | 24 #include "components/autofill/core/browser/phone_number_i18n.h" |
25 #include "components/autofill/core/browser/validation.h" | 25 #include "components/autofill/core/browser/validation.h" |
26 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 26 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
27 #include "components/autofill/core/common/autofill_pref_names.h" | 27 #include "components/autofill/core/common/autofill_pref_names.h" |
28 #include "content/public/browser/browser_context.h" | |
29 | 28 |
30 namespace autofill { | 29 namespace autofill { |
31 namespace { | 30 namespace { |
32 | 31 |
33 const base::string16::value_type kCreditCardPrefix[] = {'*', 0}; | 32 const base::string16::value_type kCreditCardPrefix[] = {'*', 0}; |
34 | 33 |
35 template<typename T> | 34 template<typename T> |
36 class FormGroupMatchesByGUIDFunctor { | 35 class FormGroupMatchesByGUIDFunctor { |
37 public: | 36 public: |
38 explicit FormGroupMatchesByGUIDFunctor(const std::string& guid) | 37 explicit FormGroupMatchesByGUIDFunctor(const std::string& guid) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 | 139 |
141 // A helper function for finding the maximum value in a string->int map. | 140 // A helper function for finding the maximum value in a string->int map. |
142 static bool CompareVotes(const std::pair<std::string, int>& a, | 141 static bool CompareVotes(const std::pair<std::string, int>& a, |
143 const std::pair<std::string, int>& b) { | 142 const std::pair<std::string, int>& b) { |
144 return a.second < b.second; | 143 return a.second < b.second; |
145 } | 144 } |
146 | 145 |
147 } // namespace | 146 } // namespace |
148 | 147 |
149 PersonalDataManager::PersonalDataManager(const std::string& app_locale) | 148 PersonalDataManager::PersonalDataManager(const std::string& app_locale) |
150 : browser_context_(NULL), | 149 : autofill_webdata_(NULL), |
151 is_data_loaded_(false), | 150 is_data_loaded_(false), |
152 pending_profiles_query_(0), | 151 pending_profiles_query_(0), |
153 pending_creditcards_query_(0), | 152 pending_creditcards_query_(0), |
154 app_locale_(app_locale), | 153 app_locale_(app_locale), |
155 metric_logger_(new AutofillMetrics), | 154 metric_logger_(new AutofillMetrics), |
156 is_off_the_record_(false), | 155 is_off_the_record_(false), |
157 has_logged_profile_count_(false) {} | 156 has_logged_profile_count_(false) {} |
158 | 157 |
159 void PersonalDataManager::Init(content::BrowserContext* browser_context, | 158 void PersonalDataManager::Init( |
160 PrefService* pref_service, | 159 scoped_refptr<AutofillWebDataService> autofill_webdata, |
161 bool is_off_the_record) { | 160 PrefService* pref_service, |
162 browser_context_ = browser_context; | 161 bool is_off_the_record) { |
162 autofill_webdata_ = autofill_webdata; | |
163 pref_service_ = pref_service; | 163 pref_service_ = pref_service; |
164 is_off_the_record_ = is_off_the_record; | 164 is_off_the_record_ = is_off_the_record; |
165 | 165 |
166 if (!is_off_the_record_) | 166 if (!is_off_the_record_) |
167 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); | 167 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); |
168 | 168 |
169 scoped_refptr<AutofillWebDataService> autofill_data( | |
170 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
171 | |
172 // WebDataService may not be available in tests. | 169 // WebDataService may not be available in tests. |
Ilya Sherman
2013/11/14 02:22:02
Out of curiousity, do you know whether this is com
blundell
2013/11/14 16:46:30
Found the offenders (at least in unit_tests) by pu
| |
173 if (!autofill_data.get()) | 170 if (!autofill_webdata_.get()) |
174 return; | 171 return; |
175 | 172 |
176 LoadProfiles(); | 173 LoadProfiles(); |
177 LoadCreditCards(); | 174 LoadCreditCards(); |
178 | 175 |
179 autofill_data->AddObserver(this); | 176 autofill_webdata_->AddObserver(this); |
180 } | 177 } |
181 | 178 |
182 PersonalDataManager::~PersonalDataManager() { | 179 PersonalDataManager::~PersonalDataManager() { |
183 CancelPendingQuery(&pending_profiles_query_); | 180 CancelPendingQuery(&pending_profiles_query_); |
184 CancelPendingQuery(&pending_creditcards_query_); | 181 CancelPendingQuery(&pending_creditcards_query_); |
185 | 182 |
186 if (!browser_context_) | 183 if (autofill_webdata_.get()) |
187 return; | 184 autofill_webdata_->RemoveObserver(this); |
188 | |
189 scoped_refptr<AutofillWebDataService> autofill_data( | |
190 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
191 if (autofill_data.get()) | |
192 autofill_data->RemoveObserver(this); | |
193 } | 185 } |
194 | 186 |
195 void PersonalDataManager::OnWebDataServiceRequestDone( | 187 void PersonalDataManager::OnWebDataServiceRequestDone( |
196 WebDataServiceBase::Handle h, | 188 WebDataServiceBase::Handle h, |
197 const WDTypedResult* result) { | 189 const WDTypedResult* result) { |
198 DCHECK(pending_profiles_query_ || pending_creditcards_query_); | 190 DCHECK(pending_profiles_query_ || pending_creditcards_query_); |
199 | 191 |
200 if (!result) { | 192 if (!result) { |
201 // Error from the web database. | 193 // Error from the web database. |
202 if (h == pending_creditcards_query_) | 194 if (h == pending_creditcards_query_) |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 if (is_off_the_record_) | 380 if (is_off_the_record_) |
389 return; | 381 return; |
390 | 382 |
391 if (profile.IsEmpty(app_locale_)) | 383 if (profile.IsEmpty(app_locale_)) |
392 return; | 384 return; |
393 | 385 |
394 // Don't add an existing profile. | 386 // Don't add an existing profile. |
395 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) | 387 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
396 return; | 388 return; |
397 | 389 |
398 scoped_refptr<AutofillWebDataService> autofill_data( | 390 if (!autofill_webdata_.get()) |
399 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
400 if (!autofill_data.get()) | |
401 return; | 391 return; |
402 | 392 |
403 // Don't add a duplicate. | 393 // Don't add a duplicate. |
404 if (FindByContents(web_profiles_, profile)) | 394 if (FindByContents(web_profiles_, profile)) |
405 return; | 395 return; |
406 | 396 |
407 // Add the new profile to the web database. | 397 // Add the new profile to the web database. |
408 autofill_data->AddAutofillProfile(profile); | 398 autofill_webdata_->AddAutofillProfile(profile); |
409 | 399 |
410 // Refresh our local cache and send notifications to observers. | 400 // Refresh our local cache and send notifications to observers. |
411 Refresh(); | 401 Refresh(); |
412 } | 402 } |
413 | 403 |
414 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { | 404 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { |
415 if (is_off_the_record_) | 405 if (is_off_the_record_) |
416 return; | 406 return; |
417 | 407 |
418 AutofillProfile* existing_profile = GetProfileByGUID(profile.guid()); | 408 AutofillProfile* existing_profile = GetProfileByGUID(profile.guid()); |
419 if (!existing_profile) | 409 if (!existing_profile) |
420 return; | 410 return; |
421 | 411 |
422 // Don't overwrite the origin for a profile that is already stored. | 412 // Don't overwrite the origin for a profile that is already stored. |
423 if (existing_profile->Compare(profile) == 0) | 413 if (existing_profile->Compare(profile) == 0) |
424 return; | 414 return; |
425 | 415 |
426 if (profile.IsEmpty(app_locale_)) { | 416 if (profile.IsEmpty(app_locale_)) { |
427 RemoveByGUID(profile.guid()); | 417 RemoveByGUID(profile.guid()); |
428 return; | 418 return; |
429 } | 419 } |
430 | 420 |
431 scoped_refptr<AutofillWebDataService> autofill_data( | 421 if (!autofill_webdata_.get()) |
432 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
433 if (!autofill_data.get()) | |
434 return; | 422 return; |
435 | 423 |
436 // Make the update. | 424 // Make the update. |
437 autofill_data->UpdateAutofillProfile(profile); | 425 autofill_webdata_->UpdateAutofillProfile(profile); |
438 | 426 |
439 // Refresh our local cache and send notifications to observers. | 427 // Refresh our local cache and send notifications to observers. |
440 Refresh(); | 428 Refresh(); |
441 } | 429 } |
442 | 430 |
443 AutofillProfile* PersonalDataManager::GetProfileByGUID( | 431 AutofillProfile* PersonalDataManager::GetProfileByGUID( |
444 const std::string& guid) { | 432 const std::string& guid) { |
445 const std::vector<AutofillProfile*>& profiles = GetProfiles(); | 433 const std::vector<AutofillProfile*>& profiles = GetProfiles(); |
446 std::vector<AutofillProfile*>::const_iterator iter = | 434 std::vector<AutofillProfile*>::const_iterator iter = |
447 FindElementByGUID<AutofillProfile>(profiles, guid); | 435 FindElementByGUID<AutofillProfile>(profiles, guid); |
448 return (iter != profiles.end()) ? *iter : NULL; | 436 return (iter != profiles.end()) ? *iter : NULL; |
449 } | 437 } |
450 | 438 |
451 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { | 439 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { |
452 if (is_off_the_record_) | 440 if (is_off_the_record_) |
453 return; | 441 return; |
454 | 442 |
455 if (credit_card.IsEmpty(app_locale_)) | 443 if (credit_card.IsEmpty(app_locale_)) |
456 return; | 444 return; |
457 | 445 |
458 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) | 446 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
459 return; | 447 return; |
460 | 448 |
461 scoped_refptr<AutofillWebDataService> autofill_data( | 449 if (!autofill_webdata_.get()) |
462 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
463 if (!autofill_data.get()) | |
464 return; | 450 return; |
465 | 451 |
466 // Don't add a duplicate. | 452 // Don't add a duplicate. |
467 if (FindByContents(credit_cards_, credit_card)) | 453 if (FindByContents(credit_cards_, credit_card)) |
468 return; | 454 return; |
469 | 455 |
470 // Add the new credit card to the web database. | 456 // Add the new credit card to the web database. |
471 autofill_data->AddCreditCard(credit_card); | 457 autofill_webdata_->AddCreditCard(credit_card); |
472 | 458 |
473 // Refresh our local cache and send notifications to observers. | 459 // Refresh our local cache and send notifications to observers. |
474 Refresh(); | 460 Refresh(); |
475 } | 461 } |
476 | 462 |
477 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { | 463 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { |
478 if (is_off_the_record_) | 464 if (is_off_the_record_) |
479 return; | 465 return; |
480 | 466 |
481 CreditCard* existing_credit_card = GetCreditCardByGUID(credit_card.guid()); | 467 CreditCard* existing_credit_card = GetCreditCardByGUID(credit_card.guid()); |
482 if (!existing_credit_card) | 468 if (!existing_credit_card) |
483 return; | 469 return; |
484 | 470 |
485 // Don't overwrite the origin for a credit card that is already stored. | 471 // Don't overwrite the origin for a credit card that is already stored. |
486 if (existing_credit_card->Compare(credit_card) == 0) | 472 if (existing_credit_card->Compare(credit_card) == 0) |
487 return; | 473 return; |
488 | 474 |
489 if (credit_card.IsEmpty(app_locale_)) { | 475 if (credit_card.IsEmpty(app_locale_)) { |
490 RemoveByGUID(credit_card.guid()); | 476 RemoveByGUID(credit_card.guid()); |
491 return; | 477 return; |
492 } | 478 } |
493 | 479 |
494 scoped_refptr<AutofillWebDataService> autofill_data( | 480 if (!autofill_webdata_.get()) |
495 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
496 if (!autofill_data.get()) | |
497 return; | 481 return; |
498 | 482 |
499 // Make the update. | 483 // Make the update. |
500 autofill_data->UpdateCreditCard(credit_card); | 484 autofill_webdata_->UpdateCreditCard(credit_card); |
501 | 485 |
502 // Refresh our local cache and send notifications to observers. | 486 // Refresh our local cache and send notifications to observers. |
503 Refresh(); | 487 Refresh(); |
504 } | 488 } |
505 | 489 |
506 void PersonalDataManager::RemoveByGUID(const std::string& guid) { | 490 void PersonalDataManager::RemoveByGUID(const std::string& guid) { |
507 if (is_off_the_record_) | 491 if (is_off_the_record_) |
508 return; | 492 return; |
509 | 493 |
510 bool is_credit_card = FindByGUID<CreditCard>(credit_cards_, guid); | 494 bool is_credit_card = FindByGUID<CreditCard>(credit_cards_, guid); |
511 bool is_profile = !is_credit_card && | 495 bool is_profile = !is_credit_card && |
512 FindByGUID<AutofillProfile>(web_profiles_, guid); | 496 FindByGUID<AutofillProfile>(web_profiles_, guid); |
513 if (!is_credit_card && !is_profile) | 497 if (!is_credit_card && !is_profile) |
514 return; | 498 return; |
515 | 499 |
516 scoped_refptr<AutofillWebDataService> autofill_data( | 500 if (!autofill_webdata_.get()) |
517 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
518 if (!autofill_data.get()) | |
519 return; | 501 return; |
520 | 502 |
521 if (is_credit_card) | 503 if (is_credit_card) |
522 autofill_data->RemoveCreditCard(guid); | 504 autofill_webdata_->RemoveCreditCard(guid); |
523 else | 505 else |
524 autofill_data->RemoveAutofillProfile(guid); | 506 autofill_webdata_->RemoveAutofillProfile(guid); |
525 | 507 |
526 // Refresh our local cache and send notifications to observers. | 508 // Refresh our local cache and send notifications to observers. |
527 Refresh(); | 509 Refresh(); |
528 } | 510 } |
529 | 511 |
530 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { | 512 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { |
531 const std::vector<CreditCard*>& credit_cards = GetCreditCards(); | 513 const std::vector<CreditCard*>& credit_cards = GetCreditCards(); |
532 std::vector<CreditCard*>::const_iterator iter = | 514 std::vector<CreditCard*>::const_iterator iter = |
533 FindElementByGUID<CreditCard>(credit_cards, guid); | 515 FindElementByGUID<CreditCard>(credit_cards, guid); |
534 return (iter != credit_cards.end()) ? *iter : NULL; | 516 return (iter != credit_cards.end()) ? *iter : NULL; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
797 | 779 |
798 // Ensure that profile labels are up to date. Currently, sync relies on | 780 // Ensure that profile labels are up to date. Currently, sync relies on |
799 // labels to identify a profile. | 781 // labels to identify a profile. |
800 // TODO(dhollowa): We need to deprecate labels and update the way sync | 782 // TODO(dhollowa): We need to deprecate labels and update the way sync |
801 // identifies profiles. | 783 // identifies profiles. |
802 std::vector<AutofillProfile*> profile_pointers(profiles->size()); | 784 std::vector<AutofillProfile*> profile_pointers(profiles->size()); |
803 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), | 785 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), |
804 address_of<AutofillProfile>); | 786 address_of<AutofillProfile>); |
805 AutofillProfile::AdjustInferredLabels(&profile_pointers); | 787 AutofillProfile::AdjustInferredLabels(&profile_pointers); |
806 | 788 |
807 scoped_refptr<AutofillWebDataService> autofill_data( | 789 if (!autofill_webdata_.get()) |
808 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
809 if (!autofill_data.get()) | |
810 return; | 790 return; |
811 | 791 |
812 // 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 |
813 // the web database. | 793 // the web database. |
814 for (std::vector<AutofillProfile*>::const_iterator iter = | 794 for (std::vector<AutofillProfile*>::const_iterator iter = |
815 web_profiles_.begin(); | 795 web_profiles_.begin(); |
816 iter != web_profiles_.end(); ++iter) { | 796 iter != web_profiles_.end(); ++iter) { |
817 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) | 797 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) |
818 autofill_data->RemoveAutofillProfile((*iter)->guid()); | 798 autofill_webdata_->RemoveAutofillProfile((*iter)->guid()); |
819 } | 799 } |
820 | 800 |
821 // Update the web database with the existing profiles. | 801 // Update the web database with the existing profiles. |
822 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); | 802 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); |
823 iter != profiles->end(); ++iter) { | 803 iter != profiles->end(); ++iter) { |
824 if (FindByGUID<AutofillProfile>(web_profiles_, iter->guid())) | 804 if (FindByGUID<AutofillProfile>(web_profiles_, iter->guid())) |
825 autofill_data->UpdateAutofillProfile(*iter); | 805 autofill_webdata_->UpdateAutofillProfile(*iter); |
826 } | 806 } |
827 | 807 |
828 // Add the new profiles to the web database. Don't add a duplicate. | 808 // Add the new profiles to the web database. Don't add a duplicate. |
829 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); | 809 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); |
830 iter != profiles->end(); ++iter) { | 810 iter != profiles->end(); ++iter) { |
831 if (!FindByGUID<AutofillProfile>(web_profiles_, iter->guid()) && | 811 if (!FindByGUID<AutofillProfile>(web_profiles_, iter->guid()) && |
832 !FindByContents(web_profiles_, *iter)) | 812 !FindByContents(web_profiles_, *iter)) |
833 autofill_data->AddAutofillProfile(*iter); | 813 autofill_webdata_->AddAutofillProfile(*iter); |
834 } | 814 } |
835 | 815 |
836 // Copy in the new profiles. | 816 // Copy in the new profiles. |
837 web_profiles_.clear(); | 817 web_profiles_.clear(); |
838 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); | 818 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); |
839 iter != profiles->end(); ++iter) { | 819 iter != profiles->end(); ++iter) { |
840 web_profiles_.push_back(new AutofillProfile(*iter)); | 820 web_profiles_.push_back(new AutofillProfile(*iter)); |
841 } | 821 } |
842 | 822 |
843 // Refresh our local cache and send notifications to observers. | 823 // Refresh our local cache and send notifications to observers. |
844 Refresh(); | 824 Refresh(); |
845 } | 825 } |
846 | 826 |
847 void PersonalDataManager::SetCreditCards( | 827 void PersonalDataManager::SetCreditCards( |
848 std::vector<CreditCard>* credit_cards) { | 828 std::vector<CreditCard>* credit_cards) { |
849 if (is_off_the_record_) | 829 if (is_off_the_record_) |
850 return; | 830 return; |
851 | 831 |
852 // Remove empty credit cards from input. | 832 // Remove empty credit cards from input. |
853 credit_cards->erase(std::remove_if(credit_cards->begin(), credit_cards->end(), | 833 credit_cards->erase(std::remove_if(credit_cards->begin(), credit_cards->end(), |
854 IsEmptyFunctor<CreditCard>(app_locale_)), | 834 IsEmptyFunctor<CreditCard>(app_locale_)), |
855 credit_cards->end()); | 835 credit_cards->end()); |
856 | 836 |
857 scoped_refptr<AutofillWebDataService> autofill_data( | 837 if (!autofill_webdata_.get()) |
858 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
859 if (!autofill_data.get()) | |
860 return; | 838 return; |
861 | 839 |
862 // Any credit cards that are not in the new credit card list should be | 840 // Any credit cards that are not in the new credit card list should be |
863 // removed. | 841 // removed. |
864 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); | 842 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); |
865 iter != credit_cards_.end(); ++iter) { | 843 iter != credit_cards_.end(); ++iter) { |
866 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) | 844 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) |
867 autofill_data->RemoveCreditCard((*iter)->guid()); | 845 autofill_webdata_->RemoveCreditCard((*iter)->guid()); |
868 } | 846 } |
869 | 847 |
870 // Update the web database with the existing credit cards. | 848 // Update the web database with the existing credit cards. |
871 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 849 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
872 iter != credit_cards->end(); ++iter) { | 850 iter != credit_cards->end(); ++iter) { |
873 if (FindByGUID<CreditCard>(credit_cards_, iter->guid())) | 851 if (FindByGUID<CreditCard>(credit_cards_, iter->guid())) |
874 autofill_data->UpdateCreditCard(*iter); | 852 autofill_webdata_->UpdateCreditCard(*iter); |
875 } | 853 } |
876 | 854 |
877 // Add the new credit cards to the web database. Don't add a duplicate. | 855 // Add the new credit cards to the web database. Don't add a duplicate. |
878 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 856 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
879 iter != credit_cards->end(); ++iter) { | 857 iter != credit_cards->end(); ++iter) { |
880 if (!FindByGUID<CreditCard>(credit_cards_, iter->guid()) && | 858 if (!FindByGUID<CreditCard>(credit_cards_, iter->guid()) && |
881 !FindByContents(credit_cards_, *iter)) | 859 !FindByContents(credit_cards_, *iter)) |
882 autofill_data->AddCreditCard(*iter); | 860 autofill_webdata_->AddCreditCard(*iter); |
883 } | 861 } |
884 | 862 |
885 // Copy in the new credit cards. | 863 // Copy in the new credit cards. |
886 credit_cards_.clear(); | 864 credit_cards_.clear(); |
887 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 865 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
888 iter != credit_cards->end(); ++iter) { | 866 iter != credit_cards->end(); ++iter) { |
889 credit_cards_.push_back(new CreditCard(*iter)); | 867 credit_cards_.push_back(new CreditCard(*iter)); |
890 } | 868 } |
891 | 869 |
892 // Refresh our local cache and send notifications to observers. | 870 // Refresh our local cache and send notifications to observers. |
893 Refresh(); | 871 Refresh(); |
894 } | 872 } |
895 | 873 |
896 void PersonalDataManager::LoadProfiles() { | 874 void PersonalDataManager::LoadProfiles() { |
897 scoped_refptr<AutofillWebDataService> autofill_data( | 875 if (!autofill_webdata_.get()) { |
898 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
899 if (!autofill_data.get()) { | |
900 NOTREACHED(); | 876 NOTREACHED(); |
901 return; | 877 return; |
902 } | 878 } |
903 | 879 |
904 CancelPendingQuery(&pending_profiles_query_); | 880 CancelPendingQuery(&pending_profiles_query_); |
905 | 881 |
906 pending_profiles_query_ = autofill_data->GetAutofillProfiles(this); | 882 pending_profiles_query_ = autofill_webdata_->GetAutofillProfiles(this); |
907 } | 883 } |
908 | 884 |
909 // Win and Linux implementations do nothing. Mac and Android implementations | 885 // Win and Linux implementations do nothing. Mac and Android implementations |
910 // fill in the contents of |auxiliary_profiles_|. | 886 // fill in the contents of |auxiliary_profiles_|. |
911 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 887 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
912 void PersonalDataManager::LoadAuxiliaryProfiles() const { | 888 void PersonalDataManager::LoadAuxiliaryProfiles() const { |
913 } | 889 } |
914 #endif | 890 #endif |
915 | 891 |
916 void PersonalDataManager::LoadCreditCards() { | 892 void PersonalDataManager::LoadCreditCards() { |
917 scoped_refptr<AutofillWebDataService> autofill_data( | 893 if (!autofill_webdata_.get()) { |
918 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
919 if (!autofill_data.get()) { | |
920 NOTREACHED(); | 894 NOTREACHED(); |
921 return; | 895 return; |
922 } | 896 } |
923 | 897 |
924 CancelPendingQuery(&pending_creditcards_query_); | 898 CancelPendingQuery(&pending_creditcards_query_); |
925 | 899 |
926 pending_creditcards_query_ = autofill_data->GetCreditCards(this); | 900 pending_creditcards_query_ = autofill_webdata_->GetCreditCards(this); |
927 } | 901 } |
928 | 902 |
929 void PersonalDataManager::ReceiveLoadedProfiles(WebDataServiceBase::Handle h, | 903 void PersonalDataManager::ReceiveLoadedProfiles(WebDataServiceBase::Handle h, |
930 const WDTypedResult* result) { | 904 const WDTypedResult* result) { |
931 DCHECK_EQ(pending_profiles_query_, h); | 905 DCHECK_EQ(pending_profiles_query_, h); |
932 | 906 |
933 pending_profiles_query_ = 0; | 907 pending_profiles_query_ = 0; |
934 web_profiles_.clear(); | 908 web_profiles_.clear(); |
935 | 909 |
936 const WDResult<std::vector<AutofillProfile*> >* r = | 910 const WDResult<std::vector<AutofillProfile*> >* r = |
(...skipping 21 matching lines...) Expand all Loading... | |
958 std::vector<CreditCard*> credit_cards = r->GetValue(); | 932 std::vector<CreditCard*> credit_cards = r->GetValue(); |
959 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); | 933 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); |
960 iter != credit_cards.end(); ++iter) { | 934 iter != credit_cards.end(); ++iter) { |
961 credit_cards_.push_back(*iter); | 935 credit_cards_.push_back(*iter); |
962 } | 936 } |
963 } | 937 } |
964 | 938 |
965 void PersonalDataManager::CancelPendingQuery( | 939 void PersonalDataManager::CancelPendingQuery( |
966 WebDataServiceBase::Handle* handle) { | 940 WebDataServiceBase::Handle* handle) { |
967 if (*handle) { | 941 if (*handle) { |
968 scoped_refptr<AutofillWebDataService> autofill_data( | 942 if (!autofill_webdata_.get()) { |
969 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
970 if (!autofill_data.get()) { | |
971 NOTREACHED(); | 943 NOTREACHED(); |
972 return; | 944 return; |
973 } | 945 } |
974 autofill_data->CancelRequest(*handle); | 946 autofill_webdata_->CancelRequest(*handle); |
975 } | 947 } |
976 *handle = 0; | 948 *handle = 0; |
977 } | 949 } |
978 | 950 |
979 std::string PersonalDataManager::SaveImportedProfile( | 951 std::string PersonalDataManager::SaveImportedProfile( |
980 const AutofillProfile& imported_profile) { | 952 const AutofillProfile& imported_profile) { |
981 if (is_off_the_record_) | 953 if (is_off_the_record_) |
982 return std::string(); | 954 return std::string(); |
983 | 955 |
984 // Don't save a web profile if the data in the profile is a subset of an | 956 // Don't save a web profile if the data in the profile is a subset of an |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1040 | 1012 |
1041 const AutofillMetrics* PersonalDataManager::metric_logger() const { | 1013 const AutofillMetrics* PersonalDataManager::metric_logger() const { |
1042 return metric_logger_.get(); | 1014 return metric_logger_.get(); |
1043 } | 1015 } |
1044 | 1016 |
1045 void PersonalDataManager::set_metric_logger( | 1017 void PersonalDataManager::set_metric_logger( |
1046 const AutofillMetrics* metric_logger) { | 1018 const AutofillMetrics* metric_logger) { |
1047 metric_logger_.reset(metric_logger); | 1019 metric_logger_.reset(metric_logger); |
1048 } | 1020 } |
1049 | 1021 |
1050 void PersonalDataManager::set_browser_context( | 1022 void PersonalDataManager::set_autofill_webdata_service( |
1051 content::BrowserContext* context) { | 1023 scoped_refptr<AutofillWebDataService> webdata) { |
1052 browser_context_ = context; | 1024 autofill_webdata_ = webdata; |
1053 } | 1025 } |
1054 | 1026 |
1055 void PersonalDataManager::set_pref_service(PrefService* pref_service) { | 1027 void PersonalDataManager::set_pref_service(PrefService* pref_service) { |
1056 pref_service_ = pref_service; | 1028 pref_service_ = pref_service; |
1057 } | 1029 } |
1058 | 1030 |
1059 std::string PersonalDataManager::MostCommonCountryCodeFromProfiles() const { | 1031 std::string PersonalDataManager::MostCommonCountryCodeFromProfiles() const { |
1060 // Count up country codes from existing profiles. | 1032 // Count up country codes from existing profiles. |
1061 std::map<std::string, int> votes; | 1033 std::map<std::string, int> votes; |
1062 // TODO(estade): can we make this GetProfiles() instead? It seems to cause | 1034 // TODO(estade): can we make this GetProfiles() instead? It seems to cause |
(...skipping 16 matching lines...) Expand all Loading... | |
1079 if (!votes.empty()) { | 1051 if (!votes.empty()) { |
1080 std::map<std::string, int>::iterator iter = | 1052 std::map<std::string, int>::iterator iter = |
1081 std::max_element(votes.begin(), votes.end(), CompareVotes); | 1053 std::max_element(votes.begin(), votes.end(), CompareVotes); |
1082 return iter->first; | 1054 return iter->first; |
1083 } | 1055 } |
1084 | 1056 |
1085 return std::string(); | 1057 return std::string(); |
1086 } | 1058 } |
1087 | 1059 |
1088 } // namespace autofill | 1060 } // namespace autofill |
OLD | NEW |