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

Side by Side 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, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_
6 #define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ 6 #define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_
7
8 #include <vector>
9 7
10 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
11 #include "base/observer_list.h" 9 #include "base/observer_list.h"
12 #include "base/supports_user_data.h"
13 #include "components/autofill/browser/webdata/autofill_webdata.h" 10 #include "components/autofill/browser/webdata/autofill_webdata.h"
14 #include "components/autofill/common/form_field_data.h" 11 #include "components/autofill/common/form_field_data.h"
15 #include "components/webdata/common/web_data_results.h" 12 #include "components/webdata/common/web_data_results.h"
16 #include "components/webdata/common/web_data_service_base.h" 13 #include "components/webdata/common/web_data_service_base.h"
17 #include "components/webdata/common/web_data_service_consumer.h" 14 #include "components/webdata/common/web_data_service_consumer.h"
18 #include "components/webdata/common/web_database.h" 15 #include "components/webdata/common/web_database.h"
19 16
20 class WebDatabaseService;
21
22 namespace content {
23 class BrowserContext;
24 }
25
26 namespace autofill { 17 namespace autofill {
27 18
28 class AutofillChange; 19 class AutofillChange;
29 class AutofillProfile; 20 class AutofillProfile;
30 class AutofillWebDataServiceObserverOnDBThread; 21 class AutofillWebDataServiceObserverOnDBThread;
31 class AutofillWebDataServiceObserverOnUIThread;
32 class CreditCard; 22 class CreditCard;
33 23
34 // API for Autofill web data. 24 // Backend implentation for the AutofillWebDataService. This class runs on the
35 class AutofillWebDataService : public AutofillWebData, 25 // DB thread, as it handles reads and writes to the WebDatabase, and functions
36 public WebDataServiceBase { 26 // in it should only be called from that thread. Most functions here are just
27 // the implementations of the corresponding functions in the Autofill
28 // WebDataService.
29 class AutofillWebDataBackend
30 : public base::RefCountedThreadSafe<AutofillWebDataBackend,
31 content::BrowserThread::DeleteOnDBThread> {
37 public: 32 public:
38 AutofillWebDataService(); 33 AutofillWebDataBackend();
39 34
40 AutofillWebDataService(scoped_refptr<WebDatabaseService> wdbs, 35 // Adds form fields to the web database.
41 const ProfileErrorCallback& callback); 36 WebDatabase::State AddFormElements(const std::vector<FormFieldData>& fields,
37 WebDatabase* db);
42 38
43 // Retrieve an AutofillWebDataService for the given context. 39 // Returns a vector of values which have been entered in form input fields
44 // Can return NULL in some contexts. 40 // named |name|.
45 static scoped_refptr<AutofillWebDataService> FromBrowserContext( 41 scoped_ptr<WDTypedResult> GetFormValuesForElementName(
46 content::BrowserContext* context);
47
48 // Notifies listeners on the UI thread that multiple changes have been made to
49 // to Autofill records of the database.
50 // NOTE: This method is intended to be called from the DB thread. It
51 // it asynchronously notifies listeners on the UI thread.
52 // |web_data_service| may be NULL for testing purposes.
53 static void NotifyOfMultipleAutofillChanges(
54 AutofillWebDataService* web_data_service);
55
56 // WebDataServiceBase implementation.
57 virtual void ShutdownOnUIThread() OVERRIDE;
58
59 // AutofillWebData implementation.
60 virtual void AddFormFields(
61 const std::vector<FormFieldData>& fields) OVERRIDE;
62 virtual WebDataServiceBase::Handle GetFormValuesForElementName(
63 const base::string16& name, 42 const base::string16& name,
64 const base::string16& prefix, 43 const base::string16& prefix,
65 int limit, 44 int limit,
66 WebDataServiceConsumer* consumer) OVERRIDE; 45 WebDatabase* db);
67 virtual void RemoveFormElementsAddedBetween(
68 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE;
69 virtual void RemoveExpiredFormElements() OVERRIDE;
70 virtual void RemoveFormValueForElementName(
71 const base::string16& name,
72 const base::string16& value) OVERRIDE;
73 virtual void AddAutofillProfile(const AutofillProfile& profile) OVERRIDE;
74 virtual void UpdateAutofillProfile(const AutofillProfile& profile) OVERRIDE;
75 virtual void RemoveAutofillProfile(const std::string& guid) OVERRIDE;
76 virtual WebDataServiceBase::Handle GetAutofillProfiles(
77 WebDataServiceConsumer* consumer) OVERRIDE;
78 virtual void AddCreditCard(const CreditCard& credit_card) OVERRIDE;
79 virtual void UpdateCreditCard(const CreditCard& credit_card) OVERRIDE;
80 virtual void RemoveCreditCard(const std::string& guid) OVERRIDE;
81 virtual WebDataServiceBase::Handle GetCreditCards(
82 WebDataServiceConsumer* consumer) OVERRIDE;
83 virtual void RemoveAutofillDataModifiedBetween(
84 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE;
85 46
47 // Removes form elements recorded for Autocomplete from the database.
48 WebDatabase::State RemoveFormElementsAddedBetween(
49 const base::Time& delete_begin,
50 const base::Time& delete_end,
51 WebDatabase* db);
52
53 // Removes expired form elements recorded for Autocomplete from the database.
54 WebDatabase::State RemoveExpiredFormElements(WebDatabase* db);
55
56 // Removes the Form-value |value| which has been entered in form input fields
57 // named |name| from the database.
58 WebDatabase::State RemoveFormValueForElementName(const base::string16& name,
59 const base::string16& value,
60 WebDatabase* db);
61
62 // Adds an Autofill profile to the web database.
63 WebDatabase::State AddAutofillProfile(const AutofillProfile& profile,
64 WebDatabase* db);
65
66 // Updates an Autofill profile in the web database.
67 WebDatabase::State UpdateAutofillProfile(const AutofillProfile& profile,
68 WebDatabase* db);
69
70 // Removes an Autofill profile from the web database.
71 WebDatabase::State RemoveAutofillProfile(const std::string& guid,
72 WebDatabase* db);
73
74 // Returns all Autofill profiles from the web database.
75 scoped_ptr<WDTypedResult> GetAutofillProfiles(WebDatabase* db);
76
77 // Adds a credit card to the web database.
78 WebDatabase::State AddCreditCard(const CreditCard& credit_card,
79 WebDatabase* db);
80
81 // Updates a credit card in the web database.
82 WebDatabase::State UpdateCreditCard(const CreditCard& credit_card,
83 WebDatabase* db);
84
85 // Removes a credit card from the web database.
86 WebDatabase::State RemoveCreditCard(const std::string& guid,
87 WebDatabase* db);
88
89 // Returns a vector of all credit cards from the web database.
90 scoped_ptr<WDTypedResult> GetCreditCards(WebDatabase* db);
91
92 // Removes Autofill records from the database.
93 WebDatabase::State RemoveAutofillDataModifiedBetween(
94 const base::Time& delete_begin,
95 const base::Time& delete_end,
96 WebDatabase* db);
97
98 // Add an observer to be notified of changes on the DB thread.
86 void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer); 99 void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer);
100
101 // Remove an observer.
87 void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer); 102 void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer);
88 103
89 void AddObserver(AutofillWebDataServiceObserverOnUIThread* observer);
90 void RemoveObserver(AutofillWebDataServiceObserverOnUIThread* observer);
91
92 // Returns a SupportsUserData objects that may be used to store data
93 // owned by the DB thread on this object. Should be called only from
94 // the DB thread, and will be destroyed on the DB thread soon after
95 // |ShutdownOnUIThread()| is called.
96 base::SupportsUserData* GetDBUserData();
97
98 protected: 104 protected:
99 virtual ~AutofillWebDataService(); 105 virtual ~AutofillWebDataBackend();
100
101 virtual void ShutdownOnDBThread();
102 106
103 private: 107 private:
104 WebDatabase::State AddFormElementsImpl( 108 friend struct content::BrowserThread::DeleteOnThread<
105 const std::vector<FormFieldData>& fields, WebDatabase* db); 109 content::BrowserThread::DB>;
106 scoped_ptr<WDTypedResult> GetFormValuesForElementNameImpl( 110 friend class base::DeleteHelper<AutofillWebDataBackend>;
107 const base::string16& name, const base::string16& prefix, int limit, 111 // We have to friend RCTS<> so WIN shared-lib build is happy
108 WebDatabase* db); 112 // (http://crbug/112250).
109 WebDatabase::State RemoveFormElementsAddedBetweenImpl( 113 friend class base::RefCountedThreadSafe<AutofillWebDataBackend,
110 const base::Time& delete_begin, const base::Time& delete_end, 114 content::BrowserThread::DeleteOnDBThread>;
111 WebDatabase* db);
112 WebDatabase::State RemoveExpiredFormElementsImpl(WebDatabase* db);
113 WebDatabase::State RemoveFormValueForElementNameImpl(
114 const base::string16& name, const base::string16& value, WebDatabase* db);
115 WebDatabase::State AddAutofillProfileImpl(
116 const AutofillProfile& profile, WebDatabase* db);
117 WebDatabase::State UpdateAutofillProfileImpl(
118 const AutofillProfile& profile, WebDatabase* db);
119 WebDatabase::State RemoveAutofillProfileImpl(
120 const std::string& guid, WebDatabase* db);
121 scoped_ptr<WDTypedResult> GetAutofillProfilesImpl(WebDatabase* db);
122 WebDatabase::State AddCreditCardImpl(
123 const CreditCard& credit_card, WebDatabase* db);
124 WebDatabase::State UpdateCreditCardImpl(
125 const CreditCard& credit_card, WebDatabase* db);
126 WebDatabase::State RemoveCreditCardImpl(
127 const std::string& guid, WebDatabase* db);
128 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db);
129 WebDatabase::State RemoveAutofillDataModifiedBetweenImpl(
130 const base::Time& delete_begin, const base::Time& delete_end,
131 WebDatabase* db);
132 115
133 // Callbacks to ensure that sensitive info is destroyed if request is 116 // Callbacks to ensure that sensitive info is destroyed if request is
134 // cancelled. 117 // cancelled.
135 void DestroyAutofillProfileResult(const WDTypedResult* result); 118 void DestroyAutofillProfileResult(const WDTypedResult* result);
136 void DestroyAutofillCreditCardResult(const WDTypedResult* result); 119 void DestroyAutofillCreditCardResult(const WDTypedResult* result);
137 120
138 void NotifyAutofillMultipleChangedOnUIThread(); 121 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_;
139 122
140 // This makes the destructor public, and thus allows us to aggregate 123 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackend);
141 // SupportsUserData. It is private by default to prevent incorrect
142 // usage in class hierarchies where it is inherited by
143 // reference-counted objects.
144 class SupportsUserDataAggregatable : public base::SupportsUserData {
145 public:
146 SupportsUserDataAggregatable() {}
147 virtual ~SupportsUserDataAggregatable() {}
148 private:
149 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable);
150 };
151
152 // Storage for user data to be accessed only on the DB thread. May
153 // be used e.g. for SyncableService subclasses that need to be owned
154 // by this object. Is created on first call to |GetDBUserData()|.
155 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_;
156
157 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_;
158 ObserverList<AutofillWebDataServiceObserverOnUIThread> ui_observer_list_;
159
160 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataService);
161 }; 124 };
162 125
163 } // namespace autofill 126 } // namespace autofill
164 127
165 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_SERVICE_H_ 128 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698