| 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" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 std::copy(web_profiles_.begin(), web_profiles_.end(), | 160 std::copy(web_profiles_.begin(), web_profiles_.end(), |
| 161 profile_pointers.begin()); | 161 profile_pointers.begin()); |
| 162 AutofillProfile::AdjustInferredLabels(&profile_pointers); | 162 AutofillProfile::AdjustInferredLabels(&profile_pointers); |
| 163 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_, | 163 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_, |
| 164 OnPersonalDataChanged()); | 164 OnPersonalDataChanged()); |
| 165 | 165 |
| 166 // As all Autofill data is ready, the Autocomplete data is ready as well. | 166 // 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, | 167 // If sync is not set, cull older entries of the autocomplete. Otherwise, |
| 168 // the entries will be culled when sync is connected. | 168 // the entries will be culled when sync is connected. |
| 169 ProfileSyncServiceBase* sync_service = | 169 ProfileSyncServiceBase* sync_service = |
| 170 ProfileSyncServiceBase::ForContext(browser_context_); | 170 ProfileSyncServiceBase::FromBrowserContext(browser_context_); |
| 171 if (sync_service && (!sync_service->HasSyncSetupCompleted() || | 171 if (sync_service && (!sync_service->HasSyncSetupCompleted() || |
| 172 !PrefServiceBase::ForContext( | 172 !PrefServiceBase::FromBrowserContext( |
| 173 browser_context_)->GetBoolean( | 173 browser_context_)->GetBoolean( |
| 174 prefs::kSyncAutofill))) { | 174 prefs::kSyncAutofill))) { |
| 175 scoped_ptr<AutofillWebDataService> service( | 175 scoped_ptr<AutofillWebDataService> service( |
| 176 AutofillWebDataService::ForContext(browser_context_)); | 176 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 177 if (service.get()) | 177 if (service.get()) |
| 178 service->RemoveExpiredFormElements(); | 178 service->RemoveExpiredFormElements(); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 void PersonalDataManager::SetObserver(PersonalDataManagerObserver* observer) { | 183 void PersonalDataManager::SetObserver(PersonalDataManagerObserver* observer) { |
| 184 // TODO(dhollowa): RemoveObserver is for compatibility with old code, it | 184 // TODO(dhollowa): RemoveObserver is for compatibility with old code, it |
| 185 // should be nuked. | 185 // should be nuked. |
| 186 observers_.RemoveObserver(observer); | 186 observers_.RemoveObserver(observer); |
| 187 observers_.AddObserver(observer); | 187 observers_.AddObserver(observer); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void PersonalDataManager::RemoveObserver( | 190 void PersonalDataManager::RemoveObserver( |
| 191 PersonalDataManagerObserver* observer) { | 191 PersonalDataManagerObserver* observer) { |
| 192 observers_.RemoveObserver(observer); | 192 observers_.RemoveObserver(observer); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // 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 |
| 196 // |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 |
| 197 // changes. This method, |OnStateChange| acts as a deferred call to | 197 // changes. This method, |OnStateChange| acts as a deferred call to |
| 198 // |EmptyMigrationTrash| once the sync service becomes available. | 198 // |EmptyMigrationTrash| once the sync service becomes available. |
| 199 void PersonalDataManager::OnStateChanged() { | 199 void PersonalDataManager::OnStateChanged() { |
| 200 if (!browser_context_ || browser_context_->IsOffTheRecord()) | 200 if (!browser_context_ || browser_context_->IsOffTheRecord()) |
| 201 return; | 201 return; |
| 202 | 202 |
| 203 scoped_ptr<AutofillWebDataService> autofill_data( | 203 scoped_ptr<AutofillWebDataService> autofill_data( |
| 204 AutofillWebDataService::ForContext(browser_context_)); | 204 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 205 if (!autofill_data.get()) { | 205 if (!autofill_data.get()) { |
| 206 NOTREACHED(); | 206 NOTREACHED(); |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 | 209 |
| 210 ProfileSyncServiceBase* sync_service = | 210 ProfileSyncServiceBase* sync_service = |
| 211 ProfileSyncServiceBase::ForContext(browser_context_); | 211 ProfileSyncServiceBase::FromBrowserContext(browser_context_); |
| 212 if (!sync_service) | 212 if (!sync_service) |
| 213 return; | 213 return; |
| 214 | 214 |
| 215 if (sync_service->ShouldPushChanges()) { | 215 if (sync_service->ShouldPushChanges()) { |
| 216 autofill_data->EmptyMigrationTrash(true); | 216 autofill_data->EmptyMigrationTrash(true); |
| 217 sync_service->RemoveObserver(this); | 217 sync_service->RemoveObserver(this); |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 void PersonalDataManager::Shutdown() { | 221 void PersonalDataManager::Shutdown() { |
| 222 CancelPendingQuery(&pending_profiles_query_); | 222 CancelPendingQuery(&pending_profiles_query_); |
| 223 CancelPendingQuery(&pending_creditcards_query_); | 223 CancelPendingQuery(&pending_creditcards_query_); |
| 224 notification_registrar_.RemoveAll(); | 224 notification_registrar_.RemoveAll(); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void PersonalDataManager::Observe(int type, | 227 void PersonalDataManager::Observe(int type, |
| 228 const content::NotificationSource& source, | 228 const content::NotificationSource& source, |
| 229 const content::NotificationDetails& details) { | 229 const content::NotificationDetails& details) { |
| 230 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); | 230 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); |
| 231 | 231 |
| 232 if (DCHECK_IS_ON()) { | 232 if (DCHECK_IS_ON()) { |
| 233 scoped_ptr<AutofillWebDataService> autofill_data( | 233 scoped_ptr<AutofillWebDataService> autofill_data( |
| 234 AutofillWebDataService::ForContext(browser_context_)); | 234 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 235 | 235 |
| 236 DCHECK(autofill_data.get() && | 236 DCHECK(autofill_data.get() && |
| 237 autofill_data->GetNotificationSource() == source); | 237 autofill_data->GetNotificationSource() == source); |
| 238 } | 238 } |
| 239 | 239 |
| 240 Refresh(); | 240 Refresh(); |
| 241 } | 241 } |
| 242 | 242 |
| 243 bool PersonalDataManager::ImportFormData( | 243 bool PersonalDataManager::ImportFormData( |
| 244 const FormStructure& form, | 244 const FormStructure& form, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 return; | 363 return; |
| 364 | 364 |
| 365 if (profile.IsEmpty()) | 365 if (profile.IsEmpty()) |
| 366 return; | 366 return; |
| 367 | 367 |
| 368 // Don't add an existing profile. | 368 // Don't add an existing profile. |
| 369 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) | 369 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
| 370 return; | 370 return; |
| 371 | 371 |
| 372 scoped_ptr<AutofillWebDataService> autofill_data( | 372 scoped_ptr<AutofillWebDataService> autofill_data( |
| 373 AutofillWebDataService::ForContext(browser_context_)); | 373 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 374 if (!autofill_data.get()) | 374 if (!autofill_data.get()) |
| 375 return; | 375 return; |
| 376 | 376 |
| 377 // Don't add a duplicate. | 377 // Don't add a duplicate. |
| 378 if (FindByContents(web_profiles_, profile)) | 378 if (FindByContents(web_profiles_, profile)) |
| 379 return; | 379 return; |
| 380 | 380 |
| 381 // Add the new profile to the web database. | 381 // Add the new profile to the web database. |
| 382 autofill_data->AddAutofillProfile(profile); | 382 autofill_data->AddAutofillProfile(profile); |
| 383 | 383 |
| 384 // Refresh our local cache and send notifications to observers. | 384 // Refresh our local cache and send notifications to observers. |
| 385 Refresh(); | 385 Refresh(); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { | 388 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { |
| 389 if (browser_context_->IsOffTheRecord()) | 389 if (browser_context_->IsOffTheRecord()) |
| 390 return; | 390 return; |
| 391 | 391 |
| 392 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) | 392 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
| 393 return; | 393 return; |
| 394 | 394 |
| 395 if (profile.IsEmpty()) { | 395 if (profile.IsEmpty()) { |
| 396 RemoveProfile(profile.guid()); | 396 RemoveProfile(profile.guid()); |
| 397 return; | 397 return; |
| 398 } | 398 } |
| 399 | 399 |
| 400 scoped_ptr<AutofillWebDataService> autofill_data( | 400 scoped_ptr<AutofillWebDataService> autofill_data( |
| 401 AutofillWebDataService::ForContext(browser_context_)); | 401 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 402 if (!autofill_data.get()) | 402 if (!autofill_data.get()) |
| 403 return; | 403 return; |
| 404 | 404 |
| 405 // Make the update. | 405 // Make the update. |
| 406 autofill_data->UpdateAutofillProfile(profile); | 406 autofill_data->UpdateAutofillProfile(profile); |
| 407 | 407 |
| 408 // Refresh our local cache and send notifications to observers. | 408 // Refresh our local cache and send notifications to observers. |
| 409 Refresh(); | 409 Refresh(); |
| 410 } | 410 } |
| 411 | 411 |
| 412 void PersonalDataManager::RemoveProfile(const std::string& guid) { | 412 void PersonalDataManager::RemoveProfile(const std::string& guid) { |
| 413 if (browser_context_->IsOffTheRecord()) | 413 if (browser_context_->IsOffTheRecord()) |
| 414 return; | 414 return; |
| 415 | 415 |
| 416 if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) | 416 if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) |
| 417 return; | 417 return; |
| 418 | 418 |
| 419 scoped_ptr<AutofillWebDataService> autofill_data( | 419 scoped_ptr<AutofillWebDataService> autofill_data( |
| 420 AutofillWebDataService::ForContext(browser_context_)); | 420 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 421 if (!autofill_data.get()) | 421 if (!autofill_data.get()) |
| 422 return; | 422 return; |
| 423 | 423 |
| 424 // Remove the profile. | 424 // Remove the profile. |
| 425 autofill_data->RemoveAutofillProfile(guid); | 425 autofill_data->RemoveAutofillProfile(guid); |
| 426 | 426 |
| 427 // Refresh our local cache and send notifications to observers. | 427 // Refresh our local cache and send notifications to observers. |
| 428 Refresh(); | 428 Refresh(); |
| 429 } | 429 } |
| 430 | 430 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 442 if (browser_context_->IsOffTheRecord()) | 442 if (browser_context_->IsOffTheRecord()) |
| 443 return; | 443 return; |
| 444 | 444 |
| 445 if (credit_card.IsEmpty()) | 445 if (credit_card.IsEmpty()) |
| 446 return; | 446 return; |
| 447 | 447 |
| 448 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) | 448 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
| 449 return; | 449 return; |
| 450 | 450 |
| 451 scoped_ptr<AutofillWebDataService> autofill_data( | 451 scoped_ptr<AutofillWebDataService> autofill_data( |
| 452 AutofillWebDataService::ForContext(browser_context_)); | 452 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 453 if (!autofill_data.get()) | 453 if (!autofill_data.get()) |
| 454 return; | 454 return; |
| 455 | 455 |
| 456 // Don't add a duplicate. | 456 // Don't add a duplicate. |
| 457 if (FindByContents(credit_cards_, credit_card)) | 457 if (FindByContents(credit_cards_, credit_card)) |
| 458 return; | 458 return; |
| 459 | 459 |
| 460 // Add the new credit card to the web database. | 460 // Add the new credit card to the web database. |
| 461 autofill_data->AddCreditCard(credit_card); | 461 autofill_data->AddCreditCard(credit_card); |
| 462 | 462 |
| 463 // Refresh our local cache and send notifications to observers. | 463 // Refresh our local cache and send notifications to observers. |
| 464 Refresh(); | 464 Refresh(); |
| 465 } | 465 } |
| 466 | 466 |
| 467 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { | 467 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { |
| 468 if (browser_context_->IsOffTheRecord()) | 468 if (browser_context_->IsOffTheRecord()) |
| 469 return; | 469 return; |
| 470 | 470 |
| 471 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) | 471 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
| 472 return; | 472 return; |
| 473 | 473 |
| 474 if (credit_card.IsEmpty()) { | 474 if (credit_card.IsEmpty()) { |
| 475 RemoveCreditCard(credit_card.guid()); | 475 RemoveCreditCard(credit_card.guid()); |
| 476 return; | 476 return; |
| 477 } | 477 } |
| 478 | 478 |
| 479 scoped_ptr<AutofillWebDataService> autofill_data( | 479 scoped_ptr<AutofillWebDataService> autofill_data( |
| 480 AutofillWebDataService::ForContext(browser_context_)); | 480 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 481 if (!autofill_data.get()) | 481 if (!autofill_data.get()) |
| 482 return; | 482 return; |
| 483 | 483 |
| 484 // Make the update. | 484 // Make the update. |
| 485 autofill_data->UpdateCreditCard(credit_card); | 485 autofill_data->UpdateCreditCard(credit_card); |
| 486 | 486 |
| 487 // Refresh our local cache and send notifications to observers. | 487 // Refresh our local cache and send notifications to observers. |
| 488 Refresh(); | 488 Refresh(); |
| 489 } | 489 } |
| 490 | 490 |
| 491 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { | 491 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { |
| 492 if (browser_context_->IsOffTheRecord()) | 492 if (browser_context_->IsOffTheRecord()) |
| 493 return; | 493 return; |
| 494 | 494 |
| 495 if (!FindByGUID<CreditCard>(credit_cards_, guid)) | 495 if (!FindByGUID<CreditCard>(credit_cards_, guid)) |
| 496 return; | 496 return; |
| 497 | 497 |
| 498 scoped_ptr<AutofillWebDataService> autofill_data( | 498 scoped_ptr<AutofillWebDataService> autofill_data( |
| 499 AutofillWebDataService::ForContext(browser_context_)); | 499 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 500 if (!autofill_data.get()) | 500 if (!autofill_data.get()) |
| 501 return; | 501 return; |
| 502 | 502 |
| 503 // Remove the credit card. | 503 // Remove the credit card. |
| 504 autofill_data->RemoveCreditCard(guid); | 504 autofill_data->RemoveCreditCard(guid); |
| 505 | 505 |
| 506 // Refresh our local cache and send notifications to observers. | 506 // Refresh our local cache and send notifications to observers. |
| 507 Refresh(); | 507 Refresh(); |
| 508 } | 508 } |
| 509 | 509 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 530 } | 530 } |
| 531 } | 531 } |
| 532 | 532 |
| 533 bool PersonalDataManager::IsDataLoaded() const { | 533 bool PersonalDataManager::IsDataLoaded() const { |
| 534 return is_data_loaded_; | 534 return is_data_loaded_; |
| 535 } | 535 } |
| 536 | 536 |
| 537 const std::vector<AutofillProfile*>& PersonalDataManager::profiles() const { | 537 const std::vector<AutofillProfile*>& PersonalDataManager::profiles() const { |
| 538 // |browser_context_| is NULL in AutofillManagerTest. | 538 // |browser_context_| is NULL in AutofillManagerTest. |
| 539 bool auxiliary_profiles_enabled = browser_context_ ? | 539 bool auxiliary_profiles_enabled = browser_context_ ? |
| 540 PrefServiceBase::ForContext(browser_context_)->GetBoolean( | 540 PrefServiceBase::FromBrowserContext(browser_context_)->GetBoolean( |
| 541 prefs::kAutofillAuxiliaryProfilesEnabled) : | 541 prefs::kAutofillAuxiliaryProfilesEnabled) : |
| 542 false; | 542 false; |
| 543 if (!auxiliary_profiles_enabled) | 543 if (!auxiliary_profiles_enabled) |
| 544 return web_profiles(); | 544 return web_profiles(); |
| 545 | 545 |
| 546 #if !defined(OS_MACOSX) | 546 #if !defined(OS_MACOSX) |
| 547 NOTREACHED() << "Auxiliary profiles supported on Mac only"; | 547 NOTREACHED() << "Auxiliary profiles supported on Mac only"; |
| 548 #endif | 548 #endif |
| 549 | 549 |
| 550 profiles_.clear(); | 550 profiles_.clear(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 579 metric_logger_(new AutofillMetrics), | 579 metric_logger_(new AutofillMetrics), |
| 580 has_logged_profile_count_(false) { | 580 has_logged_profile_count_(false) { |
| 581 } | 581 } |
| 582 | 582 |
| 583 void PersonalDataManager::Init(BrowserContext* browser_context) { | 583 void PersonalDataManager::Init(BrowserContext* browser_context) { |
| 584 browser_context_ = browser_context; | 584 browser_context_ = browser_context; |
| 585 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); | 585 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); |
| 586 | 586 |
| 587 // WebDataService may not be available in tests. | 587 // WebDataService may not be available in tests. |
| 588 scoped_ptr<AutofillWebDataService> autofill_data( | 588 scoped_ptr<AutofillWebDataService> autofill_data( |
| 589 AutofillWebDataService::ForContext(browser_context_)); | 589 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 590 if (!autofill_data.get()) | 590 if (!autofill_data.get()) |
| 591 return; | 591 return; |
| 592 | 592 |
| 593 LoadProfiles(); | 593 LoadProfiles(); |
| 594 LoadCreditCards(); | 594 LoadCreditCards(); |
| 595 | 595 |
| 596 notification_registrar_.Add( | 596 notification_registrar_.Add( |
| 597 this, | 597 this, |
| 598 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, | 598 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, |
| 599 autofill_data->GetNotificationSource()); | 599 autofill_data->GetNotificationSource()); |
| 600 } | 600 } |
| 601 | 601 |
| 602 bool PersonalDataManager::IsAutofillEnabled() const { | 602 bool PersonalDataManager::IsAutofillEnabled() const { |
| 603 return PrefServiceBase::ForContext(browser_context_)->GetBoolean( | 603 return PrefServiceBase::FromBrowserContext(browser_context_)->GetBoolean( |
| 604 prefs::kAutofillEnabled); | 604 prefs::kAutofillEnabled); |
| 605 } | 605 } |
| 606 | 606 |
| 607 // static | 607 // static |
| 608 bool PersonalDataManager::IsValidLearnableProfile( | 608 bool PersonalDataManager::IsValidLearnableProfile( |
| 609 const AutofillProfile& profile) { | 609 const AutofillProfile& profile) { |
| 610 if (!IsMinimumAddress(profile)) | 610 if (!IsMinimumAddress(profile)) |
| 611 return false; | 611 return false; |
| 612 | 612 |
| 613 string16 email = profile.GetInfo(EMAIL_ADDRESS); | 613 string16 email = profile.GetInfo(EMAIL_ADDRESS); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 // Ensure that profile labels are up to date. Currently, sync relies on | 675 // Ensure that profile labels are up to date. Currently, sync relies on |
| 676 // labels to identify a profile. | 676 // labels to identify a profile. |
| 677 // TODO(dhollowa): We need to deprecate labels and update the way sync | 677 // TODO(dhollowa): We need to deprecate labels and update the way sync |
| 678 // identifies profiles. | 678 // identifies profiles. |
| 679 std::vector<AutofillProfile*> profile_pointers(profiles->size()); | 679 std::vector<AutofillProfile*> profile_pointers(profiles->size()); |
| 680 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), | 680 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), |
| 681 address_of<AutofillProfile>); | 681 address_of<AutofillProfile>); |
| 682 AutofillProfile::AdjustInferredLabels(&profile_pointers); | 682 AutofillProfile::AdjustInferredLabels(&profile_pointers); |
| 683 | 683 |
| 684 scoped_ptr<AutofillWebDataService> autofill_data( | 684 scoped_ptr<AutofillWebDataService> autofill_data( |
| 685 AutofillWebDataService::ForContext(browser_context_)); | 685 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 686 if (!autofill_data.get()) | 686 if (!autofill_data.get()) |
| 687 return; | 687 return; |
| 688 | 688 |
| 689 // Any profiles that are not in the new profile list should be removed from | 689 // Any profiles that are not in the new profile list should be removed from |
| 690 // the web database. | 690 // the web database. |
| 691 for (std::vector<AutofillProfile*>::const_iterator iter = | 691 for (std::vector<AutofillProfile*>::const_iterator iter = |
| 692 web_profiles_.begin(); | 692 web_profiles_.begin(); |
| 693 iter != web_profiles_.end(); ++iter) { | 693 iter != web_profiles_.end(); ++iter) { |
| 694 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) | 694 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) |
| 695 autofill_data->RemoveAutofillProfile((*iter)->guid()); | 695 autofill_data->RemoveAutofillProfile((*iter)->guid()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 return; | 727 return; |
| 728 | 728 |
| 729 // Remove empty credit cards from input. | 729 // Remove empty credit cards from input. |
| 730 credit_cards->erase( | 730 credit_cards->erase( |
| 731 std::remove_if( | 731 std::remove_if( |
| 732 credit_cards->begin(), credit_cards->end(), | 732 credit_cards->begin(), credit_cards->end(), |
| 733 std::mem_fun_ref(&CreditCard::IsEmpty)), | 733 std::mem_fun_ref(&CreditCard::IsEmpty)), |
| 734 credit_cards->end()); | 734 credit_cards->end()); |
| 735 | 735 |
| 736 scoped_ptr<AutofillWebDataService> autofill_data( | 736 scoped_ptr<AutofillWebDataService> autofill_data( |
| 737 AutofillWebDataService::ForContext(browser_context_)); | 737 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 738 if (!autofill_data.get()) | 738 if (!autofill_data.get()) |
| 739 return; | 739 return; |
| 740 | 740 |
| 741 // Any credit cards that are not in the new credit card list should be | 741 // Any credit cards that are not in the new credit card list should be |
| 742 // removed. | 742 // removed. |
| 743 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); | 743 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); |
| 744 iter != credit_cards_.end(); ++iter) { | 744 iter != credit_cards_.end(); ++iter) { |
| 745 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) | 745 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) |
| 746 autofill_data->RemoveCreditCard((*iter)->guid()); | 746 autofill_data->RemoveCreditCard((*iter)->guid()); |
| 747 } | 747 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 767 iter != credit_cards->end(); ++iter) { | 767 iter != credit_cards->end(); ++iter) { |
| 768 credit_cards_.push_back(new CreditCard(*iter)); | 768 credit_cards_.push_back(new CreditCard(*iter)); |
| 769 } | 769 } |
| 770 | 770 |
| 771 // Refresh our local cache and send notifications to observers. | 771 // Refresh our local cache and send notifications to observers. |
| 772 Refresh(); | 772 Refresh(); |
| 773 } | 773 } |
| 774 | 774 |
| 775 void PersonalDataManager::LoadProfiles() { | 775 void PersonalDataManager::LoadProfiles() { |
| 776 scoped_ptr<AutofillWebDataService> autofill_data( | 776 scoped_ptr<AutofillWebDataService> autofill_data( |
| 777 AutofillWebDataService::ForContext(browser_context_)); | 777 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 778 if (!autofill_data.get()) { | 778 if (!autofill_data.get()) { |
| 779 NOTREACHED(); | 779 NOTREACHED(); |
| 780 return; | 780 return; |
| 781 } | 781 } |
| 782 | 782 |
| 783 CancelPendingQuery(&pending_profiles_query_); | 783 CancelPendingQuery(&pending_profiles_query_); |
| 784 | 784 |
| 785 pending_profiles_query_ = autofill_data->GetAutofillProfiles(this); | 785 pending_profiles_query_ = autofill_data->GetAutofillProfiles(this); |
| 786 } | 786 } |
| 787 | 787 |
| 788 // Win and Linux implementations do nothing. Mac implementation fills in the | 788 // Win and Linux implementations do nothing. Mac implementation fills in the |
| 789 // contents of |auxiliary_profiles_|. | 789 // contents of |auxiliary_profiles_|. |
| 790 #if !defined(OS_MACOSX) | 790 #if !defined(OS_MACOSX) |
| 791 void PersonalDataManager::LoadAuxiliaryProfiles() const { | 791 void PersonalDataManager::LoadAuxiliaryProfiles() const { |
| 792 } | 792 } |
| 793 #endif | 793 #endif |
| 794 | 794 |
| 795 void PersonalDataManager::LoadCreditCards() { | 795 void PersonalDataManager::LoadCreditCards() { |
| 796 scoped_ptr<AutofillWebDataService> autofill_data( | 796 scoped_ptr<AutofillWebDataService> autofill_data( |
| 797 AutofillWebDataService::ForContext(browser_context_)); | 797 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 798 if (!autofill_data.get()) { | 798 if (!autofill_data.get()) { |
| 799 NOTREACHED(); | 799 NOTREACHED(); |
| 800 return; | 800 return; |
| 801 } | 801 } |
| 802 | 802 |
| 803 CancelPendingQuery(&pending_creditcards_query_); | 803 CancelPendingQuery(&pending_creditcards_query_); |
| 804 | 804 |
| 805 pending_creditcards_query_ = autofill_data->GetCreditCards(this); | 805 pending_creditcards_query_ = autofill_data->GetCreditCards(this); |
| 806 } | 806 } |
| 807 | 807 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); | 839 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); |
| 840 iter != credit_cards.end(); ++iter) { | 840 iter != credit_cards.end(); ++iter) { |
| 841 credit_cards_.push_back(*iter); | 841 credit_cards_.push_back(*iter); |
| 842 } | 842 } |
| 843 } | 843 } |
| 844 | 844 |
| 845 void PersonalDataManager::CancelPendingQuery( | 845 void PersonalDataManager::CancelPendingQuery( |
| 846 WebDataServiceBase::Handle* handle) { | 846 WebDataServiceBase::Handle* handle) { |
| 847 if (*handle) { | 847 if (*handle) { |
| 848 scoped_ptr<AutofillWebDataService> autofill_data( | 848 scoped_ptr<AutofillWebDataService> autofill_data( |
| 849 AutofillWebDataService::ForContext(browser_context_)); | 849 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 850 if (!autofill_data.get()) { | 850 if (!autofill_data.get()) { |
| 851 NOTREACHED(); | 851 NOTREACHED(); |
| 852 return; | 852 return; |
| 853 } | 853 } |
| 854 autofill_data->CancelRequest(*handle); | 854 autofill_data->CancelRequest(*handle); |
| 855 } | 855 } |
| 856 *handle = 0; | 856 *handle = 0; |
| 857 } | 857 } |
| 858 | 858 |
| 859 void PersonalDataManager::SaveImportedProfile( | 859 void PersonalDataManager::SaveImportedProfile( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 creditcards.push_back(imported_credit_card); | 909 creditcards.push_back(imported_credit_card); |
| 910 | 910 |
| 911 SetCreditCards(&creditcards); | 911 SetCreditCards(&creditcards); |
| 912 } | 912 } |
| 913 | 913 |
| 914 void PersonalDataManager::EmptyMigrationTrash() { | 914 void PersonalDataManager::EmptyMigrationTrash() { |
| 915 if (!browser_context_ || browser_context_->IsOffTheRecord()) | 915 if (!browser_context_ || browser_context_->IsOffTheRecord()) |
| 916 return; | 916 return; |
| 917 | 917 |
| 918 scoped_ptr<AutofillWebDataService> autofill_data( | 918 scoped_ptr<AutofillWebDataService> autofill_data( |
| 919 AutofillWebDataService::ForContext(browser_context_)); | 919 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 920 if (!autofill_data.get()) { | 920 if (!autofill_data.get()) { |
| 921 NOTREACHED(); | 921 NOTREACHED(); |
| 922 return; | 922 return; |
| 923 } | 923 } |
| 924 | 924 |
| 925 ProfileSyncServiceBase* sync_service = | 925 ProfileSyncServiceBase* sync_service = |
| 926 ProfileSyncServiceBase::ForContext(browser_context_); | 926 ProfileSyncServiceBase::FromBrowserContext(browser_context_); |
| 927 if (!sync_service) | 927 if (!sync_service) |
| 928 return; | 928 return; |
| 929 | 929 |
| 930 if (!sync_service->HasSyncSetupCompleted()) { | 930 if (!sync_service->HasSyncSetupCompleted()) { |
| 931 autofill_data->EmptyMigrationTrash(false); | 931 autofill_data->EmptyMigrationTrash(false); |
| 932 } else if (sync_service->ShouldPushChanges()) { | 932 } else if (sync_service->ShouldPushChanges()) { |
| 933 autofill_data->EmptyMigrationTrash(true); | 933 autofill_data->EmptyMigrationTrash(true); |
| 934 } else { | 934 } else { |
| 935 // Install ourself as a listener so we can empty the trash once the | 935 // Install ourself as a listener so we can empty the trash once the |
| 936 // sync service becomes available. | 936 // sync service becomes available. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 947 } | 947 } |
| 948 | 948 |
| 949 const AutofillMetrics* PersonalDataManager::metric_logger() const { | 949 const AutofillMetrics* PersonalDataManager::metric_logger() const { |
| 950 return metric_logger_.get(); | 950 return metric_logger_.get(); |
| 951 } | 951 } |
| 952 | 952 |
| 953 void PersonalDataManager::set_metric_logger( | 953 void PersonalDataManager::set_metric_logger( |
| 954 const AutofillMetrics* metric_logger) { | 954 const AutofillMetrics* metric_logger) { |
| 955 metric_logger_.reset(metric_logger); | 955 metric_logger_.reset(metric_logger); |
| 956 } | 956 } |
| OLD | NEW |