Chromium Code Reviews| 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/api/prefs/pref_service_base.h" | 22 #include "chrome/browser/api/prefs/pref_service_base.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" | |
| 27 #include "chrome/browser/webdata/web_data_service.h" | |
| 28 #include "chrome/browser/webdata/web_data_service_factory.h" | |
| 29 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 30 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 31 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
| 33 | 30 |
| 34 namespace { | 31 namespace { |
| 35 | 32 |
| 36 template<typename T> | 33 template<typename T> |
| 37 class FormGroupMatchesByGUIDFunctor { | 34 class FormGroupMatchesByGUIDFunctor { |
| 38 public: | 35 public: |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 } | 117 } |
| 121 | 118 |
| 122 } // namespace | 119 } // namespace |
| 123 | 120 |
| 124 PersonalDataManager::~PersonalDataManager() { | 121 PersonalDataManager::~PersonalDataManager() { |
| 125 CancelPendingQuery(&pending_profiles_query_); | 122 CancelPendingQuery(&pending_profiles_query_); |
| 126 CancelPendingQuery(&pending_creditcards_query_); | 123 CancelPendingQuery(&pending_creditcards_query_); |
| 127 } | 124 } |
| 128 | 125 |
| 129 void PersonalDataManager::OnWebDataServiceRequestDone( | 126 void PersonalDataManager::OnWebDataServiceRequestDone( |
| 130 WebDataService::Handle h, | 127 WebDataServiceBase::Handle h, |
| 131 const WDTypedResult* result) { | 128 const WDTypedResult* result) { |
| 132 DCHECK(pending_profiles_query_ || pending_creditcards_query_); | 129 DCHECK(pending_profiles_query_ || pending_creditcards_query_); |
| 133 | 130 |
| 134 if (!result) { | 131 if (!result) { |
| 135 // Error from the web database. | 132 // Error from the web database. |
| 136 if (h == pending_creditcards_query_) | 133 if (h == pending_creditcards_query_) |
| 137 pending_creditcards_query_ = 0; | 134 pending_creditcards_query_ = 0; |
| 138 else if (h == pending_profiles_query_) | 135 else if (h == pending_profiles_query_) |
| 139 pending_profiles_query_ = 0; | 136 pending_profiles_query_ = 0; |
| 140 return; | 137 return; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 165 OnPersonalDataChanged()); | 162 OnPersonalDataChanged()); |
| 166 | 163 |
| 167 // As all Autofill data is ready, the Autocomplete data is ready as well. | 164 // As all Autofill data is ready, the Autocomplete data is ready as well. |
| 168 // If sync is not set, cull older entries of the autocomplete. Otherwise, | 165 // If sync is not set, cull older entries of the autocomplete. Otherwise, |
| 169 // the entries will be culled when sync is connected. | 166 // the entries will be culled when sync is connected. |
| 170 ProfileSyncService* sync_service = | 167 ProfileSyncService* sync_service = |
| 171 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | 168 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| 172 if (sync_service && (!sync_service->HasSyncSetupCompleted() || | 169 if (sync_service && (!sync_service->HasSyncSetupCompleted() || |
| 173 !PrefServiceBase::ForProfile(profile_)->GetBoolean( | 170 !PrefServiceBase::ForProfile(profile_)->GetBoolean( |
| 174 prefs::kSyncAutofill))) { | 171 prefs::kSyncAutofill))) { |
| 175 scoped_refptr<WebDataService> web_data_service = | 172 scoped_refptr<WebDataServiceBase> service = |
| 176 WebDataServiceFactory::GetForProfile(profile_, | 173 WebDataServiceBase::ForProfile(profile_); |
| 177 Profile::EXPLICIT_ACCESS); | 174 if (service) { |
|
dhollowa
2012/09/04 21:53:52
nit: no need for {} with single-line if-body.
Jói
2012/09/06 01:17:27
Done.
| |
| 178 if (web_data_service) | 175 AutofillWebData::ForService(service)->RemoveExpiredFormElements(); |
| 179 web_data_service->RemoveExpiredFormElements(); | 176 } |
| 180 } | 177 } |
| 181 } | 178 } |
| 182 } | 179 } |
| 183 | 180 |
| 184 void PersonalDataManager::SetObserver(PersonalDataManagerObserver* observer) { | 181 void PersonalDataManager::SetObserver(PersonalDataManagerObserver* observer) { |
| 185 // TODO(dhollowa): RemoveObserver is for compatibility with old code, it | 182 // TODO(dhollowa): RemoveObserver is for compatibility with old code, it |
| 186 // should be nuked. | 183 // should be nuked. |
| 187 observers_.RemoveObserver(observer); | 184 observers_.RemoveObserver(observer); |
| 188 observers_.AddObserver(observer); | 185 observers_.AddObserver(observer); |
| 189 } | 186 } |
| 190 | 187 |
| 191 void PersonalDataManager::RemoveObserver( | 188 void PersonalDataManager::RemoveObserver( |
| 192 PersonalDataManagerObserver* observer) { | 189 PersonalDataManagerObserver* observer) { |
| 193 observers_.RemoveObserver(observer); | 190 observers_.RemoveObserver(observer); |
| 194 } | 191 } |
| 195 | 192 |
| 196 // The |PersonalDataManager| is set up as a listener of the sync service in | 193 // The |PersonalDataManager| is set up as a listener of the sync service in |
| 197 // |EmptyMigrationTrash| in the case where sync is not yet ready to receive | 194 // |EmptyMigrationTrash| in the case where sync is not yet ready to receive |
| 198 // changes. This method, |OnStateChange| acts as a deferred call to | 195 // changes. This method, |OnStateChange| acts as a deferred call to |
| 199 // |EmptyMigrationTrash| once the sync service becomes available. | 196 // |EmptyMigrationTrash| once the sync service becomes available. |
| 200 void PersonalDataManager::OnStateChanged() { | 197 void PersonalDataManager::OnStateChanged() { |
| 201 if (!profile_ || profile_->IsOffTheRecord()) | 198 if (!profile_ || profile_->IsOffTheRecord()) |
| 202 return; | 199 return; |
| 203 | 200 |
| 204 scoped_refptr<WebDataService> web_data_service = | 201 scoped_refptr<WebDataServiceBase> web_data_service = |
| 205 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 202 WebDataServiceBase::ForProfile(profile_); |
| 206 if (!web_data_service.get()) { | 203 if (!web_data_service.get()) { |
| 207 NOTREACHED(); | 204 NOTREACHED(); |
| 208 return; | 205 return; |
| 209 } | 206 } |
| 210 | 207 |
| 211 ProfileSyncService* sync_service = | 208 ProfileSyncService* sync_service = |
| 212 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | 209 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| 213 if (!sync_service) | 210 if (!sync_service) |
| 214 return; | 211 return; |
| 215 | 212 |
| 216 if (sync_service->ShouldPushChanges()) { | 213 if (sync_service->ShouldPushChanges()) { |
| 217 web_data_service->EmptyMigrationTrash(true); | 214 AutofillWebData::ForService(web_data_service)->EmptyMigrationTrash(true); |
| 218 sync_service->RemoveObserver(this); | 215 sync_service->RemoveObserver(this); |
| 219 } | 216 } |
| 220 } | 217 } |
| 221 | 218 |
| 222 void PersonalDataManager::Shutdown() { | 219 void PersonalDataManager::Shutdown() { |
| 223 CancelPendingQuery(&pending_profiles_query_); | 220 CancelPendingQuery(&pending_profiles_query_); |
| 224 CancelPendingQuery(&pending_creditcards_query_); | 221 CancelPendingQuery(&pending_creditcards_query_); |
| 225 notification_registrar_.RemoveAll(); | 222 notification_registrar_.RemoveAll(); |
| 226 } | 223 } |
| 227 | 224 |
| 228 void PersonalDataManager::Observe(int type, | 225 void PersonalDataManager::Observe(int type, |
| 229 const content::NotificationSource& source, | 226 const content::NotificationSource& source, |
| 230 const content::NotificationDetails& details) { | 227 const content::NotificationDetails& details) { |
| 231 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); | 228 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); |
| 232 scoped_refptr<WebDataService> web_data_service = | 229 scoped_refptr<WebDataServiceBase> web_data_service = |
| 233 content::Source<WebDataService>(source).ptr(); | 230 content::Source<WebDataServiceBase>(source).ptr(); |
| 234 | 231 |
| 235 DCHECK(web_data_service.get() && | 232 DCHECK(web_data_service.get() && |
| 236 web_data_service.get() == WebDataServiceFactory::GetForProfile( | 233 web_data_service.get() == WebDataServiceBase::ForProfile( |
| 237 profile_, Profile::EXPLICIT_ACCESS).get()); | 234 profile_).get()); |
| 238 Refresh(); | 235 Refresh(); |
| 239 } | 236 } |
| 240 | 237 |
| 241 bool PersonalDataManager::ImportFormData( | 238 bool PersonalDataManager::ImportFormData( |
| 242 const FormStructure& form, | 239 const FormStructure& form, |
| 243 const CreditCard** imported_credit_card) { | 240 const CreditCard** imported_credit_card) { |
| 244 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); | 241 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); |
| 245 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); | 242 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); |
| 246 | 243 |
| 247 // Parse the form and construct a profile based on the information that is | 244 // 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... | |
| 360 if (profile_->IsOffTheRecord()) | 357 if (profile_->IsOffTheRecord()) |
| 361 return; | 358 return; |
| 362 | 359 |
| 363 if (profile.IsEmpty()) | 360 if (profile.IsEmpty()) |
| 364 return; | 361 return; |
| 365 | 362 |
| 366 // Don't add an existing profile. | 363 // Don't add an existing profile. |
| 367 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) | 364 if (FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
| 368 return; | 365 return; |
| 369 | 366 |
| 370 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( | 367 scoped_refptr<WebDataServiceBase> wds = |
|
dhollowa
2012/09/04 21:53:52
Maybe some helpers like |autofill_data()| and |web
Jói
2012/09/06 01:17:27
Will look at this once we've finished discussing h
| |
| 371 profile_, Profile::EXPLICIT_ACCESS); | 368 WebDataServiceBase::ForProfile(profile_); |
| 372 if (!wds.get()) | 369 if (!wds.get()) |
| 373 return; | 370 return; |
| 374 | 371 |
| 375 // Don't add a duplicate. | 372 // Don't add a duplicate. |
| 376 if (FindByContents(web_profiles_, profile)) | 373 if (FindByContents(web_profiles_, profile)) |
| 377 return; | 374 return; |
| 378 | 375 |
| 379 // Add the new profile to the web database. | 376 // Add the new profile to the web database. |
| 380 wds->AddAutofillProfile(profile); | 377 AutofillWebData::ForService(wds)->AddAutofillProfile(profile); |
| 381 | 378 |
| 382 // Refresh our local cache and send notifications to observers. | 379 // Refresh our local cache and send notifications to observers. |
| 383 Refresh(); | 380 Refresh(); |
| 384 } | 381 } |
| 385 | 382 |
| 386 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { | 383 void PersonalDataManager::UpdateProfile(const AutofillProfile& profile) { |
| 387 if (profile_->IsOffTheRecord()) | 384 if (profile_->IsOffTheRecord()) |
| 388 return; | 385 return; |
| 389 | 386 |
| 390 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) | 387 if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid())) |
| 391 return; | 388 return; |
| 392 | 389 |
| 393 if (profile.IsEmpty()) { | 390 if (profile.IsEmpty()) { |
| 394 RemoveProfile(profile.guid()); | 391 RemoveProfile(profile.guid()); |
| 395 return; | 392 return; |
| 396 } | 393 } |
| 397 | 394 |
| 398 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( | 395 scoped_refptr<WebDataServiceBase> wds = |
| 399 profile_, Profile::EXPLICIT_ACCESS); | 396 WebDataServiceBase::ForProfile(profile_); |
| 400 if (!wds.get()) | 397 if (!wds.get()) |
| 401 return; | 398 return; |
| 402 | 399 |
| 403 // Make the update. | 400 // Make the update. |
| 404 wds->UpdateAutofillProfile(profile); | 401 AutofillWebData::ForService(wds)->UpdateAutofillProfile(profile); |
| 405 | 402 |
| 406 // Refresh our local cache and send notifications to observers. | 403 // Refresh our local cache and send notifications to observers. |
| 407 Refresh(); | 404 Refresh(); |
| 408 } | 405 } |
| 409 | 406 |
| 410 void PersonalDataManager::RemoveProfile(const std::string& guid) { | 407 void PersonalDataManager::RemoveProfile(const std::string& guid) { |
| 411 if (profile_->IsOffTheRecord()) | 408 if (profile_->IsOffTheRecord()) |
| 412 return; | 409 return; |
| 413 | 410 |
| 414 if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) | 411 if (!FindByGUID<AutofillProfile>(web_profiles_, guid)) |
| 415 return; | 412 return; |
| 416 | 413 |
| 417 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( | 414 scoped_refptr<WebDataServiceBase> wds = |
| 418 profile_, Profile::EXPLICIT_ACCESS); | 415 WebDataServiceBase::ForProfile(profile_); |
| 419 if (!wds.get()) | 416 if (!wds.get()) |
| 420 return; | 417 return; |
| 421 | 418 |
| 422 // Remove the profile. | 419 // Remove the profile. |
| 423 wds->RemoveAutofillProfile(guid); | 420 AutofillWebData::ForService(wds)->RemoveAutofillProfile(guid); |
| 424 | 421 |
| 425 // Refresh our local cache and send notifications to observers. | 422 // Refresh our local cache and send notifications to observers. |
| 426 Refresh(); | 423 Refresh(); |
| 427 } | 424 } |
| 428 | 425 |
| 429 AutofillProfile* PersonalDataManager::GetProfileByGUID( | 426 AutofillProfile* PersonalDataManager::GetProfileByGUID( |
| 430 const std::string& guid) { | 427 const std::string& guid) { |
| 431 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_.begin(); | 428 for (std::vector<AutofillProfile*>::iterator iter = web_profiles_.begin(); |
| 432 iter != web_profiles_.end(); ++iter) { | 429 iter != web_profiles_.end(); ++iter) { |
| 433 if ((*iter)->guid() == guid) | 430 if ((*iter)->guid() == guid) |
| 434 return *iter; | 431 return *iter; |
| 435 } | 432 } |
| 436 return NULL; | 433 return NULL; |
| 437 } | 434 } |
| 438 | 435 |
| 439 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { | 436 void PersonalDataManager::AddCreditCard(const CreditCard& credit_card) { |
| 440 if (profile_->IsOffTheRecord()) | 437 if (profile_->IsOffTheRecord()) |
| 441 return; | 438 return; |
| 442 | 439 |
| 443 if (credit_card.IsEmpty()) | 440 if (credit_card.IsEmpty()) |
| 444 return; | 441 return; |
| 445 | 442 |
| 446 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) | 443 if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
| 447 return; | 444 return; |
| 448 | 445 |
| 449 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( | 446 scoped_refptr<WebDataServiceBase> wds = |
| 450 profile_, Profile::EXPLICIT_ACCESS); | 447 WebDataServiceBase::ForProfile(profile_); |
| 451 if (!wds.get()) | 448 if (!wds.get()) |
| 452 return; | 449 return; |
| 453 | 450 |
| 454 // Don't add a duplicate. | 451 // Don't add a duplicate. |
| 455 if (FindByContents(credit_cards_, credit_card)) | 452 if (FindByContents(credit_cards_, credit_card)) |
| 456 return; | 453 return; |
| 457 | 454 |
| 458 // Add the new credit card to the web database. | 455 // Add the new credit card to the web database. |
| 459 wds->AddCreditCard(credit_card); | 456 AutofillWebData::ForService(wds)->AddCreditCard(credit_card); |
| 460 | 457 |
| 461 // Refresh our local cache and send notifications to observers. | 458 // Refresh our local cache and send notifications to observers. |
| 462 Refresh(); | 459 Refresh(); |
| 463 } | 460 } |
| 464 | 461 |
| 465 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { | 462 void PersonalDataManager::UpdateCreditCard(const CreditCard& credit_card) { |
| 466 if (profile_->IsOffTheRecord()) | 463 if (profile_->IsOffTheRecord()) |
| 467 return; | 464 return; |
| 468 | 465 |
| 469 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) | 466 if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid())) |
| 470 return; | 467 return; |
| 471 | 468 |
| 472 if (credit_card.IsEmpty()) { | 469 if (credit_card.IsEmpty()) { |
| 473 RemoveCreditCard(credit_card.guid()); | 470 RemoveCreditCard(credit_card.guid()); |
| 474 return; | 471 return; |
| 475 } | 472 } |
| 476 | 473 |
| 477 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( | 474 scoped_refptr<WebDataServiceBase> wds = |
| 478 profile_, Profile::EXPLICIT_ACCESS); | 475 WebDataServiceBase::ForProfile(profile_); |
| 479 if (!wds.get()) | 476 if (!wds.get()) |
| 480 return; | 477 return; |
| 481 | 478 |
| 482 // Make the update. | 479 // Make the update. |
| 483 wds->UpdateCreditCard(credit_card); | 480 AutofillWebData::ForService(wds)->UpdateCreditCard(credit_card); |
| 484 | 481 |
| 485 // Refresh our local cache and send notifications to observers. | 482 // Refresh our local cache and send notifications to observers. |
| 486 Refresh(); | 483 Refresh(); |
| 487 } | 484 } |
| 488 | 485 |
| 489 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { | 486 void PersonalDataManager::RemoveCreditCard(const std::string& guid) { |
| 490 if (profile_->IsOffTheRecord()) | 487 if (profile_->IsOffTheRecord()) |
| 491 return; | 488 return; |
| 492 | 489 |
| 493 if (!FindByGUID<CreditCard>(credit_cards_, guid)) | 490 if (!FindByGUID<CreditCard>(credit_cards_, guid)) |
| 494 return; | 491 return; |
| 495 | 492 |
| 496 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( | 493 scoped_refptr<WebDataServiceBase> wds = |
| 497 profile_, Profile::EXPLICIT_ACCESS); | 494 WebDataServiceBase::ForProfile(profile_); |
| 498 if (!wds.get()) | 495 if (!wds.get()) |
| 499 return; | 496 return; |
| 500 | 497 |
| 501 // Remove the credit card. | 498 // Remove the credit card. |
| 502 wds->RemoveCreditCard(guid); | 499 AutofillWebData::ForService(wds)->RemoveCreditCard(guid); |
| 503 | 500 |
| 504 // Refresh our local cache and send notifications to observers. | 501 // Refresh our local cache and send notifications to observers. |
| 505 Refresh(); | 502 Refresh(); |
| 506 } | 503 } |
| 507 | 504 |
| 508 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { | 505 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { |
| 509 for (std::vector<CreditCard*>::iterator iter = credit_cards_.begin(); | 506 for (std::vector<CreditCard*>::iterator iter = credit_cards_.begin(); |
| 510 iter != credit_cards_.end(); ++iter) { | 507 iter != credit_cards_.end(); ++iter) { |
| 511 if ((*iter)->guid() == guid) | 508 if ((*iter)->guid() == guid) |
| 512 return *iter; | 509 return *iter; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 pending_creditcards_query_(0), | 573 pending_creditcards_query_(0), |
| 577 metric_logger_(new AutofillMetrics), | 574 metric_logger_(new AutofillMetrics), |
| 578 has_logged_profile_count_(false) { | 575 has_logged_profile_count_(false) { |
| 579 } | 576 } |
| 580 | 577 |
| 581 void PersonalDataManager::Init(Profile* profile) { | 578 void PersonalDataManager::Init(Profile* profile) { |
| 582 profile_ = profile; | 579 profile_ = profile; |
| 583 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); | 580 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); |
| 584 | 581 |
| 585 // WebDataService may not be available in tests. | 582 // WebDataService may not be available in tests. |
| 586 scoped_refptr<WebDataService> web_data_service = | 583 scoped_refptr<WebDataServiceBase> web_data_service = |
| 587 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 584 WebDataServiceBase::ForProfile(profile_); |
| 588 if (!web_data_service.get()) | 585 if (!web_data_service.get()) |
| 589 return; | 586 return; |
| 590 | 587 |
| 591 LoadProfiles(); | 588 LoadProfiles(); |
| 592 LoadCreditCards(); | 589 LoadCreditCards(); |
| 593 | 590 |
| 594 notification_registrar_.Add( | 591 notification_registrar_.Add( |
| 595 this, | 592 this, |
| 596 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, | 593 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, |
| 597 content::Source<WebDataService>(web_data_service)); | 594 content::Source<WebDataServiceBase>(web_data_service)); |
| 598 } | 595 } |
| 599 | 596 |
| 600 bool PersonalDataManager::IsAutofillEnabled() const { | 597 bool PersonalDataManager::IsAutofillEnabled() const { |
| 601 return PrefServiceBase::ForProfile(profile_)->GetBoolean( | 598 return PrefServiceBase::ForProfile(profile_)->GetBoolean( |
| 602 prefs::kAutofillEnabled); | 599 prefs::kAutofillEnabled); |
| 603 } | 600 } |
| 604 | 601 |
| 605 // static | 602 // static |
| 606 bool PersonalDataManager::IsValidLearnableProfile( | 603 bool PersonalDataManager::IsValidLearnableProfile( |
| 607 const AutofillProfile& profile) { | 604 const AutofillProfile& profile) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 | 669 |
| 673 // Ensure that profile labels are up to date. Currently, sync relies on | 670 // Ensure that profile labels are up to date. Currently, sync relies on |
| 674 // labels to identify a profile. | 671 // labels to identify a profile. |
| 675 // TODO(dhollowa): We need to deprecate labels and update the way sync | 672 // TODO(dhollowa): We need to deprecate labels and update the way sync |
| 676 // identifies profiles. | 673 // identifies profiles. |
| 677 std::vector<AutofillProfile*> profile_pointers(profiles->size()); | 674 std::vector<AutofillProfile*> profile_pointers(profiles->size()); |
| 678 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), | 675 std::transform(profiles->begin(), profiles->end(), profile_pointers.begin(), |
| 679 address_of<AutofillProfile>); | 676 address_of<AutofillProfile>); |
| 680 AutofillProfile::AdjustInferredLabels(&profile_pointers); | 677 AutofillProfile::AdjustInferredLabels(&profile_pointers); |
| 681 | 678 |
| 682 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( | 679 scoped_refptr<WebDataServiceBase> wds = |
| 683 profile_, Profile::EXPLICIT_ACCESS); | 680 WebDataServiceBase::ForProfile(profile_); |
| 684 if (!wds.get()) | 681 if (!wds.get()) |
| 685 return; | 682 return; |
| 683 AutofillWebData* autofill_data = AutofillWebData::ForService(wds); | |
| 686 | 684 |
| 687 // Any profiles that are not in the new profile list should be removed from | 685 // Any profiles that are not in the new profile list should be removed from |
| 688 // the web database. | 686 // the web database. |
| 689 for (std::vector<AutofillProfile*>::const_iterator iter = | 687 for (std::vector<AutofillProfile*>::const_iterator iter = |
| 690 web_profiles_.begin(); | 688 web_profiles_.begin(); |
| 691 iter != web_profiles_.end(); ++iter) { | 689 iter != web_profiles_.end(); ++iter) { |
| 692 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) | 690 if (!FindByGUID<AutofillProfile>(*profiles, (*iter)->guid())) |
| 693 wds->RemoveAutofillProfile((*iter)->guid()); | 691 autofill_data->RemoveAutofillProfile((*iter)->guid()); |
| 694 } | 692 } |
| 695 | 693 |
| 696 // Update the web database with the existing profiles. | 694 // Update the web database with the existing profiles. |
| 697 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); | 695 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); |
| 698 iter != profiles->end(); ++iter) { | 696 iter != profiles->end(); ++iter) { |
| 699 if (FindByGUID<AutofillProfile>(web_profiles_, iter->guid())) | 697 if (FindByGUID<AutofillProfile>(web_profiles_, iter->guid())) |
| 700 wds->UpdateAutofillProfile(*iter); | 698 autofill_data->UpdateAutofillProfile(*iter); |
| 701 } | 699 } |
| 702 | 700 |
| 703 // Add the new profiles to the web database. Don't add a duplicate. | 701 // Add the new profiles to the web database. Don't add a duplicate. |
| 704 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); | 702 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); |
| 705 iter != profiles->end(); ++iter) { | 703 iter != profiles->end(); ++iter) { |
| 706 if (!FindByGUID<AutofillProfile>(web_profiles_, iter->guid()) && | 704 if (!FindByGUID<AutofillProfile>(web_profiles_, iter->guid()) && |
| 707 !FindByContents(web_profiles_, *iter)) | 705 !FindByContents(web_profiles_, *iter)) |
| 708 wds->AddAutofillProfile(*iter); | 706 autofill_data->AddAutofillProfile(*iter); |
| 709 } | 707 } |
| 710 | 708 |
| 711 // Copy in the new profiles. | 709 // Copy in the new profiles. |
| 712 web_profiles_.clear(); | 710 web_profiles_.clear(); |
| 713 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); | 711 for (std::vector<AutofillProfile>::iterator iter = profiles->begin(); |
| 714 iter != profiles->end(); ++iter) { | 712 iter != profiles->end(); ++iter) { |
| 715 web_profiles_.push_back(new AutofillProfile(*iter)); | 713 web_profiles_.push_back(new AutofillProfile(*iter)); |
| 716 } | 714 } |
| 717 | 715 |
| 718 // Refresh our local cache and send notifications to observers. | 716 // Refresh our local cache and send notifications to observers. |
| 719 Refresh(); | 717 Refresh(); |
| 720 } | 718 } |
| 721 | 719 |
| 722 void PersonalDataManager::SetCreditCards( | 720 void PersonalDataManager::SetCreditCards( |
| 723 std::vector<CreditCard>* credit_cards) { | 721 std::vector<CreditCard>* credit_cards) { |
| 724 if (profile_->IsOffTheRecord()) | 722 if (profile_->IsOffTheRecord()) |
| 725 return; | 723 return; |
| 726 | 724 |
| 727 // Remove empty credit cards from input. | 725 // Remove empty credit cards from input. |
| 728 credit_cards->erase( | 726 credit_cards->erase( |
| 729 std::remove_if( | 727 std::remove_if( |
| 730 credit_cards->begin(), credit_cards->end(), | 728 credit_cards->begin(), credit_cards->end(), |
| 731 std::mem_fun_ref(&CreditCard::IsEmpty)), | 729 std::mem_fun_ref(&CreditCard::IsEmpty)), |
| 732 credit_cards->end()); | 730 credit_cards->end()); |
| 733 | 731 |
| 734 scoped_refptr<WebDataService> wds = WebDataServiceFactory::GetForProfile( | 732 scoped_refptr<WebDataServiceBase> wds = |
| 735 profile_, Profile::EXPLICIT_ACCESS); | 733 WebDataServiceBase::ForProfile(profile_); |
| 736 if (!wds.get()) | 734 if (!wds.get()) |
| 737 return; | 735 return; |
| 736 AutofillWebData* autofill_data = AutofillWebData::ForService(wds); | |
| 738 | 737 |
| 739 // Any credit cards that are not in the new credit card list should be | 738 // Any credit cards that are not in the new credit card list should be |
| 740 // removed. | 739 // removed. |
| 741 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); | 740 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); |
| 742 iter != credit_cards_.end(); ++iter) { | 741 iter != credit_cards_.end(); ++iter) { |
| 743 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) | 742 if (!FindByGUID<CreditCard>(*credit_cards, (*iter)->guid())) |
| 744 wds->RemoveCreditCard((*iter)->guid()); | 743 autofill_data->RemoveCreditCard((*iter)->guid()); |
| 745 } | 744 } |
| 746 | 745 |
| 747 // Update the web database with the existing credit cards. | 746 // Update the web database with the existing credit cards. |
| 748 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 747 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
| 749 iter != credit_cards->end(); ++iter) { | 748 iter != credit_cards->end(); ++iter) { |
| 750 if (FindByGUID<CreditCard>(credit_cards_, iter->guid())) | 749 if (FindByGUID<CreditCard>(credit_cards_, iter->guid())) |
| 751 wds->UpdateCreditCard(*iter); | 750 autofill_data->UpdateCreditCard(*iter); |
| 752 } | 751 } |
| 753 | 752 |
| 754 // Add the new credit cards to the web database. Don't add a duplicate. | 753 // Add the new credit cards to the web database. Don't add a duplicate. |
| 755 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 754 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
| 756 iter != credit_cards->end(); ++iter) { | 755 iter != credit_cards->end(); ++iter) { |
| 757 if (!FindByGUID<CreditCard>(credit_cards_, iter->guid()) && | 756 if (!FindByGUID<CreditCard>(credit_cards_, iter->guid()) && |
| 758 !FindByContents(credit_cards_, *iter)) | 757 !FindByContents(credit_cards_, *iter)) |
| 759 wds->AddCreditCard(*iter); | 758 autofill_data->AddCreditCard(*iter); |
| 760 } | 759 } |
| 761 | 760 |
| 762 // Copy in the new credit cards. | 761 // Copy in the new credit cards. |
| 763 credit_cards_.clear(); | 762 credit_cards_.clear(); |
| 764 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); | 763 for (std::vector<CreditCard>::iterator iter = credit_cards->begin(); |
| 765 iter != credit_cards->end(); ++iter) { | 764 iter != credit_cards->end(); ++iter) { |
| 766 credit_cards_.push_back(new CreditCard(*iter)); | 765 credit_cards_.push_back(new CreditCard(*iter)); |
| 767 } | 766 } |
| 768 | 767 |
| 769 // Refresh our local cache and send notifications to observers. | 768 // Refresh our local cache and send notifications to observers. |
| 770 Refresh(); | 769 Refresh(); |
| 771 } | 770 } |
| 772 | 771 |
| 773 void PersonalDataManager::LoadProfiles() { | 772 void PersonalDataManager::LoadProfiles() { |
| 774 scoped_refptr<WebDataService> web_data_service = | 773 scoped_refptr<WebDataServiceBase> web_data_service = |
| 775 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 774 WebDataServiceBase::ForProfile(profile_); |
| 776 if (!web_data_service.get()) { | 775 if (!web_data_service.get()) { |
| 777 NOTREACHED(); | 776 NOTREACHED(); |
| 778 return; | 777 return; |
| 779 } | 778 } |
| 780 | 779 |
| 781 CancelPendingQuery(&pending_profiles_query_); | 780 CancelPendingQuery(&pending_profiles_query_); |
| 782 | 781 |
| 783 pending_profiles_query_ = web_data_service->GetAutofillProfiles(this); | 782 pending_profiles_query_ = AutofillWebData::ForService( |
| 783 web_data_service)->GetAutofillProfiles(this); | |
| 784 } | 784 } |
| 785 | 785 |
| 786 // Win and Linux implementations do nothing. Mac implementation fills in the | 786 // Win and Linux implementations do nothing. Mac implementation fills in the |
| 787 // contents of |auxiliary_profiles_|. | 787 // contents of |auxiliary_profiles_|. |
| 788 #if !defined(OS_MACOSX) | 788 #if !defined(OS_MACOSX) |
| 789 void PersonalDataManager::LoadAuxiliaryProfiles() const { | 789 void PersonalDataManager::LoadAuxiliaryProfiles() const { |
| 790 } | 790 } |
| 791 #endif | 791 #endif |
| 792 | 792 |
| 793 void PersonalDataManager::LoadCreditCards() { | 793 void PersonalDataManager::LoadCreditCards() { |
| 794 scoped_refptr<WebDataService> web_data_service = | 794 scoped_refptr<WebDataServiceBase> web_data_service = |
| 795 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 795 WebDataServiceBase::ForProfile(profile_); |
| 796 if (!web_data_service.get()) { | 796 if (!web_data_service.get()) { |
| 797 NOTREACHED(); | 797 NOTREACHED(); |
| 798 return; | 798 return; |
| 799 } | 799 } |
| 800 | 800 |
| 801 CancelPendingQuery(&pending_creditcards_query_); | 801 CancelPendingQuery(&pending_creditcards_query_); |
| 802 | 802 |
| 803 pending_creditcards_query_ = web_data_service->GetCreditCards(this); | 803 pending_creditcards_query_ = AutofillWebData::ForService( |
| 804 web_data_service)->GetCreditCards(this); | |
| 804 } | 805 } |
| 805 | 806 |
| 806 void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, | 807 void PersonalDataManager::ReceiveLoadedProfiles(WebDataServiceBase::Handle h, |
| 807 const WDTypedResult* result) { | 808 const WDTypedResult* result) { |
| 808 DCHECK_EQ(pending_profiles_query_, h); | 809 DCHECK_EQ(pending_profiles_query_, h); |
| 809 | 810 |
| 810 pending_profiles_query_ = 0; | 811 pending_profiles_query_ = 0; |
| 811 web_profiles_.clear(); | 812 web_profiles_.clear(); |
| 812 | 813 |
| 813 const WDResult<std::vector<AutofillProfile*> >* r = | 814 const WDResult<std::vector<AutofillProfile*> >* r = |
| 814 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); | 815 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); |
| 815 | 816 |
| 816 std::vector<AutofillProfile*> profiles = r->GetValue(); | 817 std::vector<AutofillProfile*> profiles = r->GetValue(); |
| 817 for (std::vector<AutofillProfile*>::iterator iter = profiles.begin(); | 818 for (std::vector<AutofillProfile*>::iterator iter = profiles.begin(); |
| 818 iter != profiles.end(); ++iter) { | 819 iter != profiles.end(); ++iter) { |
| 819 web_profiles_.push_back(*iter); | 820 web_profiles_.push_back(*iter); |
| 820 } | 821 } |
| 821 | 822 |
| 822 LogProfileCount(); | 823 LogProfileCount(); |
| 823 EmptyMigrationTrash(); | 824 EmptyMigrationTrash(); |
| 824 } | 825 } |
| 825 | 826 |
| 826 void PersonalDataManager::ReceiveLoadedCreditCards( | 827 void PersonalDataManager::ReceiveLoadedCreditCards( |
| 827 WebDataService::Handle h, const WDTypedResult* result) { | 828 WebDataServiceBase::Handle h, const WDTypedResult* result) { |
| 828 DCHECK_EQ(pending_creditcards_query_, h); | 829 DCHECK_EQ(pending_creditcards_query_, h); |
| 829 | 830 |
| 830 pending_creditcards_query_ = 0; | 831 pending_creditcards_query_ = 0; |
| 831 credit_cards_.clear(); | 832 credit_cards_.clear(); |
| 832 | 833 |
| 833 const WDResult<std::vector<CreditCard*> >* r = | 834 const WDResult<std::vector<CreditCard*> >* r = |
| 834 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 835 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
| 835 | 836 |
| 836 std::vector<CreditCard*> credit_cards = r->GetValue(); | 837 std::vector<CreditCard*> credit_cards = r->GetValue(); |
| 837 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); | 838 for (std::vector<CreditCard*>::iterator iter = credit_cards.begin(); |
| 838 iter != credit_cards.end(); ++iter) { | 839 iter != credit_cards.end(); ++iter) { |
| 839 credit_cards_.push_back(*iter); | 840 credit_cards_.push_back(*iter); |
| 840 } | 841 } |
| 841 } | 842 } |
| 842 | 843 |
| 843 void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) { | 844 void PersonalDataManager::CancelPendingQuery( |
| 845 WebDataServiceBase::Handle* handle) { | |
| 844 if (*handle) { | 846 if (*handle) { |
| 845 scoped_refptr<WebDataService> web_data_service = | 847 scoped_refptr<WebDataServiceBase> web_data_service = |
| 846 WebDataServiceFactory::GetForProfile(profile_, | 848 WebDataServiceBase::ForProfile(profile_); |
| 847 Profile::EXPLICIT_ACCESS); | |
| 848 if (!web_data_service.get()) { | 849 if (!web_data_service.get()) { |
| 849 NOTREACHED(); | 850 NOTREACHED(); |
| 850 return; | 851 return; |
| 851 } | 852 } |
| 852 web_data_service->CancelRequest(*handle); | 853 web_data_service->CancelRequest(*handle); |
| 853 } | 854 } |
| 854 *handle = 0; | 855 *handle = 0; |
| 855 } | 856 } |
| 856 | 857 |
| 857 void PersonalDataManager::SaveImportedProfile( | 858 void PersonalDataManager::SaveImportedProfile( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 if (!merged) | 907 if (!merged) |
| 907 creditcards.push_back(imported_credit_card); | 908 creditcards.push_back(imported_credit_card); |
| 908 | 909 |
| 909 SetCreditCards(&creditcards); | 910 SetCreditCards(&creditcards); |
| 910 } | 911 } |
| 911 | 912 |
| 912 void PersonalDataManager::EmptyMigrationTrash() { | 913 void PersonalDataManager::EmptyMigrationTrash() { |
| 913 if (!profile_ || profile_->IsOffTheRecord()) | 914 if (!profile_ || profile_->IsOffTheRecord()) |
| 914 return; | 915 return; |
| 915 | 916 |
| 916 scoped_refptr<WebDataService> web_data_service = | 917 scoped_refptr<WebDataServiceBase> web_data_service = |
| 917 WebDataServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 918 WebDataServiceBase::ForProfile(profile_); |
| 918 if (!web_data_service.get()) { | 919 if (!web_data_service.get()) { |
| 919 NOTREACHED(); | 920 NOTREACHED(); |
| 920 return; | 921 return; |
| 921 } | 922 } |
| 922 | 923 |
| 923 ProfileSyncService* sync_service = | 924 ProfileSyncService* sync_service = |
| 924 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | 925 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
| 925 if (!sync_service) | 926 if (!sync_service) |
| 926 return; | 927 return; |
| 927 | 928 |
| 929 AutofillWebData* autofill_data = | |
| 930 AutofillWebData::ForService(web_data_service); | |
| 928 if (!sync_service->HasSyncSetupCompleted()) { | 931 if (!sync_service->HasSyncSetupCompleted()) { |
| 929 web_data_service->EmptyMigrationTrash(false); | 932 autofill_data->EmptyMigrationTrash(false); |
| 930 } else if (sync_service->ShouldPushChanges()) { | 933 } else if (sync_service->ShouldPushChanges()) { |
| 931 web_data_service->EmptyMigrationTrash(true); | 934 autofill_data->EmptyMigrationTrash(true); |
| 932 } else { | 935 } else { |
| 933 // Install ourself as a listener so we can empty the trash once the | 936 // Install ourself as a listener so we can empty the trash once the |
| 934 // sync service becomes available. | 937 // sync service becomes available. |
| 935 if (!sync_service->HasObserver(this)) | 938 if (!sync_service->HasObserver(this)) |
| 936 sync_service->AddObserver(this); | 939 sync_service->AddObserver(this); |
| 937 } | 940 } |
| 938 } | 941 } |
| 939 | 942 |
| 940 void PersonalDataManager::LogProfileCount() const { | 943 void PersonalDataManager::LogProfileCount() const { |
| 941 if (!has_logged_profile_count_) { | 944 if (!has_logged_profile_count_) { |
| 942 metric_logger_->LogStoredProfileCount(web_profiles_.size()); | 945 metric_logger_->LogStoredProfileCount(web_profiles_.size()); |
| 943 has_logged_profile_count_ = true; | 946 has_logged_profile_count_ = true; |
| 944 } | 947 } |
| 945 } | 948 } |
| 946 | 949 |
| 947 const AutofillMetrics* PersonalDataManager::metric_logger() const { | 950 const AutofillMetrics* PersonalDataManager::metric_logger() const { |
| 948 return metric_logger_.get(); | 951 return metric_logger_.get(); |
| 949 } | 952 } |
| 950 | 953 |
| 951 void PersonalDataManager::set_metric_logger( | 954 void PersonalDataManager::set_metric_logger( |
| 952 const AutofillMetrics* metric_logger) { | 955 const AutofillMetrics* metric_logger) { |
| 953 metric_logger_.reset(metric_logger); | 956 metric_logger_.reset(metric_logger); |
| 954 } | 957 } |
| OLD | NEW |