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/web_data_service.h" | 26 #include "chrome/browser/webdata/web_data_service.h" |
| 27 #include "chrome/browser/webdata/web_data_service_factory.h" |
27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 template<typename T> | 35 template<typename T> |
35 class FormGroupMatchesByGUIDFunctor { | 36 class FormGroupMatchesByGUIDFunctor { |
36 public: | 37 public: |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 178 } |
178 | 179 |
179 // The |PersonalDataManager| is set up as a listener of the sync service in | 180 // The |PersonalDataManager| is set up as a listener of the sync service in |
180 // |EmptyMigrationTrash| in the case where sync is not yet ready to receive | 181 // |EmptyMigrationTrash| in the case where sync is not yet ready to receive |
181 // changes. This method, |OnStateChange| acts as a deferred call to | 182 // changes. This method, |OnStateChange| acts as a deferred call to |
182 // |EmptyMigrationTrash| once the sync service becomes available. | 183 // |EmptyMigrationTrash| once the sync service becomes available. |
183 void PersonalDataManager::OnStateChanged() { | 184 void PersonalDataManager::OnStateChanged() { |
184 if (!profile_ || profile_->IsOffTheRecord()) | 185 if (!profile_ || profile_->IsOffTheRecord()) |
185 return; | 186 return; |
186 | 187 |
187 WebDataService* web_data_service = | 188 scoped_refptr<WebDataService> web_data_service = |
188 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 189 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
189 if (!web_data_service) { | 190 if (!web_data_service.get()) { |
190 NOTREACHED(); | 191 NOTREACHED(); |
191 return; | 192 return; |
192 } | 193 } |
193 | 194 |
194 ProfileSyncService* sync_service = | 195 ProfileSyncService* sync_service = |
195 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | 196 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
196 if (!sync_service) | 197 if (!sync_service) |
197 return; | 198 return; |
198 | 199 |
199 if (sync_service->ShouldPushChanges()) { | 200 if (sync_service->ShouldPushChanges()) { |
200 web_data_service->EmptyMigrationTrash(true); | 201 web_data_service->EmptyMigrationTrash(true); |
201 sync_service->RemoveObserver(this); | 202 sync_service->RemoveObserver(this); |
202 } | 203 } |
203 } | 204 } |
204 | 205 |
205 void PersonalDataManager::Shutdown() { | 206 void PersonalDataManager::Shutdown() { |
206 CancelPendingQuery(&pending_profiles_query_); | 207 CancelPendingQuery(&pending_profiles_query_); |
207 CancelPendingQuery(&pending_creditcards_query_); | 208 CancelPendingQuery(&pending_creditcards_query_); |
208 notification_registrar_.RemoveAll(); | 209 notification_registrar_.RemoveAll(); |
209 } | 210 } |
210 | 211 |
211 void PersonalDataManager::Observe(int type, | 212 void PersonalDataManager::Observe(int type, |
212 const content::NotificationSource& source, | 213 const content::NotificationSource& source, |
213 const content::NotificationDetails& details) { | 214 const content::NotificationDetails& details) { |
214 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); | 215 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); |
215 WebDataService* web_data_service = | 216 scoped_refptr<WebDataService> web_data_service = |
216 content::Source<WebDataService>(source).ptr(); | 217 content::Source<WebDataService>(source).ptr(); |
217 | 218 |
218 DCHECK(web_data_service && | 219 DCHECK(web_data_service.get() && |
219 web_data_service == | 220 web_data_service.get() == WebDataServiceFactory::GetForProfile( |
220 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)); | 221 profile_, Profile::EXPLICIT_ACCESS).get()); |
221 Refresh(); | 222 Refresh(); |
222 } | 223 } |
223 | 224 |
224 bool PersonalDataManager::ImportFormData( | 225 bool PersonalDataManager::ImportFormData( |
225 const FormStructure& form, | 226 const FormStructure& form, |
226 const CreditCard** imported_credit_card) { | 227 const CreditCard** imported_credit_card) { |
227 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); | 228 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); |
228 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); | 229 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); |
229 | 230 |
230 // Parse the form and construct a profile based on the information that is | 231 // 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... |
343 if (profile_->IsOffTheRecord()) | 344 if (profile_->IsOffTheRecord()) |
344 return; | 345 return; |
345 | 346 |
346 if (profile.IsEmpty()) | 347 if (profile.IsEmpty()) |
347 return; | 348 return; |
348 | 349 |
349 // Don't add an existing profile. | 350 // Don't add an existing profile. |
350 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) | 351 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
351 return; | 352 return; |
352 | 353 |
353 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 354 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
354 if (!wds) | 355 profile_, Profile::EXPLICIT_ACCESS); |
| 356 if (!wds.get()) |
355 return; | 357 return; |
356 | 358 |
357 // Don't add a duplicate. | 359 // Don't add a duplicate. |
358 if (FindByContents(web_profiles_, profile)) | 360 if (FindByContents(web_profiles_, profile)) |
359 return; | 361 return; |
360 | 362 |
361 // Add the new profile to the web database. | 363 // Add the new profile to the web database. |
362 wds->AddAutofillProfile(profile); | 364 wds->AddAutofillProfile(profile); |
363 | 365 |
364 // Refresh our local cache and send notifications to observers. | 366 // Refresh our local cache and send notifications to observers. |
365 Refresh(); | 367 Refresh(); |
366 } | 368 } |
367 | 369 |
368 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { | 370 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { |
369 if (profile_->IsOffTheRecord()) | 371 if (profile_->IsOffTheRecord()) |
370 return; | 372 return; |
371 | 373 |
372 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) | 374 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
373 return; | 375 return; |
374 | 376 |
375 if (profile.IsEmpty()) { | 377 if (profile.IsEmpty()) { |
376 RemoveProfile(profile.guid()); | 378 RemoveProfile(profile.guid()); |
377 return; | 379 return; |
378 } | 380 } |
379 | 381 |
380 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 382 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
381 if (!wds) | 383 profile_, Profile::EXPLICIT_ACCESS); |
| 384 if (!wds.get()) |
382 return; | 385 return; |
383 | 386 |
384 // Make the update. | 387 // Make the update. |
385 wds->UpdateAutofillProfile(profile); | 388 wds->UpdateAutofillProfile(profile); |
386 | 389 |
387 // Refresh our local cache and send notifications to observers. | 390 // Refresh our local cache and send notifications to observers. |
388 Refresh(); | 391 Refresh(); |
389 } | 392 } |
390 | 393 |
391 void PersonalDataManager::RemoveProfile(const std::string& guid) { | 394 void PersonalDataManager::RemoveProfile(const std::string& guid) { |
392 if (profile_->IsOffTheRecord()) | 395 if (profile_->IsOffTheRecord()) |
393 return; | 396 return; |
394 | 397 |
395 if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) | 398 if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) |
396 return; | 399 return; |
397 | 400 |
398 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 401 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
399 if (!wds) | 402 profile_, Profile::EXPLICIT_ACCESS); |
| 403 if (!wds.get()) |
400 return; | 404 return; |
401 | 405 |
402 // Remove the profile. | 406 // Remove the profile. |
403 wds->RemoveAutofillProfile(guid); | 407 wds->RemoveAutofillProfile(guid); |
404 | 408 |
405 // Refresh our local cache and send notifications to observers. | 409 // Refresh our local cache and send notifications to observers. |
406 Refresh(); | 410 Refresh(); |
407 } | 411 } |
408 | 412 |
409 AutofillProfile* PersonalDataManager::GetProfileByGUID( | 413 AutofillProfile* PersonalDataManager::GetProfileByGUID( |
410 const std::string& guid) { | 414 const std::string& guid) { |
411 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_->begin(); | 415 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_->begin(); |
412 iter != web_profiles_->end(); ++iter) { | 416 iter != web_profiles_->end(); ++iter) { |
413 if ((*iter)->guid() == guid) | 417 if ((*iter)->guid() == guid) |
414 return *iter; | 418 return *iter; |
415 } | 419 } |
416 return NULL; | 420 return NULL; |
417 } | 421 } |
418 | 422 |
419 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { | 423 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { |
420 if (profile_->IsOffTheRecord()) | 424 if (profile_->IsOffTheRecord()) |
421 return; | 425 return; |
422 | 426 |
423 if (credit_card.IsEmpty()) | 427 if (credit_card.IsEmpty()) |
424 return; | 428 return; |
425 | 429 |
426 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) | 430 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
427 return; | 431 return; |
428 | 432 |
429 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 433 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
430 if (!wds) | 434 profile_, Profile::EXPLICIT_ACCESS); |
| 435 if (!wds.get()) |
431 return; | 436 return; |
432 | 437 |
433 // Don't add a duplicate. | 438 // Don't add a duplicate. |
434 if (FindByContents(credit_cards_, credit_card)) | 439 if (FindByContents(credit_cards_, credit_card)) |
435 return; | 440 return; |
436 | 441 |
437 // Add the new credit card to the web database. | 442 // Add the new credit card to the web database. |
438 wds->AddCreditCard(credit_card); | 443 wds->AddCreditCard(credit_card); |
439 | 444 |
440 // Refresh our local cache and send notifications to observers. | 445 // Refresh our local cache and send notifications to observers. |
441 Refresh(); | 446 Refresh(); |
442 } | 447 } |
443 | 448 |
444 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { | 449 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { |
445 if (profile_->IsOffTheRecord()) | 450 if (profile_->IsOffTheRecord()) |
446 return; | 451 return; |
447 | 452 |
448 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) | 453 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
449 return; | 454 return; |
450 | 455 |
451 if (credit_card.IsEmpty()) { | 456 if (credit_card.IsEmpty()) { |
452 RemoveCreditCard(credit_card.guid()); | 457 RemoveCreditCard(credit_card.guid()); |
453 return; | 458 return; |
454 } | 459 } |
455 | 460 |
456 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 461 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
457 if (!wds) | 462 profile_, Profile::EXPLICIT_ACCESS); |
| 463 if (!wds.get()) |
458 return; | 464 return; |
459 | 465 |
460 // Make the update. | 466 // Make the update. |
461 wds->UpdateCreditCard(credit_card); | 467 wds->UpdateCreditCard(credit_card); |
462 | 468 |
463 // Refresh our local cache and send notifications to observers. | 469 // Refresh our local cache and send notifications to observers. |
464 Refresh(); | 470 Refresh(); |
465 } | 471 } |
466 | 472 |
467 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { | 473 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { |
468 if (profile_->IsOffTheRecord()) | 474 if (profile_->IsOffTheRecord()) |
469 return; | 475 return; |
470 | 476 |
471 if (!FindByGUID<CreditCard>(credit_cards_, guid)) | 477 if (!FindByGUID<CreditCard>(credit_cards_, guid)) |
472 return; | 478 return; |
473 | 479 |
474 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 480 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
475 if (!wds) | 481 profile_, Profile::EXPLICIT_ACCESS); |
| 482 if (!wds.get()) |
476 return; | 483 return; |
477 | 484 |
478 // Remove the credit card. | 485 // Remove the credit card. |
479 wds->RemoveCreditCard(guid); | 486 wds->RemoveCreditCard(guid); |
480 | 487 |
481 // Refresh our local cache and send notifications to observers. | 488 // Refresh our local cache and send notifications to observers. |
482 Refresh(); | 489 Refresh(); |
483 } | 490 } |
484 | 491 |
485 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { | 492 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 pending_creditcards_query_(0), | 558 pending_creditcards_query_(0), |
552 metric_logger_(new AutofillMetrics), | 559 metric_logger_(new AutofillMetrics), |
553 has_logged_profile_count_(false) { | 560 has_logged_profile_count_(false) { |
554 } | 561 } |
555 | 562 |
556 void PersonalDataManager::Init(Profile* profile) { | 563 void PersonalDataManager::Init(Profile* profile) { |
557 profile_ = profile; | 564 profile_ = profile; |
558 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); | 565 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); |
559 | 566 |
560 // WebDataService may not be available in tests. | 567 // WebDataService may not be available in tests. |
561 WebDataService* web_data_service = | 568 scoped_refptr<WebDataService> web_data_service = |
562 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 569 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
563 if (!web_data_service) | 570 if (!web_data_service.get()) |
564 return; | 571 return; |
565 | 572 |
566 LoadProfiles(); | 573 LoadProfiles(); |
567 LoadCreditCards(); | 574 LoadCreditCards(); |
568 | 575 |
569 notification_registrar_.Add( | 576 notification_registrar_.Add( |
570 this, | 577 this, |
571 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, | 578 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, |
572 content::Source<WebDataService>(web_data_service)); | 579 content::Source<WebDataService>(web_data_service)); |
573 } | 580 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 | 653 |
647 // Ensure that profile labels are up to date. Currently, sync relies on | 654 // Ensure that profile labels are up to date. Currently, sync relies on |
648 // labels to identify a profile. | 655 // labels to identify a profile. |
649 // TODO(dhollowa): We need to deprecate labels and update the way sync | 656 // TODO(dhollowa): We need to deprecate labels and update the way sync |
650 // identifies profiles. | 657 // identifies profiles. |
651 std::vector<AutofillProfile*> profile_pointers(profiles->size()); | 658 std::vector<AutofillProfile*> profile_pointers(profiles->size()); |
652 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), | 659 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), |
653 address_of<AutofillProfile>); | 660 address_of<AutofillProfile>); |
654 AutofillProfile::AdjustInferredLabels(&profile_pointers); | 661 AutofillProfile::AdjustInferredLabels(&profile_pointers); |
655 | 662 |
656 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 663 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
657 if (!wds) | 664 profile_, Profile::EXPLICIT_ACCESS); |
| 665 if (!wds.get()) |
658 return; | 666 return; |
659 | 667 |
660 // Any profiles that are not in the new profile list should be removed from | 668 // Any profiles that are not in the new profile list should be removed from |
661 // the web database. | 669 // the web database. |
662 for (std::vector<AutofillProfile*>::const_iterator iter = | 670 for (std::vector<AutofillProfile*>::const_iterator iter = |
663 web_profiles_.begin(); | 671 web_profiles_.begin(); |
664 iter != web_profiles_.end(); ++iter) { | 672 iter != web_profiles_.end(); ++iter) { |
665 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) | 673 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) |
666 wds->RemoveAutofillProfile((*iter)->guid()); | 674 wds->RemoveAutofillProfile((*iter)->guid()); |
667 } | 675 } |
(...skipping 29 matching lines...) Expand all Loading... |
697 if (profile_->IsOffTheRecord()) | 705 if (profile_->IsOffTheRecord()) |
698 return; | 706 return; |
699 | 707 |
700 // Remove empty credit cards from input. | 708 // Remove empty credit cards from input. |
701 credit_cards->erase( | 709 credit_cards->erase( |
702 std::remove_if( | 710 std::remove_if( |
703 credit_cards->begin(), credit_cards->end(), | 711 credit_cards->begin(), credit_cards->end(), |
704 std::mem_fun_ref(&CreditCard::IsEmpty)), | 712 std::mem_fun_ref(&CreditCard::IsEmpty)), |
705 credit_cards->end()); | 713 credit_cards->end()); |
706 | 714 |
707 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 715 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( |
708 if (!wds) | 716 profile_, Profile::EXPLICIT_ACCESS); |
| 717 if (!wds.get()) |
709 return; | 718 return; |
710 | 719 |
711 // Any credit cards that are not in the new credit card list should be | 720 // Any credit cards that are not in the new credit card list should be |
712 // removed. | 721 // removed. |
713 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); | 722 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); |
714 iter != credit_cards_.end(); ++iter) { | 723 iter != credit_cards_.end(); ++iter) { |
715 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) | 724 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) |
716 wds->RemoveCreditCard((*iter)->guid()); | 725 wds->RemoveCreditCard((*iter)->guid()); |
717 } | 726 } |
718 | 727 |
(...skipping 17 matching lines...) Expand all Loading... |
736 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 745 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
737 iter != credit_cards->end(); ++iter) { | 746 iter != credit_cards->end(); ++iter) { |
738 credit_cards_.push_back(new CreditCard(*iter)); | 747 credit_cards_.push_back(new CreditCard(*iter)); |
739 } | 748 } |
740 | 749 |
741 // Refresh our local cache and send notifications to observers. | 750 // Refresh our local cache and send notifications to observers. |
742 Refresh(); | 751 Refresh(); |
743 } | 752 } |
744 | 753 |
745 void PersonalDataManager::LoadProfiles() { | 754 void PersonalDataManager::LoadProfiles() { |
746 WebDataService* web_data_service = | 755 scoped_refptr<WebDataService> web_data_service = |
747 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 756 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
748 if (!web_data_service) { | 757 if (!web_data_service.get()) { |
749 NOTREACHED(); | 758 NOTREACHED(); |
750 return; | 759 return; |
751 } | 760 } |
752 | 761 |
753 CancelPendingQuery(&pending_profiles_query_); | 762 CancelPendingQuery(&pending_profiles_query_); |
754 | 763 |
755 pending_profiles_query_ = web_data_service->GetAutofillProfiles(this); | 764 pending_profiles_query_ = web_data_service->GetAutofillProfiles(this); |
756 } | 765 } |
757 | 766 |
758 // Win and Linux implementations do nothing. Mac implementation fills in the | 767 // Win and Linux implementations do nothing. Mac implementation fills in the |
759 // contents of |auxiliary_profiles_|. | 768 // contents of |auxiliary_profiles_|. |
760 #if !defined(OS_MACOSX) | 769 #if !defined(OS_MACOSX) |
761 void PersonalDataManager::LoadAuxiliaryProfiles() const { | 770 void PersonalDataManager::LoadAuxiliaryProfiles() const { |
762 } | 771 } |
763 #endif | 772 #endif |
764 | 773 |
765 void PersonalDataManager::LoadCreditCards() { | 774 void PersonalDataManager::LoadCreditCards() { |
766 WebDataService* web_data_service = | 775 scoped_refptr<WebDataService> web_data_service = |
767 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 776 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
768 if (!web_data_service) { | 777 if (!web_data_service.get()) { |
769 NOTREACHED(); | 778 NOTREACHED(); |
770 return; | 779 return; |
771 } | 780 } |
772 | 781 |
773 CancelPendingQuery(&pending_creditcards_query_); | 782 CancelPendingQuery(&pending_creditcards_query_); |
774 | 783 |
775 pending_creditcards_query_ = web_data_service->GetCreditCards(this); | 784 pending_creditcards_query_ = web_data_service->GetCreditCards(this); |
776 } | 785 } |
777 | 786 |
778 void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, | 787 void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, |
(...skipping 28 matching lines...) Expand all Loading... |
807 | 816 |
808 std::vector<CreditCard*> credit_cards = r->GetValue(); | 817 std::vector<CreditCard*> credit_cards = r->GetValue(); |
809 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); | 818 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); |
810 iter != credit_cards.end(); ++iter) { | 819 iter != credit_cards.end(); ++iter) { |
811 credit_cards_.push_back(*iter); | 820 credit_cards_.push_back(*iter); |
812 } | 821 } |
813 } | 822 } |
814 | 823 |
815 void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) { | 824 void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) { |
816 if (*handle) { | 825 if (*handle) { |
817 WebDataService* web_data_service = | 826 scoped_refptr<WebDataService> web_data_service = |
818 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 827 WebDataServiceFactory::GetForProfile(profile_, |
819 if (!web_data_service) { | 828 Profile::EXPLICIT_ACCESS); |
| 829 if (!web_data_service.get()) { |
820 NOTREACHED(); | 830 NOTREACHED(); |
821 return; | 831 return; |
822 } | 832 } |
823 web_data_service->CancelRequest(*handle); | 833 web_data_service->CancelRequest(*handle); |
824 } | 834 } |
825 *handle = 0; | 835 *handle = 0; |
826 } | 836 } |
827 | 837 |
828 void PersonalDataManager::SaveImportedProfile( | 838 void PersonalDataManager::SaveImportedProfile( |
829 const AutofillProfile& imported_profile) { | 839 const AutofillProfile& imported_profile) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 if (!merged) | 887 if (!merged) |
878 creditcards.push_back(imported_credit_card); | 888 creditcards.push_back(imported_credit_card); |
879 | 889 |
880 SetCreditCards(&creditcards); | 890 SetCreditCards(&creditcards); |
881 } | 891 } |
882 | 892 |
883 void PersonalDataManager::EmptyMigrationTrash() { | 893 void PersonalDataManager::EmptyMigrationTrash() { |
884 if (!profile_ || profile_->IsOffTheRecord()) | 894 if (!profile_ || profile_->IsOffTheRecord()) |
885 return; | 895 return; |
886 | 896 |
887 WebDataService* web_data_service = | 897 scoped_refptr<WebDataService> web_data_service = |
888 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 898 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
889 if (!web_data_service) { | 899 if (!web_data_service.get()) { |
890 NOTREACHED(); | 900 NOTREACHED(); |
891 return; | 901 return; |
892 } | 902 } |
893 | 903 |
894 ProfileSyncService* sync_service = | 904 ProfileSyncService* sync_service = |
895 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | 905 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
896 if (!sync_service) | 906 if (!sync_service) |
897 return; | 907 return; |
898 | 908 |
899 if (!sync_service->HasSyncSetupCompleted()) { | 909 if (!sync_service->HasSyncSetupCompleted()) { |
(...skipping 16 matching lines...) Expand all Loading... |
916 } | 926 } |
917 | 927 |
918 const AutofillMetrics* PersonalDataManager::metric_logger() const { | 928 const AutofillMetrics* PersonalDataManager::metric_logger() const { |
919 return metric_logger_.get(); | 929 return metric_logger_.get(); |
920 } | 930 } |
921 | 931 |
922 void PersonalDataManager::set_metric_logger( | 932 void PersonalDataManager::set_metric_logger( |
923 const AutofillMetrics* metric_logger) { | 933 const AutofillMetrics* metric_logger) { |
924 metric_logger_.reset(metric_logger); | 934 metric_logger_.reset(metric_logger); |
925 } | 935 } |
OLD | NEW |