OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ | 5 #ifndef CHROME_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ |
6 #define CHROME_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ | 6 #define CHROME_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "chrome/browser/webdata/web_database_table.h" | 11 #include "chrome/browser/webdata/web_database_table.h" |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 class AutofillChange; | 15 class AutofillChange; |
16 class AutofillEntry; | 16 class AutofillEntry; |
17 class AutofillProfile; | 17 class AutofillProfile; |
18 class AutofillTableTest; | 18 class AutofillTableTest; |
19 class CreditCard; | 19 class CreditCard; |
20 | 20 |
| 21 struct FormFieldData; |
| 22 |
21 namespace base { | 23 namespace base { |
22 class Time; | 24 class Time; |
23 } | 25 } |
24 | 26 |
25 namespace webkit { | |
26 namespace forms { | |
27 struct FormField; | |
28 } | |
29 } | |
30 | |
31 // This class manages the various autofill tables within the SQLite database | 27 // This class manages the various autofill tables within the SQLite database |
32 // passed to the constructor. It expects the following schemas: | 28 // passed to the constructor. It expects the following schemas: |
33 // | 29 // |
34 // Note: The database stores time in seconds, UTC. | 30 // Note: The database stores time in seconds, UTC. |
35 // | 31 // |
36 // autofill | 32 // autofill |
37 // name The name of the input as specified in the html. | 33 // name The name of the input as specified in the html. |
38 // value The literal contents of the text field. | 34 // value The literal contents of the text field. |
39 // value_lower The contents of the text field made lower_case. | 35 // value_lower The contents of the text field made lower_case. |
40 // pair_id An ID number unique to the row in the table. | 36 // pair_id An ID number unique to the row in the table. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 class AutofillTable : public WebDatabaseTable { | 115 class AutofillTable : public WebDatabaseTable { |
120 public: | 116 public: |
121 AutofillTable(sql::Connection* db, sql::MetaTable* meta_table); | 117 AutofillTable(sql::Connection* db, sql::MetaTable* meta_table); |
122 virtual ~AutofillTable(); | 118 virtual ~AutofillTable(); |
123 virtual bool Init() OVERRIDE; | 119 virtual bool Init() OVERRIDE; |
124 virtual bool IsSyncable() OVERRIDE; | 120 virtual bool IsSyncable() OVERRIDE; |
125 | 121 |
126 // Records the form elements in |elements| in the database in the | 122 // Records the form elements in |elements| in the database in the |
127 // autofill table. A list of all added and updated autofill entries | 123 // autofill table. A list of all added and updated autofill entries |
128 // is returned in the changes out parameter. | 124 // is returned in the changes out parameter. |
129 bool AddFormFieldValues(const std::vector<webkit::forms::FormField>& elements, | 125 bool AddFormFieldValues(const std::vector<FormFieldData>& elements, |
130 std::vector<AutofillChange>* changes); | 126 std::vector<AutofillChange>* changes); |
131 | 127 |
132 // Records a single form element in the database in the autofill table. A list | 128 // Records a single form element in the database in the autofill table. A list |
133 // of all added and updated autofill entries is returned in the changes out | 129 // of all added and updated autofill entries is returned in the changes out |
134 // parameter. | 130 // parameter. |
135 bool AddFormFieldValue(const webkit::forms::FormField& element, | 131 bool AddFormFieldValue(const FormFieldData& element, |
136 std::vector<AutofillChange>* changes); | 132 std::vector<AutofillChange>* changes); |
137 | 133 |
138 // Retrieves a vector of all values which have been recorded in the autofill | 134 // Retrieves a vector of all values which have been recorded in the autofill |
139 // table as the value in a form element with name |name| and which start with | 135 // table as the value in a form element with name |name| and which start with |
140 // |prefix|. The comparison of the prefix is case insensitive. | 136 // |prefix|. The comparison of the prefix is case insensitive. |
141 bool GetFormValuesForElementName(const string16& name, | 137 bool GetFormValuesForElementName(const string16& name, |
142 const string16& prefix, | 138 const string16& prefix, |
143 std::vector<string16>* values, | 139 std::vector<string16>* values, |
144 int limit); | 140 int limit); |
145 | 141 |
(...skipping 24 matching lines...) Expand all Loading... |
170 bool AddToCountOfFormElement(int64 pair_id, int delta); | 166 bool AddToCountOfFormElement(int64 pair_id, int delta); |
171 | 167 |
172 // Counts how many timestamp data rows are in the |autofill_dates| table for | 168 // Counts how many timestamp data rows are in the |autofill_dates| table for |
173 // a given |pair_id|. GetCountOfFormElement() on the other hand gives the | 169 // a given |pair_id|. GetCountOfFormElement() on the other hand gives the |
174 // |count| property for a given id. | 170 // |count| property for a given id. |
175 int CountTimestampsData(int64 pair_id); | 171 int CountTimestampsData(int64 pair_id); |
176 | 172 |
177 // Gets the pair_id and count entries from name and value specified in | 173 // Gets the pair_id and count entries from name and value specified in |
178 // |element|. Sets *pair_id and *count to 0 if there is no such row in | 174 // |element|. Sets *pair_id and *count to 0 if there is no such row in |
179 // the table. | 175 // the table. |
180 bool GetIDAndCountOfFormElement(const webkit::forms::FormField& element, | 176 bool GetIDAndCountOfFormElement(const FormFieldData& element, |
181 int64* pair_id, | 177 int64* pair_id, |
182 int* count); | 178 int* count); |
183 | 179 |
184 // Gets the count only given the pair_id. | 180 // Gets the count only given the pair_id. |
185 bool GetCountOfFormElement(int64 pair_id, int* count); | 181 bool GetCountOfFormElement(int64 pair_id, int* count); |
186 | 182 |
187 // Updates the count entry in the row corresponding to |pair_id| to |count|. | 183 // Updates the count entry in the row corresponding to |pair_id| to |count|. |
188 bool SetCountOfFormElement(int64 pair_id, int count); | 184 bool SetCountOfFormElement(int64 pair_id, int count); |
189 | 185 |
190 // Adds a new row to the autofill table with name and value given in | 186 // Adds a new row to the autofill table with name and value given in |
191 // |element|. Sets *pair_id to the pair_id of the new row. | 187 // |element|. Sets *pair_id to the pair_id of the new row. |
192 bool InsertFormElement(const webkit::forms::FormField& element, | 188 bool InsertFormElement(const FormFieldData& element, |
193 int64* pair_id); | 189 int64* pair_id); |
194 | 190 |
195 // Adds a new row to the autofill_dates table. | 191 // Adds a new row to the autofill_dates table. |
196 bool InsertPairIDAndDate(int64 pair_id, const base::Time& date_created); | 192 bool InsertPairIDAndDate(int64 pair_id, const base::Time& date_created); |
197 | 193 |
198 // Deletes last access to the Autofill data from the autofill_dates table. | 194 // Deletes last access to the Autofill data from the autofill_dates table. |
199 bool DeleteLastAccess(int64 pair_id); | 195 bool DeleteLastAccess(int64 pair_id); |
200 | 196 |
201 // Removes row from the autofill tables given |pair_id|. | 197 // Removes row from the autofill tables given |pair_id|. |
202 bool RemoveFormElementForID(int64 pair_id); | 198 bool RemoveFormElementForID(int64 pair_id); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, | 314 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, |
319 Autofill_GetAllAutofillEntries_OneResult); | 315 Autofill_GetAllAutofillEntries_OneResult); |
320 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, | 316 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, |
321 Autofill_GetAllAutofillEntries_TwoDistinct); | 317 Autofill_GetAllAutofillEntries_TwoDistinct); |
322 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, | 318 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, |
323 Autofill_GetAllAutofillEntries_TwoSame); | 319 Autofill_GetAllAutofillEntries_TwoSame); |
324 | 320 |
325 // Methods for adding autofill entries at a specified time. For | 321 // Methods for adding autofill entries at a specified time. For |
326 // testing only. | 322 // testing only. |
327 bool AddFormFieldValuesTime( | 323 bool AddFormFieldValuesTime( |
328 const std::vector<webkit::forms::FormField>& elements, | 324 const std::vector<FormFieldData>& elements, |
329 std::vector<AutofillChange>* changes, | 325 std::vector<AutofillChange>* changes, |
330 base::Time time); | 326 base::Time time); |
331 bool AddFormFieldValueTime(const webkit::forms::FormField& element, | 327 bool AddFormFieldValueTime(const FormFieldData& element, |
332 std::vector<AutofillChange>* changes, | 328 std::vector<AutofillChange>* changes, |
333 base::Time time); | 329 base::Time time); |
334 | 330 |
335 // Insert a single AutofillEntry into the autofill/autofill_dates tables. | 331 // Insert a single AutofillEntry into the autofill/autofill_dates tables. |
336 bool InsertAutofillEntry(const AutofillEntry& entry); | 332 bool InsertAutofillEntry(const AutofillEntry& entry); |
337 | 333 |
338 // Checks if the trash is empty. | 334 // Checks if the trash is empty. |
339 bool IsAutofillProfilesTrashEmpty(); | 335 bool IsAutofillProfilesTrashEmpty(); |
340 | 336 |
341 // Checks if the guid is in the trash. | 337 // Checks if the guid is in the trash. |
342 bool IsAutofillGUIDInTrash(const std::string& guid); | 338 bool IsAutofillGUIDInTrash(const std::string& guid); |
343 | 339 |
344 bool InitMainTable(); | 340 bool InitMainTable(); |
345 bool InitCreditCardsTable(); | 341 bool InitCreditCardsTable(); |
346 bool InitDatesTable(); | 342 bool InitDatesTable(); |
347 bool InitProfilesTable(); | 343 bool InitProfilesTable(); |
348 bool InitProfileNamesTable(); | 344 bool InitProfileNamesTable(); |
349 bool InitProfileEmailsTable(); | 345 bool InitProfileEmailsTable(); |
350 bool InitProfilePhonesTable(); | 346 bool InitProfilePhonesTable(); |
351 bool InitProfileTrashTable(); | 347 bool InitProfileTrashTable(); |
352 | 348 |
353 DISALLOW_COPY_AND_ASSIGN(AutofillTable); | 349 DISALLOW_COPY_AND_ASSIGN(AutofillTable); |
354 }; | 350 }; |
355 | 351 |
356 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ | 352 #endif // CHROME_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ |
OLD | NEW |