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 "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" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/autofill/autofill-inl.h" | 13 #include "chrome/browser/autofill/autofill-inl.h" |
14 #include "chrome/browser/autofill/autofill_field.h" | 14 #include "chrome/browser/autofill/autofill_field.h" |
15 #include "chrome/browser/autofill/autofill_metrics.h" | 15 #include "chrome/browser/autofill/autofill_metrics.h" |
16 #include "chrome/browser/autofill/autofill_regexes.h" | 16 #include "chrome/browser/autofill/autofill_regexes.h" |
17 #include "chrome/browser/autofill/form_structure.h" | 17 #include "chrome/browser/autofill/form_structure.h" |
18 #include "chrome/browser/autofill/personal_data_manager_observer.h" | 18 #include "chrome/browser/autofill/personal_data_manager_observer.h" |
19 #include "chrome/browser/autofill/phone_number.h" | 19 #include "chrome/browser/autofill/phone_number.h" |
20 #include "chrome/browser/autofill/phone_number_i18n.h" | 20 #include "chrome/browser/autofill/phone_number_i18n.h" |
21 #include "chrome/browser/autofill/select_control_handler.h" | 21 #include "chrome/browser/autofill/select_control_handler.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
25 #include "chrome/browser/sync/profile_sync_service_factory.h" | 25 #include "chrome/browser/sync/profile_sync_service_factory.h" |
26 #include "chrome/browser/webdata/autofill_entry.h" | 26 #include "chrome/browser/webdata/autofill_entry.h" |
27 #include "chrome/browser/webdata/web_data_service.h" | 27 #include "chrome/browser/webdata/web_data_service.h" |
| 28 #include "chrome/browser/webdata/web_data_service_factory.h" |
28 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 template<typename T> | 36 template<typename T> |
36 class FormGroupMatchesByGUIDFunctor { | 37 class FormGroupMatchesByGUIDFunctor { |
37 public: | 38 public: |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 192 } |
192 | 193 |
193 // The |PersonalDataManager| is set up as a listener of the sync service in | 194 // The |PersonalDataManager| is set up as a listener of the sync service in |
194 // |EmptyMigrationTrash| in the case where sync is not yet ready to receive | 195 // |EmptyMigrationTrash| in the case where sync is not yet ready to receive |
195 // changes. This method, |OnStateChange| acts as a deferred call to | 196 // changes. This method, |OnStateChange| acts as a deferred call to |
196 // |EmptyMigrationTrash| once the sync service becomes available. | 197 // |EmptyMigrationTrash| once the sync service becomes available. |
197 void PersonalDataManager::OnStateChanged() { | 198 void PersonalDataManager::OnStateChanged() { |
198 if (!profile_ || profile_->IsOffTheRecord()) | 199 if (!profile_ || profile_->IsOffTheRecord()) |
199 return; | 200 return; |
200 | 201 |
201 WebDataService* web_data_service = | 202 scoped_refptr<WebDataService> web_data_service = |
202 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 203 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
203 if (!web_data_service) { | 204 if (!web_data_service.get()) { |
204 NOTREACHED(); | 205 NOTREACHED(); |
205 return; | 206 return; |
206 } | 207 } |
207 | 208 |
208 ProfileSyncService* sync_service = | 209 ProfileSyncService* sync_service = |
209 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | 210 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
210 if (!sync_service) | 211 if (!sync_service) |
211 return; | 212 return; |
212 | 213 |
213 if (sync_service->ShouldPushChanges()) { | 214 if (sync_service->ShouldPushChanges()) { |
214 web_data_service->EmptyMigrationTrash(true); | 215 web_data_service->EmptyMigrationTrash(true); |
215 sync_service->RemoveObserver(this); | 216 sync_service->RemoveObserver(this); |
216 } | 217 } |
217 } | 218 } |
218 | 219 |
219 void PersonalDataManager::Shutdown() { | 220 void PersonalDataManager::Shutdown() { |
220 CancelPendingQuery(&pending_profiles_query_); | 221 CancelPendingQuery(&pending_profiles_query_); |
221 CancelPendingQuery(&pending_creditcards_query_); | 222 CancelPendingQuery(&pending_creditcards_query_); |
222 notification_registrar_.RemoveAll(); | 223 notification_registrar_.RemoveAll(); |
223 } | 224 } |
224 | 225 |
225 void PersonalDataManager::Observe(int type, | 226 void PersonalDataManager::Observe(int type, |
226 const content::NotificationSource& source, | 227 const content::NotificationSource& source, |
227 const content::NotificationDetails& details) { | 228 const content::NotificationDetails& details) { |
228 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); | 229 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); |
229 WebDataService* web_data_service = | 230 scoped_refptr<WebDataService> web_data_service = |
230 content::Source<WebDataService>(source).ptr(); | 231 content::Source<WebDataService>(source).ptr(); |
231 | 232 |
232 DCHECK(web_data_service && | 233 DCHECK(web_data_service.get() && |
233 web_data_service == | 234 web_data_service.get() == WebDataServiceFactory::GetForProfile( |
234 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)); | 235 profile_, Profile::EXPLICIT_ACCESS).get()); |
235 Refresh(); | 236 Refresh(); |
236 } | 237 } |
237 | 238 |
238 bool PersonalDataManager::ImportFormData( | 239 bool PersonalDataManager::ImportFormData( |
239 const FormStructure& form, | 240 const FormStructure& form, |
240 const CreditCard** imported_credit_card) { | 241 const CreditCard** imported_credit_card) { |
241 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); | 242 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); |
242 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); | 243 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); |
243 | 244 |
244 // Parse the form and construct a profile based on the information that is | 245 // Parse the form and construct a profile based on the information that is |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 if (profile_->IsOffTheRecord()) | 358 if (profile_->IsOffTheRecord()) |
358 return; | 359 return; |
359 | 360 |
360 if (profile.IsEmpty()) | 361 if (profile.IsEmpty()) |
361 return; | 362 return; |
362 | 363 |
363 // Don't add an existing profile. | 364 // Don't add an existing profile. |
364 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) | 365 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
365 return; | 366 return; |
366 | 367 |
367 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 368 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
368 if (!wds) | 369 profile_, Profile::EXPLICIT_ACCESS); |
| 370 if (!wds.get()) |
369 return; | 371 return; |
370 | 372 |
371 // Don't add a duplicate. | 373 // Don't add a duplicate. |
372 if (FindByContents(web_profiles_, profile)) | 374 if (FindByContents(web_profiles_, profile)) |
373 return; | 375 return; |
374 | 376 |
375 // Add the new profile to the web database. | 377 // Add the new profile to the web database. |
376 wds->AddAutofillProfile(profile); | 378 wds->AddAutofillProfile(profile); |
377 | 379 |
378 // Refresh our local cache and send notifications to observers. | 380 // Refresh our local cache and send notifications to observers. |
379 Refresh(); | 381 Refresh(); |
380 } | 382 } |
381 | 383 |
382 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { | 384 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { |
383 if (profile_->IsOffTheRecord()) | 385 if (profile_->IsOffTheRecord()) |
384 return; | 386 return; |
385 | 387 |
386 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) | 388 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
387 return; | 389 return; |
388 | 390 |
389 if (profile.IsEmpty()) { | 391 if (profile.IsEmpty()) { |
390 RemoveProfile(profile.guid()); | 392 RemoveProfile(profile.guid()); |
391 return; | 393 return; |
392 } | 394 } |
393 | 395 |
394 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 396 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
395 if (!wds) | 397 profile_, Profile::EXPLICIT_ACCESS); |
| 398 if (!wds.get()) |
396 return; | 399 return; |
397 | 400 |
398 // Make the update. | 401 // Make the update. |
399 wds->UpdateAutofillProfile(profile); | 402 wds->UpdateAutofillProfile(profile); |
400 | 403 |
401 // Refresh our local cache and send notifications to observers. | 404 // Refresh our local cache and send notifications to observers. |
402 Refresh(); | 405 Refresh(); |
403 } | 406 } |
404 | 407 |
405 void PersonalDataManager::RemoveProfile(const std::string& guid) { | 408 void PersonalDataManager::RemoveProfile(const std::string& guid) { |
406 if (profile_->IsOffTheRecord()) | 409 if (profile_->IsOffTheRecord()) |
407 return; | 410 return; |
408 | 411 |
409 if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) | 412 if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) |
410 return; | 413 return; |
411 | 414 |
412 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 415 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
413 if (!wds) | 416 profile_, Profile::EXPLICIT_ACCESS); |
| 417 if (!wds.get()) |
414 return; | 418 return; |
415 | 419 |
416 // Remove the profile. | 420 // Remove the profile. |
417 wds->RemoveAutofillProfile(guid); | 421 wds->RemoveAutofillProfile(guid); |
418 | 422 |
419 // Refresh our local cache and send notifications to observers. | 423 // Refresh our local cache and send notifications to observers. |
420 Refresh(); | 424 Refresh(); |
421 } | 425 } |
422 | 426 |
423 AutofillProfile* PersonalDataManager::GetProfileByGUID( | 427 AutofillProfile* PersonalDataManager::GetProfileByGUID( |
424 const std::string& guid) { | 428 const std::string& guid) { |
425 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_->begin(); | 429 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_->begin(); |
426 iter != web_profiles_->end(); ++iter) { | 430 iter != web_profiles_->end(); ++iter) { |
427 if ((*iter)->guid() == guid) | 431 if ((*iter)->guid() == guid) |
428 return *iter; | 432 return *iter; |
429 } | 433 } |
430 return NULL; | 434 return NULL; |
431 } | 435 } |
432 | 436 |
433 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { | 437 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { |
434 if (profile_->IsOffTheRecord()) | 438 if (profile_->IsOffTheRecord()) |
435 return; | 439 return; |
436 | 440 |
437 if (credit_card.IsEmpty()) | 441 if (credit_card.IsEmpty()) |
438 return; | 442 return; |
439 | 443 |
440 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) | 444 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
441 return; | 445 return; |
442 | 446 |
443 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 447 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
444 if (!wds) | 448 profile_, Profile::EXPLICIT_ACCESS); |
| 449 if (!wds.get()) |
445 return; | 450 return; |
446 | 451 |
447 // Don't add a duplicate. | 452 // Don't add a duplicate. |
448 if (FindByContents(credit_cards_, credit_card)) | 453 if (FindByContents(credit_cards_, credit_card)) |
449 return; | 454 return; |
450 | 455 |
451 // Add the new credit card to the web database. | 456 // Add the new credit card to the web database. |
452 wds->AddCreditCard(credit_card); | 457 wds->AddCreditCard(credit_card); |
453 | 458 |
454 // Refresh our local cache and send notifications to observers. | 459 // Refresh our local cache and send notifications to observers. |
455 Refresh(); | 460 Refresh(); |
456 } | 461 } |
457 | 462 |
458 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { | 463 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { |
459 if (profile_->IsOffTheRecord()) | 464 if (profile_->IsOffTheRecord()) |
460 return; | 465 return; |
461 | 466 |
462 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) | 467 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
463 return; | 468 return; |
464 | 469 |
465 if (credit_card.IsEmpty()) { | 470 if (credit_card.IsEmpty()) { |
466 RemoveCreditCard(credit_card.guid()); | 471 RemoveCreditCard(credit_card.guid()); |
467 return; | 472 return; |
468 } | 473 } |
469 | 474 |
470 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 475 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
471 if (!wds) | 476 profile_, Profile::EXPLICIT_ACCESS); |
| 477 if (!wds.get()) |
472 return; | 478 return; |
473 | 479 |
474 // Make the update. | 480 // Make the update. |
475 wds->UpdateCreditCard(credit_card); | 481 wds->UpdateCreditCard(credit_card); |
476 | 482 |
477 // Refresh our local cache and send notifications to observers. | 483 // Refresh our local cache and send notifications to observers. |
478 Refresh(); | 484 Refresh(); |
479 } | 485 } |
480 | 486 |
481 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { | 487 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { |
482 if (profile_->IsOffTheRecord()) | 488 if (profile_->IsOffTheRecord()) |
483 return; | 489 return; |
484 | 490 |
485 if (!FindByGUID<CreditCard>(credit_cards_, guid)) | 491 if (!FindByGUID<CreditCard>(credit_cards_, guid)) |
486 return; | 492 return; |
487 | 493 |
488 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 494 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
489 if (!wds) | 495 profile_, Profile::EXPLICIT_ACCESS); |
| 496 if (!wds.get()) |
490 return; | 497 return; |
491 | 498 |
492 // Remove the credit card. | 499 // Remove the credit card. |
493 wds->RemoveCreditCard(guid); | 500 wds->RemoveCreditCard(guid); |
494 | 501 |
495 // Refresh our local cache and send notifications to observers. | 502 // Refresh our local cache and send notifications to observers. |
496 Refresh(); | 503 Refresh(); |
497 } | 504 } |
498 | 505 |
499 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { | 506 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 pending_creditcards_query_(0), | 572 pending_creditcards_query_(0), |
566 metric_logger_(new AutofillMetrics), | 573 metric_logger_(new AutofillMetrics), |
567 has_logged_profile_count_(false) { | 574 has_logged_profile_count_(false) { |
568 } | 575 } |
569 | 576 |
570 void PersonalDataManager::Init(Profile* profile) { | 577 void PersonalDataManager::Init(Profile* profile) { |
571 profile_ = profile; | 578 profile_ = profile; |
572 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); | 579 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); |
573 | 580 |
574 // WebDataService may not be available in tests. | 581 // WebDataService may not be available in tests. |
575 WebDataService* web_data_service = | 582 scoped_refptr<WebDataService> web_data_service = |
576 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 583 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
577 if (!web_data_service) | 584 if (!web_data_service.get()) |
578 return; | 585 return; |
579 | 586 |
580 LoadProfiles(); | 587 LoadProfiles(); |
581 LoadCreditCards(); | 588 LoadCreditCards(); |
582 | 589 |
583 notification_registrar_.Add( | 590 notification_registrar_.Add( |
584 this, | 591 this, |
585 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, | 592 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, |
586 content::Source<WebDataService>(web_data_service)); | 593 content::Source<WebDataService>(web_data_service)); |
587 } | 594 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 | 667 |
661 // Ensure that profile labels are up to date. Currently, sync relies on | 668 // Ensure that profile labels are up to date. Currently, sync relies on |
662 // labels to identify a profile. | 669 // labels to identify a profile. |
663 // TODO(dhollowa): We need to deprecate labels and update the way sync | 670 // TODO(dhollowa): We need to deprecate labels and update the way sync |
664 // identifies profiles. | 671 // identifies profiles. |
665 std::vector<AutofillProfile*> profile_pointers(profiles->size()); | 672 std::vector<AutofillProfile*> profile_pointers(profiles->size()); |
666 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), | 673 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), |
667 address_of<AutofillProfile>); | 674 address_of<AutofillProfile>); |
668 AutofillProfile::AdjustInferredLabels(&profile_pointers); | 675 AutofillProfile::AdjustInferredLabels(&profile_pointers); |
669 | 676 |
670 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 677 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
671 if (!wds) | 678 profile_, Profile::EXPLICIT_ACCESS); |
| 679 if (!wds.get()) |
672 return; | 680 return; |
673 | 681 |
674 // Any profiles that are not in the new profile list should be removed from | 682 // Any profiles that are not in the new profile list should be removed from |
675 // the web database. | 683 // the web database. |
676 for (std::vector<AutofillProfile*>::const_iterator iter = | 684 for (std::vector<AutofillProfile*>::const_iterator iter = |
677 web_profiles_.begin(); | 685 web_profiles_.begin(); |
678 iter != web_profiles_.end(); ++iter) { | 686 iter != web_profiles_.end(); ++iter) { |
679 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) | 687 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) |
680 wds->RemoveAutofillProfile((*iter)->guid()); | 688 wds->RemoveAutofillProfile((*iter)->guid()); |
681 } | 689 } |
(...skipping 29 matching lines...) Expand all Loading... |
711 if (profile_->IsOffTheRecord()) | 719 if (profile_->IsOffTheRecord()) |
712 return; | 720 return; |
713 | 721 |
714 // Remove empty credit cards from input. | 722 // Remove empty credit cards from input. |
715 credit_cards->erase( | 723 credit_cards->erase( |
716 std::remove_if( | 724 std::remove_if( |
717 credit_cards->begin(), credit_cards->end(), | 725 credit_cards->begin(), credit_cards->end(), |
718 std::mem_fun_ref(&CreditCard::IsEmpty)), | 726 std::mem_fun_ref(&CreditCard::IsEmpty)), |
719 credit_cards->end()); | 727 credit_cards->end()); |
720 | 728 |
721 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 729 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
722 if (!wds) | 730 profile_, Profile::EXPLICIT_ACCESS); |
| 731 if (!wds.get()) |
723 return; | 732 return; |
724 | 733 |
725 // Any credit cards that are not in the new credit card list should be | 734 // Any credit cards that are not in the new credit card list should be |
726 // removed. | 735 // removed. |
727 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); | 736 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); |
728 iter != credit_cards_.end(); ++iter) { | 737 iter != credit_cards_.end(); ++iter) { |
729 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) | 738 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) |
730 wds->RemoveCreditCard((*iter)->guid()); | 739 wds->RemoveCreditCard((*iter)->guid()); |
731 } | 740 } |
732 | 741 |
(...skipping 17 matching lines...) Expand all Loading... |
750 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 759 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
751 iter != credit_cards->end(); ++iter) { | 760 iter != credit_cards->end(); ++iter) { |
752 credit_cards_.push_back(new CreditCard(*iter)); | 761 credit_cards_.push_back(new CreditCard(*iter)); |
753 } | 762 } |
754 | 763 |
755 // Refresh our local cache and send notifications to observers. | 764 // Refresh our local cache and send notifications to observers. |
756 Refresh(); | 765 Refresh(); |
757 } | 766 } |
758 | 767 |
759 void PersonalDataManager::LoadProfiles() { | 768 void PersonalDataManager::LoadProfiles() { |
760 WebDataService* web_data_service = | 769 scoped_refptr<WebDataService> web_data_service = |
761 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 770 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
762 if (!web_data_service) { | 771 if (!web_data_service.get()) { |
763 NOTREACHED(); | 772 NOTREACHED(); |
764 return; | 773 return; |
765 } | 774 } |
766 | 775 |
767 CancelPendingQuery(&pending_profiles_query_); | 776 CancelPendingQuery(&pending_profiles_query_); |
768 | 777 |
769 pending_profiles_query_ = web_data_service->GetAutofillProfiles(this); | 778 pending_profiles_query_ = web_data_service->GetAutofillProfiles(this); |
770 } | 779 } |
771 | 780 |
772 // Win and Linux implementations do nothing. Mac implementation fills in the | 781 // Win and Linux implementations do nothing. Mac implementation fills in the |
773 // contents of |auxiliary_profiles_|. | 782 // contents of |auxiliary_profiles_|. |
774 #if !defined(OS_MACOSX) | 783 #if !defined(OS_MACOSX) |
775 void PersonalDataManager::LoadAuxiliaryProfiles() const { | 784 void PersonalDataManager::LoadAuxiliaryProfiles() const { |
776 } | 785 } |
777 #endif | 786 #endif |
778 | 787 |
779 void PersonalDataManager::LoadCreditCards() { | 788 void PersonalDataManager::LoadCreditCards() { |
780 WebDataService* web_data_service = | 789 scoped_refptr<WebDataService> web_data_service = |
781 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 790 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
782 if (!web_data_service) { | 791 if (!web_data_service.get()) { |
783 NOTREACHED(); | 792 NOTREACHED(); |
784 return; | 793 return; |
785 } | 794 } |
786 | 795 |
787 CancelPendingQuery(&pending_creditcards_query_); | 796 CancelPendingQuery(&pending_creditcards_query_); |
788 | 797 |
789 pending_creditcards_query_ = web_data_service->GetCreditCards(this); | 798 pending_creditcards_query_ = web_data_service->GetCreditCards(this); |
790 } | 799 } |
791 | 800 |
792 void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, | 801 void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, |
(...skipping 28 matching lines...) Expand all Loading... |
821 | 830 |
822 std::vector<CreditCard*> credit_cards = r->GetValue(); | 831 std::vector<CreditCard*> credit_cards = r->GetValue(); |
823 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); | 832 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); |
824 iter != credit_cards.end(); ++iter) { | 833 iter != credit_cards.end(); ++iter) { |
825 credit_cards_.push_back(*iter); | 834 credit_cards_.push_back(*iter); |
826 } | 835 } |
827 } | 836 } |
828 | 837 |
829 void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) { | 838 void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) { |
830 if (*handle) { | 839 if (*handle) { |
831 WebDataService* web_data_service = | 840 scoped_refptr<WebDataService> web_data_service = |
832 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 841 WebDataServiceFactory::GetForProfile(profile_, |
833 if (!web_data_service) { | 842 Profile::EXPLICIT_ACCESS); |
| 843 if (!web_data_service.get()) { |
834 NOTREACHED(); | 844 NOTREACHED(); |
835 return; | 845 return; |
836 } | 846 } |
837 web_data_service->CancelRequest(*handle); | 847 web_data_service->CancelRequest(*handle); |
838 } | 848 } |
839 *handle = 0; | 849 *handle = 0; |
840 } | 850 } |
841 | 851 |
842 void PersonalDataManager::SaveImportedProfile( | 852 void PersonalDataManager::SaveImportedProfile( |
843 const AutofillProfile& imported_profile) { | 853 const AutofillProfile& imported_profile) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 if (!merged) | 901 if (!merged) |
892 creditcards.push_back(imported_credit_card); | 902 creditcards.push_back(imported_credit_card); |
893 | 903 |
894 SetCreditCards(&creditcards); | 904 SetCreditCards(&creditcards); |
895 } | 905 } |
896 | 906 |
897 void PersonalDataManager::EmptyMigrationTrash() { | 907 void PersonalDataManager::EmptyMigrationTrash() { |
898 if (!profile_ || profile_->IsOffTheRecord()) | 908 if (!profile_ || profile_->IsOffTheRecord()) |
899 return; | 909 return; |
900 | 910 |
901 WebDataService* web_data_service = | 911 scoped_refptr<WebDataService> web_data_service = |
902 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 912 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
903 if (!web_data_service) { | 913 if (!web_data_service.get()) { |
904 NOTREACHED(); | 914 NOTREACHED(); |
905 return; | 915 return; |
906 } | 916 } |
907 | 917 |
908 ProfileSyncService* sync_service = | 918 ProfileSyncService* sync_service = |
909 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | 919 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
910 if (!sync_service) | 920 if (!sync_service) |
911 return; | 921 return; |
912 | 922 |
913 if (!sync_service->HasSyncSetupCompleted()) { | 923 if (!sync_service->HasSyncSetupCompleted()) { |
(...skipping 16 matching lines...) Expand all Loading... |
930 } | 940 } |
931 | 941 |
932 const AutofillMetrics* PersonalDataManager::metric_logger() const { | 942 const AutofillMetrics* PersonalDataManager::metric_logger() const { |
933 return metric_logger_.get(); | 943 return metric_logger_.get(); |
934 } | 944 } |
935 | 945 |
936 void PersonalDataManager::set_metric_logger( | 946 void PersonalDataManager::set_metric_logger( |
937 const AutofillMetrics* metric_logger) { | 947 const AutofillMetrics* metric_logger) { |
938 metric_logger_.reset(metric_logger); | 948 metric_logger_.reset(metric_logger); |
939 } | 949 } |
OLD | NEW |