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

Unified Diff: components/autofill/browser/webdata/autofill_webdata_backend.h

Issue 14348036: Move AutofillWebData DB methods into separate class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pure merge Created 7 years, 8 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
Index: components/autofill/browser/webdata/autofill_webdata_backend.h
diff --git a/components/autofill/browser/webdata/autofill_webdata_service.h b/components/autofill/browser/webdata/autofill_webdata_backend.h
similarity index 20%
copy from components/autofill/browser/webdata/autofill_webdata_service.h
copy to components/autofill/browser/webdata/autofill_webdata_backend.h
index bfa9d5843abdf22e6f3dc8efc71ce309e5f5003a..b1ab6d63b089552b6c7f2106f0384181589e0374 100644
--- a/components/autofill/browser/webdata/autofill_webdata_service.h
+++ b/components/autofill/browser/webdata/autofill_webdata_backend.h
@@ -1,15 +1,12 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_
-#define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_
-
-#include <vector>
+#ifndef COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_
+#define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_
#include "base/memory/ref_counted.h"
#include "base/observer_list.h"
-#include "base/supports_user_data.h"
#include "components/autofill/browser/webdata/autofill_webdata.h"
#include "components/autofill/common/form_field_data.h"
#include "components/webdata/common/web_data_results.h"
@@ -17,149 +14,115 @@
#include "components/webdata/common/web_data_service_consumer.h"
#include "components/webdata/common/web_database.h"
-class WebDatabaseService;
-
-namespace content {
-class BrowserContext;
-}
-
namespace autofill {
class AutofillChange;
class AutofillProfile;
class AutofillWebDataServiceObserverOnDBThread;
-class AutofillWebDataServiceObserverOnUIThread;
class CreditCard;
-// API for Autofill web data.
-class AutofillWebDataService : public AutofillWebData,
- public WebDataServiceBase {
+// Backend implentation for the AutofillWebDataService. This class runs on the
+// DB thread, as it handles reads and writes to the WebDatabase, and functions
+// in it should only be called from that thread. Most functions here are just
+// the implementations of the corresponding functions in the Autofill
+// WebDataService.
+class AutofillWebDataBackend
+ : public base::RefCountedThreadSafe<AutofillWebDataBackend,
+ content::BrowserThread::DeleteOnDBThread> {
public:
- AutofillWebDataService();
-
- AutofillWebDataService(scoped_refptr<WebDatabaseService> wdbs,
- const ProfileErrorCallback& callback);
-
- // Retrieve an AutofillWebDataService for the given context.
- // Can return NULL in some contexts.
- static scoped_refptr<AutofillWebDataService> FromBrowserContext(
- content::BrowserContext* context);
-
- // Notifies listeners on the UI thread that multiple changes have been made to
- // to Autofill records of the database.
- // NOTE: This method is intended to be called from the DB thread. It
- // it asynchronously notifies listeners on the UI thread.
- // |web_data_service| may be NULL for testing purposes.
- static void NotifyOfMultipleAutofillChanges(
- AutofillWebDataService* web_data_service);
-
- // WebDataServiceBase implementation.
- virtual void ShutdownOnUIThread() OVERRIDE;
-
- // AutofillWebData implementation.
- virtual void AddFormFields(
- const std::vector<FormFieldData>& fields) OVERRIDE;
- virtual WebDataServiceBase::Handle GetFormValuesForElementName(
+ AutofillWebDataBackend();
+
+ // Adds form fields to the web database.
+ WebDatabase::State AddFormElements(const std::vector<FormFieldData>& fields,
+ WebDatabase* db);
+
+ // Returns a vector of values which have been entered in form input fields
+ // named |name|.
+ scoped_ptr<WDTypedResult> GetFormValuesForElementName(
const base::string16& name,
const base::string16& prefix,
int limit,
- WebDataServiceConsumer* consumer) OVERRIDE;
- virtual void RemoveFormElementsAddedBetween(
- const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE;
- virtual void RemoveExpiredFormElements() OVERRIDE;
- virtual void RemoveFormValueForElementName(
- const base::string16& name,
- const base::string16& value) OVERRIDE;
- virtual void AddAutofillProfile(const AutofillProfile& profile) OVERRIDE;
- virtual void UpdateAutofillProfile(const AutofillProfile& profile) OVERRIDE;
- virtual void RemoveAutofillProfile(const std::string& guid) OVERRIDE;
- virtual WebDataServiceBase::Handle GetAutofillProfiles(
- WebDataServiceConsumer* consumer) OVERRIDE;
- virtual void AddCreditCard(const CreditCard& credit_card) OVERRIDE;
- virtual void UpdateCreditCard(const CreditCard& credit_card) OVERRIDE;
- virtual void RemoveCreditCard(const std::string& guid) OVERRIDE;
- virtual WebDataServiceBase::Handle GetCreditCards(
- WebDataServiceConsumer* consumer) OVERRIDE;
- virtual void RemoveAutofillDataModifiedBetween(
- const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE;
+ WebDatabase* db);
- void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer);
- void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer);
+ // Removes form elements recorded for Autocomplete from the database.
+ WebDatabase::State RemoveFormElementsAddedBetween(
+ const base::Time& delete_begin,
+ const base::Time& delete_end,
+ WebDatabase* db);
- void AddObserver(AutofillWebDataServiceObserverOnUIThread* observer);
- void RemoveObserver(AutofillWebDataServiceObserverOnUIThread* observer);
+ // Removes expired form elements recorded for Autocomplete from the database.
+ WebDatabase::State RemoveExpiredFormElements(WebDatabase* db);
- // Returns a SupportsUserData objects that may be used to store data
- // owned by the DB thread on this object. Should be called only from
- // the DB thread, and will be destroyed on the DB thread soon after
- // |ShutdownOnUIThread()| is called.
- base::SupportsUserData* GetDBUserData();
+ // Removes the Form-value |value| which has been entered in form input fields
+ // named |name| from the database.
+ WebDatabase::State RemoveFormValueForElementName(const base::string16& name,
+ const base::string16& value,
+ WebDatabase* db);
- protected:
- virtual ~AutofillWebDataService();
+ // Adds an Autofill profile to the web database.
+ WebDatabase::State AddAutofillProfile(const AutofillProfile& profile,
+ WebDatabase* db);
- virtual void ShutdownOnDBThread();
+ // Updates an Autofill profile in the web database.
+ WebDatabase::State UpdateAutofillProfile(const AutofillProfile& profile,
+ WebDatabase* db);
- private:
- WebDatabase::State AddFormElementsImpl(
- const std::vector<FormFieldData>& fields, WebDatabase* db);
- scoped_ptr<WDTypedResult> GetFormValuesForElementNameImpl(
- const base::string16& name, const base::string16& prefix, int limit,
- WebDatabase* db);
- WebDatabase::State RemoveFormElementsAddedBetweenImpl(
- const base::Time& delete_begin, const base::Time& delete_end,
- WebDatabase* db);
- WebDatabase::State RemoveExpiredFormElementsImpl(WebDatabase* db);
- WebDatabase::State RemoveFormValueForElementNameImpl(
- const base::string16& name, const base::string16& value, WebDatabase* db);
- WebDatabase::State AddAutofillProfileImpl(
- const AutofillProfile& profile, WebDatabase* db);
- WebDatabase::State UpdateAutofillProfileImpl(
- const AutofillProfile& profile, WebDatabase* db);
- WebDatabase::State RemoveAutofillProfileImpl(
- const std::string& guid, WebDatabase* db);
- scoped_ptr<WDTypedResult> GetAutofillProfilesImpl(WebDatabase* db);
- WebDatabase::State AddCreditCardImpl(
- const CreditCard& credit_card, WebDatabase* db);
- WebDatabase::State UpdateCreditCardImpl(
- const CreditCard& credit_card, WebDatabase* db);
- WebDatabase::State RemoveCreditCardImpl(
- const std::string& guid, WebDatabase* db);
- scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db);
- WebDatabase::State RemoveAutofillDataModifiedBetweenImpl(
- const base::Time& delete_begin, const base::Time& delete_end,
+ // Removes an Autofill profile from the web database.
+ WebDatabase::State RemoveAutofillProfile(const std::string& guid,
+ WebDatabase* db);
+
+ // Returns all Autofill profiles from the web database.
+ scoped_ptr<WDTypedResult> GetAutofillProfiles(WebDatabase* db);
+
+ // Adds a credit card to the web database.
+ WebDatabase::State AddCreditCard(const CreditCard& credit_card,
+ WebDatabase* db);
+
+ // Updates a credit card in the web database.
+ WebDatabase::State UpdateCreditCard(const CreditCard& credit_card,
+ WebDatabase* db);
+
+ // Removes a credit card from the web database.
+ WebDatabase::State RemoveCreditCard(const std::string& guid,
+ WebDatabase* db);
+
+ // Returns a vector of all credit cards from the web database.
+ scoped_ptr<WDTypedResult> GetCreditCards(WebDatabase* db);
+
+ // Removes Autofill records from the database.
+ WebDatabase::State RemoveAutofillDataModifiedBetween(
+ const base::Time& delete_begin,
+ const base::Time& delete_end,
WebDatabase* db);
+ // Add an observer to be notified of changes on the DB thread.
+ void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer);
+
+ // Remove an observer.
+ void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer);
+
+ protected:
+ virtual ~AutofillWebDataBackend();
+
+ private:
+ friend struct content::BrowserThread::DeleteOnThread<
+ content::BrowserThread::DB>;
+ friend class base::DeleteHelper<AutofillWebDataBackend>;
+ // We have to friend RCTS<> so WIN shared-lib build is happy
+ // (http://crbug/112250).
+ friend class base::RefCountedThreadSafe<AutofillWebDataBackend,
+ content::BrowserThread::DeleteOnDBThread>;
+
// Callbacks to ensure that sensitive info is destroyed if request is
// cancelled.
void DestroyAutofillProfileResult(const WDTypedResult* result);
void DestroyAutofillCreditCardResult(const WDTypedResult* result);
- void NotifyAutofillMultipleChangedOnUIThread();
-
- // This makes the destructor public, and thus allows us to aggregate
- // SupportsUserData. It is private by default to prevent incorrect
- // usage in class hierarchies where it is inherited by
- // reference-counted objects.
- class SupportsUserDataAggregatable : public base::SupportsUserData {
- public:
- SupportsUserDataAggregatable() {}
- virtual ~SupportsUserDataAggregatable() {}
- private:
- DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable);
- };
-
- // Storage for user data to be accessed only on the DB thread. May
- // be used e.g. for SyncableService subclasses that need to be owned
- // by this object. Is created on first call to |GetDBUserData()|.
- scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_;
-
ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_;
- ObserverList<AutofillWebDataServiceObserverOnUIThread> ui_observer_list_;
- DISALLOW_COPY_AND_ASSIGN(AutofillWebDataService);
+ DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackend);
};
} // namespace autofill
-#endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_
+#endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_

Powered by Google App Engine
This is Rietveld 408576698