| 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/webdata/web_data_service.h" | 5 #include "chrome/browser/webdata/web_data_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/search_engines/template_url.h" | 14 #include "chrome/browser/search_engines/template_url.h" |
| 15 #include "chrome/browser/ui/profile_error_dialog.h" | 15 #include "chrome/browser/ui/profile_error_dialog.h" |
| 16 #include "chrome/browser/webdata/autocomplete_syncable_service.h" | 16 #include "chrome/browser/webdata/autocomplete_syncable_service.h" |
| 17 #include "chrome/browser/webdata/autofill_change.h" | 17 #include "chrome/browser/webdata/autofill_change.h" |
| 18 #include "chrome/browser/webdata/autofill_entry.h" | 18 #include "chrome/browser/webdata/autofill_entry.h" |
| 19 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" | 19 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" |
| 20 #include "chrome/browser/webdata/autofill_table.h" | 20 #include "chrome/browser/webdata/autofill_table.h" |
| 21 #include "chrome/browser/webdata/keyword_table.h" | 21 #include "chrome/browser/webdata/keyword_table.h" |
| 22 #include "chrome/browser/webdata/logins_table.h" | 22 #include "chrome/browser/webdata/logins_table.h" |
| 23 #include "chrome/browser/webdata/token_service_table.h" | 23 #include "chrome/browser/webdata/token_service_table.h" |
| 24 #include "chrome/browser/webdata/web_apps_table.h" | 24 #include "chrome/browser/webdata/web_apps_table.h" |
| 25 #include "chrome/browser/webdata/web_data_service_observer.h" |
| 25 #include "chrome/browser/webdata/web_database_service.h" | 26 #include "chrome/browser/webdata/web_database_service.h" |
| 26 #include "chrome/browser/webdata/web_intents_table.h" | 27 #include "chrome/browser/webdata/web_intents_table.h" |
| 27 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
| 28 #include "chrome/common/chrome_notification_types.h" | |
| 29 #include "components/autofill/browser/autofill_country.h" | 29 #include "components/autofill/browser/autofill_country.h" |
| 30 #include "components/autofill/browser/autofill_profile.h" | 30 #include "components/autofill/browser/autofill_profile.h" |
| 31 #include "components/autofill/browser/credit_card.h" | 31 #include "components/autofill/browser/credit_card.h" |
| 32 #include "components/autofill/common/form_field_data.h" | 32 #include "components/autofill/common/form_field_data.h" |
| 33 #ifdef DEBUG | 33 #ifdef DEBUG |
| 34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 35 #endif | 35 #endif |
| 36 #include "content/public/browser/notification_details.h" | |
| 37 #include "content/public/browser/notification_service.h" | |
| 38 #include "content/public/browser/notification_source.h" | |
| 39 #include "grit/chromium_strings.h" | 36 #include "grit/chromium_strings.h" |
| 40 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
| 41 #include "third_party/skia/include/core/SkBitmap.h" | 38 #include "third_party/skia/include/core/SkBitmap.h" |
| 42 | 39 |
| 43 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
| 44 // | 41 // |
| 45 // WebDataService implementation. | 42 // WebDataService implementation. |
| 46 // | 43 // |
| 47 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
| 48 | 45 |
| 49 using base::Bind; | 46 using base::Bind; |
| 50 using base::Time; | 47 using base::Time; |
| 51 using content::BrowserThread; | 48 using content::BrowserThread; |
| 52 | 49 |
| 53 namespace { | |
| 54 | |
| 55 // A task used by WebDataService (for Sync mainly) to inform the | |
| 56 // PersonalDataManager living on the UI thread that it needs to refresh. | |
| 57 void NotifyOfMultipleAutofillChangesTask( | |
| 58 const scoped_refptr<WebDataService>& web_data_service) { | |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 60 | |
| 61 content::NotificationService::current()->Notify( | |
| 62 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, | |
| 63 content::Source<WebDataServiceBase>(web_data_service.get()), | |
| 64 content::NotificationService::NoDetails()); | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| 68 | |
| 69 WDAppImagesResult::WDAppImagesResult() : has_all_images(false) {} | 50 WDAppImagesResult::WDAppImagesResult() : has_all_images(false) {} |
| 70 | 51 |
| 71 WDAppImagesResult::~WDAppImagesResult() {} | 52 WDAppImagesResult::~WDAppImagesResult() {} |
| 72 | 53 |
| 73 WDKeywordsResult::WDKeywordsResult() | 54 WDKeywordsResult::WDKeywordsResult() |
| 74 : default_search_provider_id(0), | 55 : default_search_provider_id(0), |
| 75 builtin_keyword_version(0) { | 56 builtin_keyword_version(0) { |
| 76 } | 57 } |
| 77 | 58 |
| 78 WDKeywordsResult::~WDKeywordsResult() {} | 59 WDKeywordsResult::~WDKeywordsResult() {} |
| (...skipping 12 matching lines...) Expand all Loading... |
| 91 // static | 72 // static |
| 92 void WebDataService::NotifyOfMultipleAutofillChanges( | 73 void WebDataService::NotifyOfMultipleAutofillChanges( |
| 93 WebDataService* web_data_service) { | 74 WebDataService* web_data_service) { |
| 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 95 | 76 |
| 96 if (!web_data_service) | 77 if (!web_data_service) |
| 97 return; | 78 return; |
| 98 | 79 |
| 99 BrowserThread::PostTask( | 80 BrowserThread::PostTask( |
| 100 BrowserThread::UI, FROM_HERE, | 81 BrowserThread::UI, FROM_HERE, |
| 101 Bind(&NotifyOfMultipleAutofillChangesTask, | 82 Bind(&WebDataService::NotifyAutofillMultipleChangedOnUIThread, |
| 102 make_scoped_refptr(web_data_service))); | 83 make_scoped_refptr(web_data_service))); |
| 103 } | 84 } |
| 104 | 85 |
| 105 void WebDataService::ShutdownOnUIThread() { | 86 void WebDataService::ShutdownOnUIThread() { |
| 106 db_loaded_ = false; | 87 db_loaded_ = false; |
| 107 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 88 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 108 Bind(&WebDataService::ShutdownSyncableServices, this)); | 89 Bind(&WebDataService::ShutdownSyncableServices, this)); |
| 109 } | 90 } |
| 110 | 91 |
| 111 void WebDataService::Init() { | 92 void WebDataService::Init() { |
| 112 wdbs_->LoadDatabase( | 93 wdbs_->LoadDatabase( |
| 113 Bind(&WebDataService::OnDatabaseInit, base::Unretained(this))); | 94 Bind(&WebDataService::OnDatabaseInit, base::Unretained(this))); |
| 114 | 95 |
| 115 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 96 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 116 Bind(&WebDataService::InitializeSyncableServices, this)); | 97 Bind(&WebDataService::InitializeSyncableServices, this)); |
| 117 } | 98 } |
| 118 | 99 |
| 119 void WebDataService::CancelRequest(Handle h) { | 100 void WebDataService::CancelRequest(Handle h) { |
| 120 wdbs_->CancelRequest(h); | 101 wdbs_->CancelRequest(h); |
| 121 } | 102 } |
| 122 | 103 |
| 123 content::NotificationSource WebDataService::GetNotificationSource() { | |
| 124 return content::Source<WebDataService>(this); | |
| 125 } | |
| 126 | |
| 127 bool WebDataService::IsDatabaseLoaded() { | 104 bool WebDataService::IsDatabaseLoaded() { |
| 128 return db_loaded_; | 105 return db_loaded_; |
| 129 } | 106 } |
| 130 | 107 |
| 131 WebDatabase* WebDataService::GetDatabase() { | 108 WebDatabase* WebDataService::GetDatabase() { |
| 132 return wdbs_->GetDatabase(); | 109 return wdbs_->GetDatabase(); |
| 133 } | 110 } |
| 134 | 111 |
| 135 ////////////////////////////////////////////////////////////////////////////// | 112 ////////////////////////////////////////////////////////////////////////////// |
| 136 // | 113 // |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 DCHECK(autocomplete_syncable_service_ == NULL); | 294 DCHECK(autocomplete_syncable_service_ == NULL); |
| 318 DCHECK(autofill_profile_syncable_service_ == NULL); | 295 DCHECK(autofill_profile_syncable_service_ == NULL); |
| 319 } | 296 } |
| 320 | 297 |
| 321 //////////////////////////////////////////////////////////////////////////////// | 298 //////////////////////////////////////////////////////////////////////////////// |
| 322 // | 299 // |
| 323 // The following methods are executed on the DB thread. | 300 // The following methods are executed on the DB thread. |
| 324 // | 301 // |
| 325 //////////////////////////////////////////////////////////////////////////////// | 302 //////////////////////////////////////////////////////////////////////////////// |
| 326 | 303 |
| 304 void WebDataService::NotifyDatabaseLoadedOnUIThread() { |
| 305 db_loaded_ = true; |
| 306 // Notify that the database has been initialized. |
| 307 FOR_EACH_OBSERVER(WebDataServiceObserver, |
| 308 observer_list_, |
| 309 WebDatabaseLoaded()); |
| 310 } |
| 311 |
| 327 void WebDataService::DBInitFailed(sql::InitStatus sql_status) { | 312 void WebDataService::DBInitFailed(sql::InitStatus sql_status) { |
| 328 ShowProfileErrorDialog( | 313 ShowProfileErrorDialog( |
| 329 (sql_status == sql::INIT_FAILURE) ? | 314 (sql_status == sql::INIT_FAILURE) ? |
| 330 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); | 315 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); |
| 331 } | 316 } |
| 332 | 317 |
| 333 void WebDataService::NotifyDatabaseLoadedOnUIThread() { | |
| 334 db_loaded_ = true; | |
| 335 // Notify that the database has been initialized. | |
| 336 content::NotificationService::current()->Notify( | |
| 337 chrome::NOTIFICATION_WEB_DATABASE_LOADED, | |
| 338 content::Source<WebDataService>(this), | |
| 339 content::NotificationService::NoDetails()); | |
| 340 } | |
| 341 | |
| 342 void WebDataService::OnDatabaseInit(sql::InitStatus status) { | 318 void WebDataService::OnDatabaseInit(sql::InitStatus status) { |
| 343 if (status == sql::INIT_OK) { | 319 if (status == sql::INIT_OK) { |
| 344 BrowserThread::PostTask( | 320 BrowserThread::PostTask( |
| 345 BrowserThread::UI, FROM_HERE, | 321 BrowserThread::UI, FROM_HERE, |
| 346 base::Bind(&WebDataService::NotifyDatabaseLoadedOnUIThread, this)); | 322 base::Bind(&WebDataService::NotifyDatabaseLoadedOnUIThread, this)); |
| 347 } else { | 323 } else { |
| 348 BrowserThread::PostTask( | 324 BrowserThread::PostTask( |
| 349 BrowserThread::UI, FROM_HERE, | 325 BrowserThread::UI, FROM_HERE, |
| 350 base::Bind(&WebDataService::DBInitFailed, this, status)); | 326 base::Bind(&WebDataService::DBInitFailed, this, status)); |
| 351 } | 327 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 const std::vector<FormFieldData>& fields, WebDatabase* db) { | 475 const std::vector<FormFieldData>& fields, WebDatabase* db) { |
| 500 AutofillChangeList changes; | 476 AutofillChangeList changes; |
| 501 if (!db->GetAutofillTable()->AddFormFieldValues(fields, &changes)) { | 477 if (!db->GetAutofillTable()->AddFormFieldValues(fields, &changes)) { |
| 502 NOTREACHED(); | 478 NOTREACHED(); |
| 503 return WebDatabase::COMMIT_NOT_NEEDED; | 479 return WebDatabase::COMMIT_NOT_NEEDED; |
| 504 } | 480 } |
| 505 | 481 |
| 506 // Post the notifications including the list of affected keys. | 482 // Post the notifications including the list of affected keys. |
| 507 // This is sent here so that work resulting from this notification will be | 483 // This is sent here so that work resulting from this notification will be |
| 508 // done on the DB thread, and not the UI thread. | 484 // done on the DB thread, and not the UI thread. |
| 509 content::NotificationService::current()->Notify( | 485 FOR_EACH_OBSERVER(WebDataServiceObserver, |
| 510 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 486 observer_list_, |
| 511 content::Source<WebDataService>(this), | 487 AutofillEntriesChanged(changes)); |
| 512 content::Details<AutofillChangeList>(&changes)); | |
| 513 | 488 |
| 514 return WebDatabase::COMMIT_NEEDED; | 489 return WebDatabase::COMMIT_NEEDED; |
| 515 } | 490 } |
| 516 | 491 |
| 517 scoped_ptr<WDTypedResult> WebDataService::GetFormValuesForElementNameImpl( | 492 scoped_ptr<WDTypedResult> WebDataService::GetFormValuesForElementNameImpl( |
| 518 const string16& name, const string16& prefix, int limit, WebDatabase* db) { | 493 const string16& name, const string16& prefix, int limit, WebDatabase* db) { |
| 519 std::vector<string16> values; | 494 std::vector<string16> values; |
| 520 db->GetAutofillTable()->GetFormValuesForElementName( | 495 db->GetAutofillTable()->GetFormValuesForElementName( |
| 521 name, prefix, &values, limit); | 496 name, prefix, &values, limit); |
| 522 return scoped_ptr<WDTypedResult>( | 497 return scoped_ptr<WDTypedResult>( |
| 523 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); | 498 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); |
| 524 } | 499 } |
| 525 | 500 |
| 526 WebDatabase::State WebDataService::RemoveFormElementsAddedBetweenImpl( | 501 WebDatabase::State WebDataService::RemoveFormElementsAddedBetweenImpl( |
| 527 const base::Time& delete_begin, const base::Time& delete_end, | 502 const base::Time& delete_begin, const base::Time& delete_end, |
| 528 WebDatabase* db) { | 503 WebDatabase* db) { |
| 529 AutofillChangeList changes; | 504 AutofillChangeList changes; |
| 530 | 505 |
| 531 if (db->GetAutofillTable()->RemoveFormElementsAddedBetween( | 506 if (db->GetAutofillTable()->RemoveFormElementsAddedBetween( |
| 532 delete_begin, delete_end, &changes)) { | 507 delete_begin, delete_end, &changes)) { |
| 533 if (!changes.empty()) { | 508 if (!changes.empty()) { |
| 534 // Post the notifications including the list of affected keys. | 509 // Post the notifications including the list of affected keys. |
| 535 // This is sent here so that work resulting from this notification | 510 // This is sent here so that work resulting from this notification |
| 536 // will be done on the DB thread, and not the UI thread. | 511 // will be done on the DB thread, and not the UI thread. |
| 537 content::NotificationService::current()->Notify( | 512 FOR_EACH_OBSERVER(WebDataServiceObserver, |
| 538 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 513 observer_list_, |
| 539 content::Source<WebDataService>(this), | 514 AutofillEntriesChanged(changes)); |
| 540 content::Details<AutofillChangeList>(&changes)); | |
| 541 } | 515 } |
| 542 return WebDatabase::COMMIT_NEEDED; | 516 return WebDatabase::COMMIT_NEEDED; |
| 543 } | 517 } |
| 544 return WebDatabase::COMMIT_NOT_NEEDED; | 518 return WebDatabase::COMMIT_NOT_NEEDED; |
| 545 } | 519 } |
| 546 | 520 |
| 547 WebDatabase::State WebDataService::RemoveExpiredFormElementsImpl( | 521 WebDatabase::State WebDataService::RemoveExpiredFormElementsImpl( |
| 548 WebDatabase* db) { | 522 WebDatabase* db) { |
| 549 AutofillChangeList changes; | 523 AutofillChangeList changes; |
| 550 | 524 |
| 551 if (db->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { | 525 if (db->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { |
| 552 if (!changes.empty()) { | 526 if (!changes.empty()) { |
| 553 // Post the notifications including the list of affected keys. | 527 // Post the notifications including the list of affected keys. |
| 554 // This is sent here so that work resulting from this notification | 528 // This is sent here so that work resulting from this notification |
| 555 // will be done on the DB thread, and not the UI thread. | 529 // will be done on the DB thread, and not the UI thread. |
| 556 content::NotificationService::current()->Notify( | 530 FOR_EACH_OBSERVER(WebDataServiceObserver, |
| 557 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 531 observer_list_, |
| 558 content::Source<WebDataService>(this), | 532 AutofillEntriesChanged(changes)); |
| 559 content::Details<AutofillChangeList>(&changes)); | |
| 560 } | 533 } |
| 561 return WebDatabase::COMMIT_NEEDED; | 534 return WebDatabase::COMMIT_NEEDED; |
| 562 } | 535 } |
| 563 return WebDatabase::COMMIT_NOT_NEEDED; | 536 return WebDatabase::COMMIT_NOT_NEEDED; |
| 564 } | 537 } |
| 565 | 538 |
| 566 WebDatabase::State WebDataService::RemoveFormValueForElementNameImpl( | 539 WebDatabase::State WebDataService::RemoveFormValueForElementNameImpl( |
| 567 const string16& name, const string16& value, WebDatabase* db) { | 540 const string16& name, const string16& value, WebDatabase* db) { |
| 568 | 541 |
| 569 if (db->GetAutofillTable()->RemoveFormElement(name, value)) { | 542 if (db->GetAutofillTable()->RemoveFormElement(name, value)) { |
| 570 AutofillChangeList changes; | 543 AutofillChangeList changes; |
| 571 changes.push_back(AutofillChange(AutofillChange::REMOVE, | 544 changes.push_back(AutofillChange(AutofillChange::REMOVE, |
| 572 AutofillKey(name, value))); | 545 AutofillKey(name, value))); |
| 573 | 546 |
| 574 // Post the notifications including the list of affected keys. | 547 // Post the notifications including the list of affected keys. |
| 575 content::NotificationService::current()->Notify( | 548 FOR_EACH_OBSERVER(WebDataServiceObserver, |
| 576 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 549 observer_list_, |
| 577 content::Source<WebDataService>(this), | 550 AutofillEntriesChanged(changes)); |
| 578 content::Details<AutofillChangeList>(&changes)); | |
| 579 | 551 |
| 580 return WebDatabase::COMMIT_NEEDED; | 552 return WebDatabase::COMMIT_NEEDED; |
| 581 } | 553 } |
| 582 return WebDatabase::COMMIT_NOT_NEEDED; | 554 return WebDatabase::COMMIT_NOT_NEEDED; |
| 583 } | 555 } |
| 584 | 556 |
| 585 WebDatabase::State WebDataService::AddAutofillProfileImpl( | 557 WebDatabase::State WebDataService::AddAutofillProfileImpl( |
| 586 const AutofillProfile& profile, WebDatabase* db) { | 558 const AutofillProfile& profile, WebDatabase* db) { |
| 587 if (!db->GetAutofillTable()->AddAutofillProfile(profile)) { | 559 if (!db->GetAutofillTable()->AddAutofillProfile(profile)) { |
| 588 NOTREACHED(); | 560 NOTREACHED(); |
| 589 return WebDatabase::COMMIT_NOT_NEEDED; | 561 return WebDatabase::COMMIT_NOT_NEEDED; |
| 590 } | 562 } |
| 591 | 563 |
| 592 // Send GUID-based notification. | 564 // Send GUID-based notification. |
| 593 AutofillProfileChange change(AutofillProfileChange::ADD, | 565 AutofillProfileChange change( |
| 594 profile.guid(), &profile); | 566 AutofillProfileChange::ADD, profile.guid(), &profile); |
| 595 content::NotificationService::current()->Notify( | 567 FOR_EACH_OBSERVER(WebDataServiceObserver, |
| 596 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 568 observer_list_, |
| 597 content::Source<WebDataService>(this), | 569 AutofillProfileChanged(change)); |
| 598 content::Details<AutofillProfileChange>(&change)); | |
| 599 | 570 |
| 600 return WebDatabase::COMMIT_NEEDED; | 571 return WebDatabase::COMMIT_NEEDED; |
| 601 } | 572 } |
| 602 | 573 |
| 603 WebDatabase::State WebDataService::UpdateAutofillProfileImpl( | 574 WebDatabase::State WebDataService::UpdateAutofillProfileImpl( |
| 604 const AutofillProfile& profile, WebDatabase* db) { | 575 const AutofillProfile& profile, WebDatabase* db) { |
| 605 // Only perform the update if the profile exists. It is currently | 576 // Only perform the update if the profile exists. It is currently |
| 606 // valid to try to update a missing profile. We simply drop the write and | 577 // valid to try to update a missing profile. We simply drop the write and |
| 607 // the caller will detect this on the next refresh. | 578 // the caller will detect this on the next refresh. |
| 608 AutofillProfile* original_profile = NULL; | 579 AutofillProfile* original_profile = NULL; |
| 609 if (!db->GetAutofillTable()->GetAutofillProfile(profile.guid(), | 580 if (!db->GetAutofillTable()->GetAutofillProfile(profile.guid(), |
| 610 &original_profile)) { | 581 &original_profile)) { |
| 611 return WebDatabase::COMMIT_NOT_NEEDED; | 582 return WebDatabase::COMMIT_NOT_NEEDED; |
| 612 } | 583 } |
| 613 scoped_ptr<AutofillProfile> scoped_profile(original_profile); | 584 scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
| 614 | 585 |
| 615 if (!db->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) { | 586 if (!db->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) { |
| 616 NOTREACHED(); | 587 NOTREACHED(); |
| 617 return WebDatabase::COMMIT_NEEDED; | 588 return WebDatabase::COMMIT_NEEDED; |
| 618 } | 589 } |
| 619 | 590 |
| 620 // Send GUID-based notification. | 591 // Send GUID-based notification. |
| 621 AutofillProfileChange change(AutofillProfileChange::UPDATE, | 592 AutofillProfileChange change(AutofillProfileChange::UPDATE, |
| 622 profile.guid(), &profile); | 593 profile.guid(), &profile); |
| 623 content::NotificationService::current()->Notify( | 594 FOR_EACH_OBSERVER(WebDataServiceObserver, |
| 624 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 595 observer_list_, |
| 625 content::Source<WebDataService>(this), | 596 AutofillProfileChanged(change)); |
| 626 content::Details<AutofillProfileChange>(&change)); | |
| 627 | 597 |
| 628 return WebDatabase::COMMIT_NEEDED; | 598 return WebDatabase::COMMIT_NEEDED; |
| 629 } | 599 } |
| 630 | 600 |
| 631 WebDatabase::State WebDataService::RemoveAutofillProfileImpl( | 601 WebDatabase::State WebDataService::RemoveAutofillProfileImpl( |
| 632 const std::string& guid, WebDatabase* db) { | 602 const std::string& guid, WebDatabase* db) { |
| 633 AutofillProfile* profile = NULL; | 603 AutofillProfile* profile = NULL; |
| 634 if (!db->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { | 604 if (!db->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { |
| 635 NOTREACHED(); | 605 NOTREACHED(); |
| 636 return WebDatabase::COMMIT_NOT_NEEDED; | 606 return WebDatabase::COMMIT_NOT_NEEDED; |
| 637 } | 607 } |
| 638 scoped_ptr<AutofillProfile> scoped_profile(profile); | 608 scoped_ptr<AutofillProfile> scoped_profile(profile); |
| 639 | 609 |
| 640 if (!db->GetAutofillTable()->RemoveAutofillProfile(guid)) { | 610 if (!db->GetAutofillTable()->RemoveAutofillProfile(guid)) { |
| 641 NOTREACHED(); | 611 NOTREACHED(); |
| 642 return WebDatabase::COMMIT_NOT_NEEDED; | 612 return WebDatabase::COMMIT_NOT_NEEDED; |
| 643 } | 613 } |
| 644 | 614 |
| 645 // Send GUID-based notification. | 615 // Send GUID-based notification. |
| 646 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); | 616 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
| 647 content::NotificationService::current()->Notify( | 617 FOR_EACH_OBSERVER(WebDataServiceObserver, |
| 648 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 618 observer_list_, |
| 649 content::Source<WebDataService>(this), | 619 AutofillProfileChanged(change)); |
| 650 content::Details<AutofillProfileChange>(&change)); | |
| 651 | 620 |
| 652 return WebDatabase::COMMIT_NEEDED; | 621 return WebDatabase::COMMIT_NEEDED; |
| 653 } | 622 } |
| 654 | 623 |
| 655 scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl( | 624 scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl( |
| 656 WebDatabase* db) { | 625 WebDatabase* db) { |
| 657 std::vector<AutofillProfile*> profiles; | 626 std::vector<AutofillProfile*> profiles; |
| 658 db->GetAutofillTable()->GetAutofillProfiles(&profiles); | 627 db->GetAutofillTable()->GetAutofillProfiles(&profiles); |
| 659 return scoped_ptr<WDTypedResult>( | 628 return scoped_ptr<WDTypedResult>( |
| 660 new WDDestroyableResult<std::vector<AutofillProfile*> >( | 629 new WDDestroyableResult<std::vector<AutofillProfile*> >( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 if (db->GetAutofillTable()-> | 690 if (db->GetAutofillTable()-> |
| 722 RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 691 RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
| 723 delete_begin, | 692 delete_begin, |
| 724 delete_end, | 693 delete_end, |
| 725 &profile_guids, | 694 &profile_guids, |
| 726 &credit_card_guids)) { | 695 &credit_card_guids)) { |
| 727 for (std::vector<std::string>::iterator iter = profile_guids.begin(); | 696 for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
| 728 iter != profile_guids.end(); ++iter) { | 697 iter != profile_guids.end(); ++iter) { |
| 729 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, | 698 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, |
| 730 NULL); | 699 NULL); |
| 731 content::NotificationService::current()->Notify( | 700 FOR_EACH_OBSERVER(WebDataServiceObserver, |
| 732 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 701 observer_list_, |
| 733 content::Source<WebDataService>(this), | 702 AutofillProfileChanged(change)); |
| 734 content::Details<AutofillProfileChange>(&change)); | |
| 735 } | 703 } |
| 736 // Note: It is the caller's responsibility to post notifications for any | 704 // Note: It is the caller's responsibility to post notifications for any |
| 737 // changes, e.g. by calling the Refresh() method of PersonalDataManager. | 705 // changes, e.g. by calling the Refresh() method of PersonalDataManager. |
| 738 return WebDatabase::COMMIT_NEEDED; | 706 return WebDatabase::COMMIT_NEEDED; |
| 739 } | 707 } |
| 740 return WebDatabase::COMMIT_NOT_NEEDED; | 708 return WebDatabase::COMMIT_NOT_NEEDED; |
| 741 } | 709 } |
| 742 | 710 |
| 711 void WebDataService::NotifyAutofillMultipleChangedOnUIThread() { |
| 712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 713 FOR_EACH_OBSERVER(WebDataServiceObserver, |
| 714 observer_list_, |
| 715 AutofillMultipleChanged()); |
| 716 } |
| 717 |
| 743 AutofillProfileSyncableService* | 718 AutofillProfileSyncableService* |
| 744 WebDataService::GetAutofillProfileSyncableService() const { | 719 WebDataService::GetAutofillProfileSyncableService() const { |
| 745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 746 DCHECK(autofill_profile_syncable_service_); // Make sure we're initialized. | 721 DCHECK(autofill_profile_syncable_service_); // Make sure we're initialized. |
| 747 | 722 |
| 748 return autofill_profile_syncable_service_; | 723 return autofill_profile_syncable_service_; |
| 749 } | 724 } |
| 750 | 725 |
| 751 AutocompleteSyncableService* WebDataService::GetAutocompleteSyncableService() | 726 AutocompleteSyncableService* WebDataService::GetAutocompleteSyncableService() |
| 752 const { | 727 const { |
| 753 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 754 DCHECK(autocomplete_syncable_service_); // Make sure we're initialized. | 729 DCHECK(autocomplete_syncable_service_); // Make sure we're initialized. |
| 755 | 730 |
| 756 return autocomplete_syncable_service_; | 731 return autocomplete_syncable_service_; |
| 757 } | 732 } |
| 758 | 733 |
| 734 void WebDataService::AddObserver(WebDataServiceObserver* observer) { |
| 735 observer_list_.AddObserver(observer); |
| 736 } |
| 737 |
| 738 void WebDataService::RemoveObserver(WebDataServiceObserver* observer) { |
| 739 observer_list_.RemoveObserver(observer); |
| 740 } |
| 741 |
| 759 void WebDataService::DestroyAutofillProfileResult(const WDTypedResult* result) { | 742 void WebDataService::DestroyAutofillProfileResult(const WDTypedResult* result) { |
| 760 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); | 743 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); |
| 761 const WDResult<std::vector<AutofillProfile*> >* r = | 744 const WDResult<std::vector<AutofillProfile*> >* r = |
| 762 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); | 745 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); |
| 763 std::vector<AutofillProfile*> profiles = r->GetValue(); | 746 std::vector<AutofillProfile*> profiles = r->GetValue(); |
| 764 STLDeleteElements(&profiles); | 747 STLDeleteElements(&profiles); |
| 765 } | 748 } |
| 766 | 749 |
| 767 void WebDataService::DestroyAutofillCreditCardResult( | 750 void WebDataService::DestroyAutofillCreditCardResult( |
| 768 const WDTypedResult* result) { | 751 const WDTypedResult* result) { |
| 769 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 752 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
| 770 const WDResult<std::vector<CreditCard*> >* r = | 753 const WDResult<std::vector<CreditCard*> >* r = |
| 771 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 754 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
| 772 | 755 |
| 773 std::vector<CreditCard*> credit_cards = r->GetValue(); | 756 std::vector<CreditCard*> credit_cards = r->GetValue(); |
| 774 STLDeleteElements(&credit_cards); | 757 STLDeleteElements(&credit_cards); |
| 775 } | 758 } |
| 776 | |
| OLD | NEW |