OLD | NEW |
1 // Copyright 2013 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_BACKEND_H_ | 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ |
6 #define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ | 6 #define COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 class WebDatabase; |
9 #include "base/observer_list.h" | |
10 #include "components/autofill/browser/webdata/autofill_webdata.h" | |
11 #include "components/autofill/common/form_field_data.h" | |
12 #include "components/webdata/common/web_data_results.h" | |
13 #include "components/webdata/common/web_data_service_base.h" | |
14 #include "components/webdata/common/web_data_service_consumer.h" | |
15 #include "components/webdata/common/web_database.h" | |
16 | 9 |
17 namespace autofill { | 10 namespace autofill { |
18 | 11 |
19 class AutofillChange; | |
20 class AutofillProfile; | |
21 class AutofillWebDataServiceObserverOnDBThread; | 12 class AutofillWebDataServiceObserverOnDBThread; |
22 class CreditCard; | |
23 | 13 |
24 // Backend implentation for the AutofillWebDataService. This class runs on the | 14 // Interface for doing Autofill work directly on the DB thread (used by |
25 // DB thread, as it handles reads and writes to the WebDatabase, and functions | 15 // Sync, mostly), without fully exposing the AutofillWebDataBackend to clients. |
26 // in it should only be called from that thread. Most functions here are just | 16 class AutofillWebDataBackend { |
27 // the implementations of the corresponding functions in the Autofill | |
28 // WebDataService. | |
29 class AutofillWebDataBackend | |
30 : public base::RefCountedThreadSafe<AutofillWebDataBackend, | |
31 content::BrowserThread::DeleteOnDBThread> { | |
32 public: | 17 public: |
33 AutofillWebDataBackend(); | 18 virtual ~AutofillWebDataBackend() {} |
34 | 19 |
35 // Adds form fields to the web database. | 20 // Get a raw pointer to the WebDatabase. |
36 WebDatabase::State AddFormElements(const std::vector<FormFieldData>& fields, | 21 virtual WebDatabase* GetDatabase() = 0; |
37 WebDatabase* db); | |
38 | |
39 // Returns a vector of values which have been entered in form input fields | |
40 // named |name|. | |
41 scoped_ptr<WDTypedResult> GetFormValuesForElementName( | |
42 const base::string16& name, | |
43 const base::string16& prefix, | |
44 int limit, | |
45 WebDatabase* db); | |
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 | 22 |
98 // Add an observer to be notified of changes on the DB thread. | 23 // Add an observer to be notified of changes on the DB thread. |
99 void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer); | 24 virtual void AddObserver( |
| 25 AutofillWebDataServiceObserverOnDBThread* observer) = 0; |
100 | 26 |
101 // Remove an observer. | 27 // Remove an observer. |
102 void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer); | 28 virtual void RemoveObserver( |
| 29 AutofillWebDataServiceObserverOnDBThread* observer) = 0; |
103 | 30 |
104 protected: | 31 // Remove expired elements from the database and commit if needed. |
105 virtual ~AutofillWebDataBackend(); | 32 virtual void RemoveExpiredFormElementsWrapper() = 0; |
106 | 33 |
107 private: | 34 // Notifies listeners on the UI thread that multiple changes have been made to |
108 friend struct content::BrowserThread::DeleteOnThread< | 35 // to Autofill records of the database. |
109 content::BrowserThread::DB>; | 36 // NOTE: This method is intended to be called from the DB thread. It |
110 friend class base::DeleteHelper<AutofillWebDataBackend>; | 37 // asynchronously notifies listeners on the UI thread. |
111 // We have to friend RCTS<> so WIN shared-lib build is happy | 38 virtual void NotifyOfMultipleAutofillChanges() = 0; |
112 // (http://crbug/112250). | |
113 friend class base::RefCountedThreadSafe<AutofillWebDataBackend, | |
114 content::BrowserThread::DeleteOnDBThread>; | |
115 | |
116 // Callbacks to ensure that sensitive info is destroyed if request is | |
117 // cancelled. | |
118 void DestroyAutofillProfileResult(const WDTypedResult* result); | |
119 void DestroyAutofillCreditCardResult(const WDTypedResult* result); | |
120 | |
121 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_; | |
122 | |
123 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackend); | |
124 }; | 39 }; |
125 | 40 |
126 } // namespace autofill | 41 } // namespace autofill |
127 | 42 |
128 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ | 43 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ |
OLD | NEW |