Chromium Code Reviews| 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 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 10 #include "components/autofill/browser/webdata/autofill_webdata.h" | 11 #include "components/autofill/browser/webdata/autofill_webdata.h" |
| 12 #include "components/autofill/browser/webdata/syncable_service_backend.h" | |
| 11 #include "components/autofill/common/form_field_data.h" | 13 #include "components/autofill/common/form_field_data.h" |
| 12 #include "components/webdata/common/web_data_results.h" | 14 #include "components/webdata/common/web_data_results.h" |
| 13 #include "components/webdata/common/web_data_service_base.h" | 15 #include "components/webdata/common/web_data_service_base.h" |
| 14 #include "components/webdata/common/web_data_service_consumer.h" | 16 #include "components/webdata/common/web_data_service_consumer.h" |
| 15 #include "components/webdata/common/web_database.h" | 17 #include "components/webdata/common/web_database.h" |
| 16 | 18 |
| 19 class WebDataServiceBackend; | |
| 20 | |
| 17 namespace autofill { | 21 namespace autofill { |
| 18 | 22 |
| 19 class AutofillChange; | 23 class AutofillChange; |
| 20 class AutofillProfile; | 24 class AutofillProfile; |
| 21 class AutofillWebDataServiceObserverOnDBThread; | 25 class AutofillWebDataServiceObserverOnDBThread; |
| 22 class CreditCard; | 26 class CreditCard; |
| 23 | 27 |
| 24 // Backend implentation for the AutofillWebDataService. This class runs on the | 28 // Backend implentation for the AutofillWebDataService. This class runs on the |
| 25 // DB thread, as it handles reads and writes to the WebDatabase, and functions | 29 // DB thread, as it handles reads and writes to the WebDatabase, and functions |
| 26 // in it should only be called from that thread. Most functions here are just | 30 // in it should only be called from that thread. Most functions here are just |
| 27 // the implementations of the corresponding functions in the Autofill | 31 // the implementations of the corresponding functions in the Autofill |
| 28 // WebDataService. | 32 // WebDataService. |
| 29 class AutofillWebDataBackend | 33 class AutofillWebDataBackend |
| 30 : public base::RefCountedThreadSafe<AutofillWebDataBackend, | 34 : public base::RefCountedThreadSafe<AutofillWebDataBackend, |
| 31 content::BrowserThread::DeleteOnDBThread> { | 35 content::BrowserThread::DeleteOnDBThread>, |
| 36 public SyncableServiceBackend { | |
| 32 public: | 37 public: |
| 33 AutofillWebDataBackend(); | 38 // |web_db_backend| is used to access the WebDatabase directly for |
| 39 // Sync-related operations. |on_changed_callback| is a closure which can be | |
| 40 // used to notify the UI thread of changes initiated by Sync. | |
|
Ilya Sherman
2013/05/08 00:39:06
Please document that |on_changed_callback| might b
Cait (Slow)
2013/05/08 19:16:01
Done.
| |
| 41 AutofillWebDataBackend(scoped_refptr<WebDataServiceBackend> web_db_backend, | |
|
Ilya Sherman
2013/05/08 00:39:06
nit: Please name this variable |web_database_backe
Cait (Slow)
2013/05/08 19:16:01
Adding a todo to rename WebDataServiceBackend to W
| |
| 42 const base::Closure& on_changed_callback); | |
| 43 | |
| 44 // SyncableServiceBackend implementation. | |
| 45 virtual void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer) | |
| 46 OVERRIDE; | |
|
Ilya Sherman
2013/05/08 00:39:06
nit: Indent two more spaces.
Cait (Slow)
2013/05/08 19:16:01
Done.
| |
| 47 virtual void RemoveObserver( | |
| 48 AutofillWebDataServiceObserverOnDBThread* observer) OVERRIDE; | |
|
Ilya Sherman
2013/05/08 00:39:06
nit: Indent two more spaces.
Cait (Slow)
2013/05/08 19:16:01
Done.
| |
| 49 virtual WebDatabase* GetDatabaseOnDB() OVERRIDE; | |
| 50 virtual void RemoveExpiredFormElementsWrapper() OVERRIDE; | |
| 51 virtual void NotifyOfMultipleAutofillChanges() OVERRIDE; | |
| 34 | 52 |
| 35 // Adds form fields to the web database. | 53 // Adds form fields to the web database. |
| 36 WebDatabase::State AddFormElements(const std::vector<FormFieldData>& fields, | 54 WebDatabase::State AddFormElements(const std::vector<FormFieldData>& fields, |
| 37 WebDatabase* db); | 55 WebDatabase* db); |
| 38 | 56 |
| 39 // Returns a vector of values which have been entered in form input fields | 57 // Returns a vector of values which have been entered in form input fields |
| 40 // named |name|. | 58 // named |name|. |
| 41 scoped_ptr<WDTypedResult> GetFormValuesForElementName( | 59 scoped_ptr<WDTypedResult> GetFormValuesForElementName( |
| 42 const base::string16& name, | 60 const base::string16& name, |
| 43 const base::string16& prefix, | 61 const base::string16& prefix, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 | 106 |
| 89 // Returns a vector of all credit cards from the web database. | 107 // Returns a vector of all credit cards from the web database. |
| 90 scoped_ptr<WDTypedResult> GetCreditCards(WebDatabase* db); | 108 scoped_ptr<WDTypedResult> GetCreditCards(WebDatabase* db); |
| 91 | 109 |
| 92 // Removes Autofill records from the database. | 110 // Removes Autofill records from the database. |
| 93 WebDatabase::State RemoveAutofillDataModifiedBetween( | 111 WebDatabase::State RemoveAutofillDataModifiedBetween( |
| 94 const base::Time& delete_begin, | 112 const base::Time& delete_begin, |
| 95 const base::Time& delete_end, | 113 const base::Time& delete_end, |
| 96 WebDatabase* db); | 114 WebDatabase* db); |
| 97 | 115 |
| 98 // Add an observer to be notified of changes on the DB thread. | |
| 99 void AddObserver(AutofillWebDataServiceObserverOnDBThread* observer); | |
| 100 | |
| 101 // Remove an observer. | |
| 102 void RemoveObserver(AutofillWebDataServiceObserverOnDBThread* observer); | |
| 103 | |
| 104 protected: | 116 protected: |
| 105 virtual ~AutofillWebDataBackend(); | 117 virtual ~AutofillWebDataBackend(); |
| 106 | 118 |
| 107 private: | 119 private: |
| 108 friend struct content::BrowserThread::DeleteOnThread< | 120 friend struct content::BrowserThread::DeleteOnThread< |
| 109 content::BrowserThread::DB>; | 121 content::BrowserThread::DB>; |
| 110 friend class base::DeleteHelper<AutofillWebDataBackend>; | 122 friend class base::DeleteHelper<AutofillWebDataBackend>; |
| 111 // We have to friend RCTS<> so WIN shared-lib build is happy | 123 // We have to friend RCTS<> so WIN shared-lib build is happy |
| 112 // (http://crbug/112250). | 124 // (http://crbug/112250). |
| 113 friend class base::RefCountedThreadSafe<AutofillWebDataBackend, | 125 friend class base::RefCountedThreadSafe<AutofillWebDataBackend, |
| 114 content::BrowserThread::DeleteOnDBThread>; | 126 content::BrowserThread::DeleteOnDBThread>; |
| 115 | 127 |
| 116 // Callbacks to ensure that sensitive info is destroyed if request is | 128 // Callbacks to ensure that sensitive info is destroyed if request is |
| 117 // cancelled. | 129 // cancelled. |
| 118 void DestroyAutofillProfileResult(const WDTypedResult* result); | 130 void DestroyAutofillProfileResult(const WDTypedResult* result); |
| 119 void DestroyAutofillCreditCardResult(const WDTypedResult* result); | 131 void DestroyAutofillCreditCardResult(const WDTypedResult* result); |
| 120 | 132 |
| 121 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_; | 133 ObserverList<AutofillWebDataServiceObserverOnDBThread> db_observer_list_; |
| 122 | 134 |
| 135 // Ptr to WebDataServiceBackend to allow direct access to DB. | |
|
Ilya Sherman
2013/05/08 00:39:06
nit: Omit "Ptr to"
Cait (Slow)
2013/05/08 19:16:01
Done.
| |
| 136 // TODO(caitkp): Make it so nobody but us needs direct DB access anymore. | |
| 137 scoped_refptr<WebDataServiceBackend> web_database_backend_; | |
| 138 | |
| 139 scoped_ptr<base::Closure> on_changed_callback_; | |
| 140 | |
| 123 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackend); | 141 DISALLOW_COPY_AND_ASSIGN(AutofillWebDataBackend); |
| 124 }; | 142 }; |
| 125 | 143 |
| 126 } // namespace autofill | 144 } // namespace autofill |
| 127 | 145 |
| 128 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ | 146 #endif // COMPONENTS_AUTOFILL_BROWSER_WEBDATA_AUTOFILL_WEBDATA_BACKEND_H_ |
| OLD | NEW |