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

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

Issue 10185008: Taking over issue 10006037: Moved WebDataService to ProfileKeyedService (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_, 164 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_,
164 OnPersonalDataChanged()); 165 OnPersonalDataChanged());
165 166
166 // As all Autofill data is ready, the Autocomplete data is ready as well. 167 // As all Autofill data is ready, the Autocomplete data is ready as well.
167 // If sync is not set, cull older entries of the autocomplete. Otherwise, 168 // If sync is not set, cull older entries of the autocomplete. Otherwise,
168 // the entries will be culled when sync is connected. 169 // the entries will be culled when sync is connected.
169 ProfileSyncService* sync_service = 170 ProfileSyncService* sync_service =
170 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); 171 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
171 if (sync_service && (!sync_service->HasSyncSetupCompleted() || 172 if (sync_service && (!sync_service->HasSyncSetupCompleted() ||
172 !profile_->GetPrefs()->GetBoolean(prefs::kSyncAutofill))) { 173 !profile_->GetPrefs()->GetBoolean(prefs::kSyncAutofill))) {
173 WebDataService* wds = 174 scoped_refptr<WebDataService> web_data_service =
174 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 175 WebDataServiceFactory::GetForProfile(profile_,
175 if (wds) 176 Profile::EXPLICIT_ACCESS);
176 wds->RemoveExpiredFormElements(); 177 if (web_data_service)
178 web_data_service->RemoveExpiredFormElements();
177 } 179 }
178 } 180 }
179 } 181 }
180 182
181 void PersonalDataManager::SetObserver(PersonalDataManagerObserver* observer) { 183 void PersonalDataManager::SetObserver(PersonalDataManagerObserver* observer) {
182 // TODO(dhollowa): RemoveObserver is for compatibility with old code, it 184 // TODO(dhollowa): RemoveObserver is for compatibility with old code, it
183 // should be nuked. 185 // should be nuked.
184 observers_.RemoveObserver(observer); 186 observers_.RemoveObserver(observer);
185 observers_.AddObserver(observer); 187 observers_.AddObserver(observer);
186 } 188 }
187 189
188 void PersonalDataManager::RemoveObserver( 190 void PersonalDataManager::RemoveObserver(
189 PersonalDataManagerObserver* observer) { 191 PersonalDataManagerObserver* observer) {
190 observers_.RemoveObserver(observer); 192 observers_.RemoveObserver(observer);
191 } 193 }
192 194
193 // The |PersonalDataManager| is set up as a listener of the sync service in 195 // 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 196 // |EmptyMigrationTrash| in the case where sync is not yet ready to receive
195 // changes. This method, |OnStateChange| acts as a deferred call to 197 // changes. This method, |OnStateChange| acts as a deferred call to
196 // |EmptyMigrationTrash| once the sync service becomes available. 198 // |EmptyMigrationTrash| once the sync service becomes available.
197 void PersonalDataManager::OnStateChanged() { 199 void PersonalDataManager::OnStateChanged() {
198 if (!profile_ || profile_->IsOffTheRecord()) 200 if (!profile_ || profile_->IsOffTheRecord())
199 return; 201 return;
200 202
201 WebDataService* web_data_service = 203 scoped_refptr<WebDataService> web_data_service =
202 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 204 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
203 if (!web_data_service) { 205 if (!web_data_service.get()) {
204 NOTREACHED(); 206 NOTREACHED();
205 return; 207 return;
206 } 208 }
207 209
208 ProfileSyncService* sync_service = 210 ProfileSyncService* sync_service =
209 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); 211 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
210 if (!sync_service) 212 if (!sync_service)
211 return; 213 return;
212 214
213 if (sync_service->ShouldPushChanges()) { 215 if (sync_service->ShouldPushChanges()) {
214 web_data_service->EmptyMigrationTrash(true); 216 web_data_service->EmptyMigrationTrash(true);
215 sync_service->RemoveObserver(this); 217 sync_service->RemoveObserver(this);
216 } 218 }
217 } 219 }
218 220
219 void PersonalDataManager::Shutdown() { 221 void PersonalDataManager::Shutdown() {
220 CancelPendingQuery(&pending_profiles_query_); 222 CancelPendingQuery(&pending_profiles_query_);
221 CancelPendingQuery(&pending_creditcards_query_); 223 CancelPendingQuery(&pending_creditcards_query_);
222 notification_registrar_.RemoveAll(); 224 notification_registrar_.RemoveAll();
223 } 225 }
224 226
225 void PersonalDataManager::Observe(int type, 227 void PersonalDataManager::Observe(int type,
226 const content::NotificationSource& source, 228 const content::NotificationSource& source,
227 const content::NotificationDetails& details) { 229 const content::NotificationDetails& details) {
228 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); 230 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED);
229 WebDataService* web_data_service = 231 scoped_refptr<WebDataService> web_data_service =
230 content::Source<WebDataService>(source).ptr(); 232 content::Source<WebDataService>(source).ptr();
231 233
232 DCHECK(web_data_service && 234 DCHECK(web_data_service.get() &&
233 web_data_service == 235 web_data_service.get() == WebDataServiceFactory::GetForProfile(
234 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)); 236 profile_, Profile::EXPLICIT_ACCESS).get());
235 Refresh(); 237 Refresh();
236 } 238 }
237 239
238 bool PersonalDataManager::ImportFormData( 240 bool PersonalDataManager::ImportFormData(
239 const FormStructure& form, 241 const FormStructure& form,
240 const CreditCard** imported_credit_card) { 242 const CreditCard** imported_credit_card) {
241 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); 243 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile);
242 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); 244 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard);
243 245
244 // Parse the form and construct a profile based on the information that is 246 // 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
357 if (profile_->IsOffTheRecord()) 359 if (profile_->IsOffTheRecord())
358 return; 360 return;
359 361
360 if (profile.IsEmpty()) 362 if (profile.IsEmpty())
361 return; 363 return;
362 364
363 // Don't add an existing profile. 365 // Don't add an existing profile.
364 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) 366 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
365 return; 367 return;
366 368
367 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 369 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
368 if (!wds) 370 profile_, Profile::EXPLICIT_ACCESS);
371 if (!wds.get())
369 return; 372 return;
370 373
371 // Don't add a duplicate. 374 // Don't add a duplicate.
372 if (FindByContents(web_profiles_, profile)) 375 if (FindByContents(web_profiles_, profile))
373 return; 376 return;
374 377
375 // Add the new profile to the web database. 378 // Add the new profile to the web database.
376 wds->AddAutofillProfile(profile); 379 wds->AddAutofillProfile(profile);
377 380
378 // Refresh our local cache and send notifications to observers. 381 // Refresh our local cache and send notifications to observers.
379 Refresh(); 382 Refresh();
380 } 383 }
381 384
382 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { 385 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) {
383 if (profile_->IsOffTheRecord()) 386 if (profile_->IsOffTheRecord())
384 return; 387 return;
385 388
386 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) 389 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
387 return; 390 return;
388 391
389 if (profile.IsEmpty()) { 392 if (profile.IsEmpty()) {
390 RemoveProfile(profile.guid()); 393 RemoveProfile(profile.guid());
391 return; 394 return;
392 } 395 }
393 396
394 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 397 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
395 if (!wds) 398 profile_, Profile::EXPLICIT_ACCESS);
399 if (!wds.get())
396 return; 400 return;
397 401
398 // Make the update. 402 // Make the update.
399 wds->UpdateAutofillProfile(profile); 403 wds->UpdateAutofillProfile(profile);
400 404
401 // Refresh our local cache and send notifications to observers. 405 // Refresh our local cache and send notifications to observers.
402 Refresh(); 406 Refresh();
403 } 407 }
404 408
405 void PersonalDataManager::RemoveProfile(const std::string& guid) { 409 void PersonalDataManager::RemoveProfile(const std::string& guid) {
406 if (profile_->IsOffTheRecord()) 410 if (profile_->IsOffTheRecord())
407 return; 411 return;
408 412
409 if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) 413 if (!FindByGUID<AutofillProfile>(web_profiles_, guid))
410 return; 414 return;
411 415
412 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 416 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
413 if (!wds) 417 profile_, Profile::EXPLICIT_ACCESS);
418 if (!wds.get())
414 return; 419 return;
415 420
416 // Remove the profile. 421 // Remove the profile.
417 wds->RemoveAutofillProfile(guid); 422 wds->RemoveAutofillProfile(guid);
418 423
419 // Refresh our local cache and send notifications to observers. 424 // Refresh our local cache and send notifications to observers.
420 Refresh(); 425 Refresh();
421 } 426 }
422 427
423 AutofillProfile* PersonalDataManager::GetProfileByGUID( 428 AutofillProfile* PersonalDataManager::GetProfileByGUID(
424 const std::string& guid) { 429 const std::string& guid) {
425 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_->begin(); 430 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_->begin();
426 iter != web_profiles_->end(); ++iter) { 431 iter != web_profiles_->end(); ++iter) {
427 if ((*iter)->guid() == guid) 432 if ((*iter)->guid() == guid)
428 return *iter; 433 return *iter;
429 } 434 }
430 return NULL; 435 return NULL;
431 } 436 }
432 437
433 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { 438 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) {
434 if (profile_->IsOffTheRecord()) 439 if (profile_->IsOffTheRecord())
435 return; 440 return;
436 441
437 if (credit_card.IsEmpty()) 442 if (credit_card.IsEmpty())
438 return; 443 return;
439 444
440 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) 445 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
441 return; 446 return;
442 447
443 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 448 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
444 if (!wds) 449 profile_, Profile::EXPLICIT_ACCESS);
450 if (!wds.get())
445 return; 451 return;
446 452
447 // Don't add a duplicate. 453 // Don't add a duplicate.
448 if (FindByContents(credit_cards_, credit_card)) 454 if (FindByContents(credit_cards_, credit_card))
449 return; 455 return;
450 456
451 // Add the new credit card to the web database. 457 // Add the new credit card to the web database.
452 wds->AddCreditCard(credit_card); 458 wds->AddCreditCard(credit_card);
453 459
454 // Refresh our local cache and send notifications to observers. 460 // Refresh our local cache and send notifications to observers.
455 Refresh(); 461 Refresh();
456 } 462 }
457 463
458 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { 464 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) {
459 if (profile_->IsOffTheRecord()) 465 if (profile_->IsOffTheRecord())
460 return; 466 return;
461 467
462 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) 468 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
463 return; 469 return;
464 470
465 if (credit_card.IsEmpty()) { 471 if (credit_card.IsEmpty()) {
466 RemoveCreditCard(credit_card.guid()); 472 RemoveCreditCard(credit_card.guid());
467 return; 473 return;
468 } 474 }
469 475
470 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 476 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
471 if (!wds) 477 profile_, Profile::EXPLICIT_ACCESS);
478 if (!wds.get())
472 return; 479 return;
473 480
474 // Make the update. 481 // Make the update.
475 wds->UpdateCreditCard(credit_card); 482 wds->UpdateCreditCard(credit_card);
476 483
477 // Refresh our local cache and send notifications to observers. 484 // Refresh our local cache and send notifications to observers.
478 Refresh(); 485 Refresh();
479 } 486 }
480 487
481 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { 488 void PersonalDataManager::RemoveCreditCard(const std::string& guid) {
482 if (profile_->IsOffTheRecord()) 489 if (profile_->IsOffTheRecord())
483 return; 490 return;
484 491
485 if (!FindByGUID<CreditCard>(credit_cards_, guid)) 492 if (!FindByGUID<CreditCard>(credit_cards_, guid))
486 return; 493 return;
487 494
488 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 495 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
489 if (!wds) 496 profile_, Profile::EXPLICIT_ACCESS);
497 if (!wds.get())
490 return; 498 return;
491 499
492 // Remove the credit card. 500 // Remove the credit card.
493 wds->RemoveCreditCard(guid); 501 wds->RemoveCreditCard(guid);
494 502
495 // Refresh our local cache and send notifications to observers. 503 // Refresh our local cache and send notifications to observers.
496 Refresh(); 504 Refresh();
497 } 505 }
498 506
499 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { 507 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 pending_creditcards_query_(0), 573 pending_creditcards_query_(0),
566 metric_logger_(new AutofillMetrics), 574 metric_logger_(new AutofillMetrics),
567 has_logged_profile_count_(false) { 575 has_logged_profile_count_(false) {
568 } 576 }
569 577
570 void PersonalDataManager::Init(Profile* profile) { 578 void PersonalDataManager::Init(Profile* profile) {
571 profile_ = profile; 579 profile_ = profile;
572 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); 580 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled());
573 581
574 // WebDataService may not be available in tests. 582 // WebDataService may not be available in tests.
575 WebDataService* web_data_service = 583 scoped_refptr<WebDataService> web_data_service =
576 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 584 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
577 if (!web_data_service) 585 if (!web_data_service.get())
578 return; 586 return;
579 587
580 LoadProfiles(); 588 LoadProfiles();
581 LoadCreditCards(); 589 LoadCreditCards();
582 590
583 notification_registrar_.Add( 591 notification_registrar_.Add(
584 this, 592 this,
585 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, 593 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED,
586 content::Source<WebDataService>(web_data_service)); 594 content::Source<WebDataService>(web_data_service));
587 } 595 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 668
661 // Ensure that profile labels are up to date. Currently, sync relies on 669 // Ensure that profile labels are up to date. Currently, sync relies on
662 // labels to identify a profile. 670 // labels to identify a profile.
663 // TODO(dhollowa): We need to deprecate labels and update the way sync 671 // TODO(dhollowa): We need to deprecate labels and update the way sync
664 // identifies profiles. 672 // identifies profiles.
665 std::vector<AutofillProfile*> profile_pointers(profiles->size()); 673 std::vector<AutofillProfile*> profile_pointers(profiles->size());
666 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), 674 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(),
667 address_of<AutofillProfile>); 675 address_of<AutofillProfile>);
668 AutofillProfile::AdjustInferredLabels(&profile_pointers); 676 AutofillProfile::AdjustInferredLabels(&profile_pointers);
669 677
670 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 678 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
671 if (!wds) 679 profile_, Profile::EXPLICIT_ACCESS);
680 if (!wds.get())
672 return; 681 return;
673 682
674 // Any profiles that are not in the new profile list should be removed from 683 // Any profiles that are not in the new profile list should be removed from
675 // the web database. 684 // the web database.
676 for (std::vector<AutofillProfile*>::const_iterator iter = 685 for (std::vector<AutofillProfile*>::const_iterator iter =
677 web_profiles_.begin(); 686 web_profiles_.begin();
678 iter != web_profiles_.end(); ++iter) { 687 iter != web_profiles_.end(); ++iter) {
679 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) 688 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid()))
680 wds->RemoveAutofillProfile((*iter)->guid()); 689 wds->RemoveAutofillProfile((*iter)->guid());
681 } 690 }
(...skipping 29 matching lines...) Expand all
711 if (profile_->IsOffTheRecord()) 720 if (profile_->IsOffTheRecord())
712 return; 721 return;
713 722
714 // Remove empty credit cards from input. 723 // Remove empty credit cards from input.
715 credit_cards->erase( 724 credit_cards->erase(
716 std::remove_if( 725 std::remove_if(
717 credit_cards->begin(), credit_cards->end(), 726 credit_cards->begin(), credit_cards->end(),
718 std::mem_fun_ref(&CreditCard::IsEmpty)), 727 std::mem_fun_ref(&CreditCard::IsEmpty)),
719 credit_cards->end()); 728 credit_cards->end());
720 729
721 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 730 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile(
722 if (!wds) 731 profile_, Profile::EXPLICIT_ACCESS);
732 if (!wds.get())
723 return; 733 return;
724 734
725 // Any credit cards that are not in the new credit card list should be 735 // Any credit cards that are not in the new credit card list should be
726 // removed. 736 // removed.
727 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); 737 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin();
728 iter != credit_cards_.end(); ++iter) { 738 iter != credit_cards_.end(); ++iter) {
729 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) 739 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid()))
730 wds->RemoveCreditCard((*iter)->guid()); 740 wds->RemoveCreditCard((*iter)->guid());
731 } 741 }
732 742
(...skipping 17 matching lines...) Expand all
750 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); 760 for (std::vector<CreditCard>::iterator iter = credit_cards->begin();
751 iter != credit_cards->end(); ++iter) { 761 iter != credit_cards->end(); ++iter) {
752 credit_cards_.push_back(new CreditCard(*iter)); 762 credit_cards_.push_back(new CreditCard(*iter));
753 } 763 }
754 764
755 // Refresh our local cache and send notifications to observers. 765 // Refresh our local cache and send notifications to observers.
756 Refresh(); 766 Refresh();
757 } 767 }
758 768
759 void PersonalDataManager::LoadProfiles() { 769 void PersonalDataManager::LoadProfiles() {
760 WebDataService* web_data_service = 770 scoped_refptr<WebDataService> web_data_service =
761 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 771 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
762 if (!web_data_service) { 772 if (!web_data_service.get()) {
763 NOTREACHED(); 773 NOTREACHED();
764 return; 774 return;
765 } 775 }
766 776
767 CancelPendingQuery(&pending_profiles_query_); 777 CancelPendingQuery(&pending_profiles_query_);
768 778
769 pending_profiles_query_ = web_data_service->GetAutofillProfiles(this); 779 pending_profiles_query_ = web_data_service->GetAutofillProfiles(this);
770 } 780 }
771 781
772 // Win and Linux implementations do nothing. Mac implementation fills in the 782 // Win and Linux implementations do nothing. Mac implementation fills in the
773 // contents of |auxiliary_profiles_|. 783 // contents of |auxiliary_profiles_|.
774 #if !defined(OS_MACOSX) 784 #if !defined(OS_MACOSX)
775 void PersonalDataManager::LoadAuxiliaryProfiles() const { 785 void PersonalDataManager::LoadAuxiliaryProfiles() const {
776 } 786 }
777 #endif 787 #endif
778 788
779 void PersonalDataManager::LoadCreditCards() { 789 void PersonalDataManager::LoadCreditCards() {
780 WebDataService* web_data_service = 790 scoped_refptr<WebDataService> web_data_service =
781 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 791 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
782 if (!web_data_service) { 792 if (!web_data_service.get()) {
783 NOTREACHED(); 793 NOTREACHED();
784 return; 794 return;
785 } 795 }
786 796
787 CancelPendingQuery(&pending_creditcards_query_); 797 CancelPendingQuery(&pending_creditcards_query_);
788 798
789 pending_creditcards_query_ = web_data_service->GetCreditCards(this); 799 pending_creditcards_query_ = web_data_service->GetCreditCards(this);
790 } 800 }
791 801
792 void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, 802 void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h,
(...skipping 28 matching lines...) Expand all
821 831
822 std::vector<CreditCard*> credit_cards = r->GetValue(); 832 std::vector<CreditCard*> credit_cards = r->GetValue();
823 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); 833 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin();
824 iter != credit_cards.end(); ++iter) { 834 iter != credit_cards.end(); ++iter) {
825 credit_cards_.push_back(*iter); 835 credit_cards_.push_back(*iter);
826 } 836 }
827 } 837 }
828 838
829 void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) { 839 void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) {
830 if (*handle) { 840 if (*handle) {
831 WebDataService* web_data_service = 841 scoped_refptr<WebDataService> web_data_service =
832 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 842 WebDataServiceFactory::GetForProfile(profile_,
833 if (!web_data_service) { 843 Profile::EXPLICIT_ACCESS);
844 if (!web_data_service.get()) {
834 NOTREACHED(); 845 NOTREACHED();
835 return; 846 return;
836 } 847 }
837 web_data_service->CancelRequest(*handle); 848 web_data_service->CancelRequest(*handle);
838 } 849 }
839 *handle = 0; 850 *handle = 0;
840 } 851 }
841 852
842 void PersonalDataManager::SaveImportedProfile( 853 void PersonalDataManager::SaveImportedProfile(
843 const AutofillProfile& imported_profile) { 854 const AutofillProfile& imported_profile) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 if (!merged) 902 if (!merged)
892 creditcards.push_back(imported_credit_card); 903 creditcards.push_back(imported_credit_card);
893 904
894 SetCreditCards(&creditcards); 905 SetCreditCards(&creditcards);
895 } 906 }
896 907
897 void PersonalDataManager::EmptyMigrationTrash() { 908 void PersonalDataManager::EmptyMigrationTrash() {
898 if (!profile_ || profile_->IsOffTheRecord()) 909 if (!profile_ || profile_->IsOffTheRecord())
899 return; 910 return;
900 911
901 WebDataService* web_data_service = 912 scoped_refptr<WebDataService> web_data_service =
902 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); 913 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
903 if (!web_data_service) { 914 if (!web_data_service.get()) {
904 NOTREACHED(); 915 NOTREACHED();
905 return; 916 return;
906 } 917 }
907 918
908 ProfileSyncService* sync_service = 919 ProfileSyncService* sync_service =
909 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); 920 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
910 if (!sync_service) 921 if (!sync_service)
911 return; 922 return;
912 923
913 if (!sync_service->HasSyncSetupCompleted()) { 924 if (!sync_service->HasSyncSetupCompleted()) {
(...skipping 16 matching lines...) Expand all
930 } 941 }
931 942
932 const AutofillMetrics* PersonalDataManager::metric_logger() const { 943 const AutofillMetrics* PersonalDataManager::metric_logger() const {
933 return metric_logger_.get(); 944 return metric_logger_.get();
934 } 945 }
935 946
936 void PersonalDataManager::set_metric_logger( 947 void PersonalDataManager::set_metric_logger(
937 const AutofillMetrics* metric_logger) { 948 const AutofillMetrics* metric_logger) {
938 metric_logger_.reset(metric_logger); 949 metric_logger_.reset(metric_logger);
939 } 950 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_metrics_unittest.cc ('k') | chrome/browser/autofill/personal_data_manager_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698