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

Unified Diff: chrome/browser/webdata/web_data_service.cc

Issue 12987023: Rip autofill code out of webdataservice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change method name in AutofillTable Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/webdata/web_data_service.h ('k') | chrome/browser/webdata/web_data_service_test_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/webdata/web_data_service.cc
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index fa581e171781b27ad25385f8bc29714a1382ed37..0c160e73b2dd1a274871fa5e7a33f00bfd2b68e3 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -6,9 +6,6 @@
#include "base/stl_util.h"
#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/webdata/autofill_change.h"
-#include "chrome/browser/webdata/autofill_entry.h"
-#include "chrome/browser/webdata/autofill_table.h"
#include "chrome/browser/webdata/keyword_table.h"
#include "chrome/browser/webdata/logins_table.h"
#include "chrome/browser/webdata/token_service_table.h"
@@ -16,10 +13,6 @@
#include "chrome/browser/webdata/web_database_service.h"
#include "chrome/browser/webdata/web_intents_table.h"
#include "chrome/common/chrome_notification_types.h"
-#include "components/autofill/browser/autofill_country.h"
-#include "components/autofill/browser/autofill_profile.h"
-#include "components/autofill/browser/credit_card.h"
-#include "components/autofill/common/form_field_data.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
@@ -35,22 +28,6 @@ using base::Bind;
using base::Time;
using content::BrowserThread;
-namespace {
-
-// A task used by WebDataService (for Sync mainly) to inform the
-// PersonalDataManager living on the UI thread that it needs to refresh.
-void NotifyOfMultipleAutofillChangesTask(
- const scoped_refptr<WebDataService>& web_data_service) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED,
- content::Source<WebDataServiceBase>(web_data_service.get()),
- content::NotificationService::NoDetails());
-}
-
-} // namespace
-
WDAppImagesResult::WDAppImagesResult() : has_all_images(false) {}
WDAppImagesResult::~WDAppImagesResult() {}
@@ -67,20 +44,6 @@ WebDataService::WebDataService(scoped_refptr<WebDatabaseService> wdbs,
: WebDataServiceBase(wdbs, callback) {
}
-// static
-void WebDataService::NotifyOfMultipleAutofillChanges(
- WebDataService* web_data_service) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
-
- if (!web_data_service)
- return;
-
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- Bind(&NotifyOfMultipleAutofillChangesTask,
- make_scoped_refptr(web_data_service)));
-}
-
//////////////////////////////////////////////////////////////////////////////
//
// Keywords.
@@ -174,93 +137,6 @@ WebDataServiceBase::Handle WebDataService::GetAllTokens(
}
////////////////////////////////////////////////////////////////////////////////
-//
-// Autofill.
-//
-////////////////////////////////////////////////////////////////////////////////
-
-void WebDataService::AddFormFields(
- const std::vector<FormFieldData>& fields) {
- wdbs_->ScheduleDBTask(FROM_HERE,
- Bind(&WebDataService::AddFormElementsImpl, this, fields));
-}
-
-WebDataServiceBase::Handle WebDataService::GetFormValuesForElementName(
- const string16& name, const string16& prefix, int limit,
- WebDataServiceConsumer* consumer) {
- return wdbs_->ScheduleDBTaskWithResult(FROM_HERE,
- Bind(&WebDataService::GetFormValuesForElementNameImpl,
- this, name, prefix, limit), consumer);
-}
-
-void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin,
- const Time& delete_end) {
- wdbs_->ScheduleDBTask(FROM_HERE,
- Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl,
- this, delete_begin, delete_end));
-}
-
-void WebDataService::RemoveExpiredFormElements() {
- wdbs_->ScheduleDBTask(FROM_HERE,
- Bind(&WebDataService::RemoveExpiredFormElementsImpl, this));
-}
-
-void WebDataService::RemoveFormValueForElementName(
- const string16& name, const string16& value) {
- wdbs_->ScheduleDBTask(FROM_HERE,
- Bind(&WebDataService::RemoveFormValueForElementNameImpl,
- this, name, value));
-}
-
-void WebDataService::AddAutofillProfile(const AutofillProfile& profile) {
- wdbs_->ScheduleDBTask(FROM_HERE,
- Bind(&WebDataService::AddAutofillProfileImpl, this, profile));
-}
-
-void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) {
- wdbs_->ScheduleDBTask(FROM_HERE,
- Bind(&WebDataService::UpdateAutofillProfileImpl, this, profile));
-}
-
-void WebDataService::RemoveAutofillProfile(const std::string& guid) {
- wdbs_->ScheduleDBTask(FROM_HERE,
- Bind(&WebDataService::RemoveAutofillProfileImpl, this, guid));
-}
-
-WebDataServiceBase::Handle WebDataService::GetAutofillProfiles(
- WebDataServiceConsumer* consumer) {
- return wdbs_->ScheduleDBTaskWithResult(FROM_HERE,
- Bind(&WebDataService::GetAutofillProfilesImpl, this), consumer);
-}
-
-void WebDataService::AddCreditCard(const CreditCard& credit_card) {
- wdbs_->ScheduleDBTask(FROM_HERE,
- Bind(&WebDataService::AddCreditCardImpl, this, credit_card));
-}
-
-void WebDataService::UpdateCreditCard(const CreditCard& credit_card) {
- wdbs_->ScheduleDBTask(FROM_HERE,
- Bind(&WebDataService::UpdateCreditCardImpl, this, credit_card));
-}
-
-void WebDataService::RemoveCreditCard(const std::string& guid) {
- wdbs_->ScheduleDBTask(FROM_HERE,
- Bind(&WebDataService::RemoveCreditCardImpl, this, guid));
-}
-
-WebDataServiceBase::Handle WebDataService::GetCreditCards(
- WebDataServiceConsumer* consumer) {
- return wdbs_->ScheduleDBTaskWithResult(FROM_HERE,
- Bind(&WebDataService::GetCreditCardsImpl, this), consumer);
-}
-
-void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween(
- const Time& delete_begin,
- const Time& delete_end) {
- wdbs_->ScheduleDBTask(FROM_HERE, Bind(
- &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl,
- this, delete_begin, delete_end));
-}
WebDataService::WebDataService()
: WebDataServiceBase(NULL, ProfileErrorCallback()) {
@@ -389,274 +265,3 @@ scoped_ptr<WDTypedResult> WebDataService::GetAllTokensImpl(WebDatabase* db) {
return scoped_ptr<WDTypedResult>(
new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map));
}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// Autofill implementation.
-//
-////////////////////////////////////////////////////////////////////////////////
-
-WebDatabase::State WebDataService::AddFormElementsImpl(
- const std::vector<FormFieldData>& fields, WebDatabase* db) {
- AutofillChangeList changes;
- if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues(
- fields, &changes)) {
- NOTREACHED();
- return WebDatabase::COMMIT_NOT_NEEDED;
- }
-
- // Post the notifications including the list of affected keys.
- // This is sent here so that work resulting from this notification will be
- // done on the DB thread, and not the UI thread.
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
- content::Source<WebDataService>(this),
- content::Details<AutofillChangeList>(&changes));
-
- return WebDatabase::COMMIT_NEEDED;
-}
-
-scoped_ptr<WDTypedResult> WebDataService::GetFormValuesForElementNameImpl(
- const string16& name, const string16& prefix, int limit, WebDatabase* db) {
- std::vector<string16> values;
- AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName(
- name, prefix, &values, limit);
- return scoped_ptr<WDTypedResult>(
- new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values));
-}
-
-WebDatabase::State WebDataService::RemoveFormElementsAddedBetweenImpl(
- const base::Time& delete_begin, const base::Time& delete_end,
- WebDatabase* db) {
- AutofillChangeList changes;
-
- if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween(
- delete_begin, delete_end, &changes)) {
- if (!changes.empty()) {
- // Post the notifications including the list of affected keys.
- // This is sent here so that work resulting from this notification
- // will be done on the DB thread, and not the UI thread.
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
- content::Source<WebDataService>(this),
- content::Details<AutofillChangeList>(&changes));
- }
- return WebDatabase::COMMIT_NEEDED;
- }
- return WebDatabase::COMMIT_NOT_NEEDED;
-}
-
-WebDatabase::State WebDataService::RemoveExpiredFormElementsImpl(
- WebDatabase* db) {
- AutofillChangeList changes;
-
- if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) {
- if (!changes.empty()) {
- // Post the notifications including the list of affected keys.
- // This is sent here so that work resulting from this notification
- // will be done on the DB thread, and not the UI thread.
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
- content::Source<WebDataService>(this),
- content::Details<AutofillChangeList>(&changes));
- }
- return WebDatabase::COMMIT_NEEDED;
- }
- return WebDatabase::COMMIT_NOT_NEEDED;
-}
-
-WebDatabase::State WebDataService::RemoveFormValueForElementNameImpl(
- const string16& name, const string16& value, WebDatabase* db) {
-
- if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) {
- AutofillChangeList changes;
- changes.push_back(AutofillChange(AutofillChange::REMOVE,
- AutofillKey(name, value)));
-
- // Post the notifications including the list of affected keys.
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
- content::Source<WebDataService>(this),
- content::Details<AutofillChangeList>(&changes));
-
- return WebDatabase::COMMIT_NEEDED;
- }
- return WebDatabase::COMMIT_NOT_NEEDED;
-}
-
-WebDatabase::State WebDataService::AddAutofillProfileImpl(
- const AutofillProfile& profile, WebDatabase* db) {
- if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) {
- NOTREACHED();
- return WebDatabase::COMMIT_NOT_NEEDED;
- }
-
- // Send GUID-based notification.
- AutofillProfileChange change(AutofillProfileChange::ADD,
- profile.guid(), &profile);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
- content::Source<WebDataService>(this),
- content::Details<AutofillProfileChange>(&change));
-
- return WebDatabase::COMMIT_NEEDED;
-}
-
-WebDatabase::State WebDataService::UpdateAutofillProfileImpl(
- const AutofillProfile& profile, WebDatabase* db) {
- // Only perform the update if the profile exists. It is currently
- // valid to try to update a missing profile. We simply drop the write and
- // the caller will detect this on the next refresh.
- AutofillProfile* original_profile = NULL;
- if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(),
- &original_profile)) {
- return WebDatabase::COMMIT_NOT_NEEDED;
- }
- scoped_ptr<AutofillProfile> scoped_profile(original_profile);
-
- if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti(
- profile)) {
- NOTREACHED();
- return WebDatabase::COMMIT_NEEDED;
- }
-
- // Send GUID-based notification.
- AutofillProfileChange change(AutofillProfileChange::UPDATE,
- profile.guid(), &profile);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
- content::Source<WebDataService>(this),
- content::Details<AutofillProfileChange>(&change));
-
- return WebDatabase::COMMIT_NEEDED;
-}
-
-WebDatabase::State WebDataService::RemoveAutofillProfileImpl(
- const std::string& guid, WebDatabase* db) {
- AutofillProfile* profile = NULL;
- if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) {
- NOTREACHED();
- return WebDatabase::COMMIT_NOT_NEEDED;
- }
- scoped_ptr<AutofillProfile> scoped_profile(profile);
-
- if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) {
- NOTREACHED();
- return WebDatabase::COMMIT_NOT_NEEDED;
- }
-
- // Send GUID-based notification.
- AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
- content::Source<WebDataService>(this),
- content::Details<AutofillProfileChange>(&change));
-
- return WebDatabase::COMMIT_NEEDED;
-}
-
-scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl(
- WebDatabase* db) {
- std::vector<AutofillProfile*> profiles;
- AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles);
- return scoped_ptr<WDTypedResult>(
- new WDDestroyableResult<std::vector<AutofillProfile*> >(
- AUTOFILL_PROFILES_RESULT,
- profiles,
- base::Bind(&WebDataService::DestroyAutofillProfileResult,
- base::Unretained(this))));
-}
-
-WebDatabase::State WebDataService::AddCreditCardImpl(
- const CreditCard& credit_card, WebDatabase* db) {
- if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) {
- NOTREACHED();
- return WebDatabase::COMMIT_NOT_NEEDED;
- }
-
- return WebDatabase::COMMIT_NEEDED;
-}
-
-WebDatabase::State WebDataService::UpdateCreditCardImpl(
- const CreditCard& credit_card, WebDatabase* db) {
- // It is currently valid to try to update a missing profile. We simply drop
- // the write and the caller will detect this on the next refresh.
- CreditCard* original_credit_card = NULL;
- if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(),
- &original_credit_card)) {
- return WebDatabase::COMMIT_NOT_NEEDED;
- }
- scoped_ptr<CreditCard> scoped_credit_card(original_credit_card);
-
- if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) {
- NOTREACHED();
- return WebDatabase::COMMIT_NOT_NEEDED;
- }
- return WebDatabase::COMMIT_NEEDED;
-}
-
-WebDatabase::State WebDataService::RemoveCreditCardImpl(
- const std::string& guid, WebDatabase* db) {
- if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) {
- NOTREACHED();
- return WebDatabase::COMMIT_NOT_NEEDED;
- }
- return WebDatabase::COMMIT_NEEDED;
-}
-
-scoped_ptr<WDTypedResult> WebDataService::GetCreditCardsImpl(WebDatabase* db) {
- std::vector<CreditCard*> credit_cards;
- AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards);
- return scoped_ptr<WDTypedResult>(
- new WDDestroyableResult<std::vector<CreditCard*> >(
- AUTOFILL_CREDITCARDS_RESULT,
- credit_cards,
- base::Bind(&WebDataService::DestroyAutofillCreditCardResult,
- base::Unretained(this))));
-}
-
-WebDatabase::State
-WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl(
- const base::Time& delete_begin, const base::Time& delete_end,
- WebDatabase* db) {
- std::vector<std::string> profile_guids;
- std::vector<std::string> credit_card_guids;
- if (AutofillTable::FromWebDatabase(db)->
- RemoveAutofillProfilesAndCreditCardsModifiedBetween(
- delete_begin,
- delete_end,
- &profile_guids,
- &credit_card_guids)) {
- for (std::vector<std::string>::iterator iter = profile_guids.begin();
- iter != profile_guids.end(); ++iter) {
- AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter,
- NULL);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
- content::Source<WebDataService>(this),
- content::Details<AutofillProfileChange>(&change));
- }
- // Note: It is the caller's responsibility to post notifications for any
- // changes, e.g. by calling the Refresh() method of PersonalDataManager.
- return WebDatabase::COMMIT_NEEDED;
- }
- return WebDatabase::COMMIT_NOT_NEEDED;
-}
-
-void WebDataService::DestroyAutofillProfileResult(const WDTypedResult* result) {
- DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT);
- const WDResult<std::vector<AutofillProfile*> >* r =
- static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result);
- std::vector<AutofillProfile*> profiles = r->GetValue();
- STLDeleteElements(&profiles);
-}
-
-void WebDataService::DestroyAutofillCreditCardResult(
- const WDTypedResult* result) {
- DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
- const WDResult<std::vector<CreditCard*> >* r =
- static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
-
- std::vector<CreditCard*> credit_cards = r->GetValue();
- STLDeleteElements(&credit_cards);
-}
« no previous file with comments | « chrome/browser/webdata/web_data_service.h ('k') | chrome/browser/webdata/web_data_service_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698