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