| 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_CORE_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ |
| 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // exp_year Four-digit year: 2017 | 156 // exp_year Four-digit year: 2017 |
| 157 // | 157 // |
| 158 // unmasked_credit_cards | 158 // unmasked_credit_cards |
| 159 // When a masked credit credit card is unmasked and the | 159 // When a masked credit credit card is unmasked and the |
| 160 // full number is downloaded, it will be stored here. | 160 // full number is downloaded, it will be stored here. |
| 161 // | 161 // |
| 162 // id Server ID. This can be joined with the id in the | 162 // id Server ID. This can be joined with the id in the |
| 163 // masked_credit_cards table to get the rest of the data. | 163 // masked_credit_cards table to get the rest of the data. |
| 164 // card_number_encrypted | 164 // card_number_encrypted |
| 165 // Full card number, encrypted. | 165 // Full card number, encrypted. |
| 166 // use_count The number of times this card has been used to fill | 166 // use_count DEPRECATED in version 65. See server_card_metadata. |
| 167 // a form. Added in version 62. | 167 // use_date DEPRECATED in version 65. See server_card_metadata. |
| 168 // use_date The date this card was last used to fill a form, in | |
| 169 // internal time format (NOT time_t). Added in version 62. | |
| 170 // unmask_date The date this card was unmasked in units of | 168 // unmask_date The date this card was unmasked in units of |
| 171 // Time::ToInternalValue. Added in version 64. | 169 // Time::ToInternalValue. Added in version 64. |
| 172 // | 170 // |
| 171 // server_card_metadata |
| 172 // Metadata (currently, usage data) about server credit |
| 173 // cards. This will be synced. |
| 174 // |
| 175 // id The server ID, which matches an ID from the |
| 176 // masked_credit_cards table. |
| 177 // use_count The number of times this card has been used to fill |
| 178 // a form. |
| 179 // use_date The date this card was last used to fill a form, |
| 180 // in internal t. |
| 181 // |
| 173 // server_addresses This table contains Autofill address data synced from | 182 // server_addresses This table contains Autofill address data synced from |
| 174 // the wallet server. It's basically the same as the | 183 // the wallet server. It's basically the same as the |
| 175 // autofill_profiles table but locally immutable. | 184 // autofill_profiles table but locally immutable. |
| 176 // | 185 // |
| 177 // id String assigned by the server to identify this address. | 186 // id String assigned by the server to identify this address. |
| 178 // This is opaque to the client. | 187 // This is opaque to the client. |
| 179 // recipient_name Added in v63. | 188 // recipient_name Added in v63. |
| 180 // company_name | 189 // company_name |
| 181 // street_address The combined lines of the street address. | 190 // street_address The combined lines of the street address. |
| 182 // address_1 Also known as "administrative area". This is normally | 191 // address_1 Also known as "administrative area". This is normally |
| 183 // the state or province in most countries. | 192 // the state or province in most countries. |
| 184 // address_2 Also known as "locality". In the US this is the city. | 193 // address_2 Also known as "locality". In the US this is the city. |
| 185 // address_3 A sub-classification beneath the city, e.g. an | 194 // address_3 A sub-classification beneath the city, e.g. an |
| 186 // inner-city district or suburb. Also known as | 195 // inner-city district or suburb. Also known as |
| 187 // "dependent_locality". | 196 // "dependent_locality". |
| 188 // address_4 Used in certain countries. Also known as | 197 // address_4 Used in certain countries. Also known as |
| 189 // "sub_dependent_locality". | 198 // "sub_dependent_locality". |
| 190 // postal_code | 199 // postal_code |
| 191 // sorting_code Similar to the zipcode column, but used for businesses | 200 // sorting_code Similar to the zipcode column, but used for businesses |
| 192 // or organizations that might not be geographically | 201 // or organizations that might not be geographically |
| 193 // contiguous. The canonical example is CEDEX in France. | 202 // contiguous. The canonical example is CEDEX in France. |
| 194 // country_code | 203 // country_code |
| 195 // language_code The BCP 47 language code used to format the address for | 204 // language_code The BCP 47 language code used to format the address for |
| 196 // display. For example, a JP address with "ja" language | 205 // display. For example, a JP address with "ja" language |
| 197 // code starts with the postal code, but a JP address with | 206 // code starts with the postal code, but a JP address with |
| 198 // "ja-latn" language code starts with the recipient name. | 207 // "ja-latn" language code starts with the recipient name. |
| 199 // phone_number Phone number. This is a string and has no formatting | 208 // phone_number Phone number. This is a string and has no formatting |
| 200 // constraints. Added in version 64. | 209 // constraints. Added in version 64. |
| 210 // |
| 211 // server_address_metadata |
| 212 // Metadata (currently, usage data) about server addresses. |
| 213 // This will be synced. |
| 214 // |
| 215 // id The server ID, which matches an ID from the |
| 216 // server_addresses table. |
| 217 // use_count The number of times this address has been used to fill |
| 218 // a form. |
| 219 // use_date The date this address was last used to fill a form, |
| 220 // in internal t. |
| 221 |
| 201 class AutofillTable : public WebDatabaseTable { | 222 class AutofillTable : public WebDatabaseTable { |
| 202 public: | 223 public: |
| 203 explicit AutofillTable(const std::string& app_locale); | 224 explicit AutofillTable(const std::string& app_locale); |
| 204 ~AutofillTable() override; | 225 ~AutofillTable() override; |
| 205 | 226 |
| 206 // Retrieves the AutofillTable* owned by |database|. | 227 // Retrieves the AutofillTable* owned by |database|. |
| 207 static AutofillTable* FromWebDatabase(WebDatabase* db); | 228 static AutofillTable* FromWebDatabase(WebDatabase* db); |
| 208 | 229 |
| 209 WebDatabaseTable::TypeKey GetTypeKey() const override; | 230 WebDatabaseTable::TypeKey GetTypeKey() const override; |
| 210 bool CreateTablesIfNecessary() override; | 231 bool CreateTablesIfNecessary() override; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 virtual bool GetCreditCards(std::vector<CreditCard*>* credit_cards); | 330 virtual bool GetCreditCards(std::vector<CreditCard*>* credit_cards); |
| 310 virtual bool GetServerCreditCards(std::vector<CreditCard*>* credit_cards); | 331 virtual bool GetServerCreditCards(std::vector<CreditCard*>* credit_cards); |
| 311 | 332 |
| 312 // Replaces all server credit cards with the given vector. Unmasked cards | 333 // Replaces all server credit cards with the given vector. Unmasked cards |
| 313 // present in the new list will be preserved (even if the input is MASKED). | 334 // present in the new list will be preserved (even if the input is MASKED). |
| 314 void SetServerCreditCards(const std::vector<CreditCard>& credit_cards); | 335 void SetServerCreditCards(const std::vector<CreditCard>& credit_cards); |
| 315 | 336 |
| 316 // Cards synced from the server may be "masked" (only last 4 digits | 337 // Cards synced from the server may be "masked" (only last 4 digits |
| 317 // available) or "unmasked" (everything is available). These functions set | 338 // available) or "unmasked" (everything is available). These functions set |
| 318 // that state. | 339 // that state. |
| 319 bool UnmaskServerCreditCard(const std::string& id, | 340 bool UnmaskServerCreditCard(const CreditCard& masked, |
| 320 const base::string16& full_number); | 341 const base::string16& full_number); |
| 321 bool MaskServerCreditCard(const std::string& id); | 342 bool MaskServerCreditCard(const std::string& id); |
| 322 | 343 |
| 323 // Updates the use count and last use date for an unmasked server card. | 344 bool UpdateServerCardUsageStats(const CreditCard& credit_card); |
| 324 bool UpdateUnmaskedCardUsageStats(const CreditCard& credit_card); | 345 bool UpdateServerAddressUsageStats(const AutofillProfile& profile); |
| 325 | 346 |
| 326 // Deletes all data from the server card and profile tables. Returns true if | 347 // Deletes all data from the server card and profile tables. Returns true if |
| 327 // any data was deleted, false if not (so false means "commit not needed" | 348 // any data was deleted, false if not (so false means "commit not needed" |
| 328 // rather than "error"). | 349 // rather than "error"). |
| 329 bool ClearAllServerData(); | 350 bool ClearAllServerData(); |
| 330 | 351 |
| 331 // Removes rows from autofill_profiles and credit_cards if they were created | 352 // Removes rows from autofill_profiles and credit_cards if they were created |
| 332 // on or after |delete_begin| and strictly before |delete_end|. Returns the | 353 // on or after |delete_begin| and strictly before |delete_end|. Returns the |
| 333 // list of deleted profile guids in |profile_guids|. Return value is true if | 354 // list of deleted profile guids in |profile_guids|. Return value is true if |
| 334 // all rows were successfully removed. Returns false on database error. In | 355 // all rows were successfully removed. Returns false on database error. In |
| (...skipping 23 matching lines...) Expand all Loading... |
| 358 // Empties the Autofill profiles "trash can". | 379 // Empties the Autofill profiles "trash can". |
| 359 bool EmptyAutofillProfilesTrash(); | 380 bool EmptyAutofillProfilesTrash(); |
| 360 | 381 |
| 361 // Retrieves all profiles in the database that have been deleted since last | 382 // Retrieves all profiles in the database that have been deleted since last |
| 362 // "empty" of the trash. | 383 // "empty" of the trash. |
| 363 bool AddAutofillGUIDToTrash(const std::string& guid); | 384 bool AddAutofillGUIDToTrash(const std::string& guid); |
| 364 | 385 |
| 365 // Clear all profiles. | 386 // Clear all profiles. |
| 366 bool ClearAutofillProfiles(); | 387 bool ClearAutofillProfiles(); |
| 367 | 388 |
| 368 // Table migration functions. | 389 // Table migration functions. NB: These do not and should not rely on other |
| 390 // functions in this class. The implementation of a function such as |
| 391 // GetCreditCard may change over time, but MigrateToVersionXX should never |
| 392 // change. |
| 369 bool MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields(); | 393 bool MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields(); |
| 370 bool MigrateToVersion55MergeAutofillDatesTable(); | 394 bool MigrateToVersion55MergeAutofillDatesTable(); |
| 371 bool MigrateToVersion56AddProfileLanguageCodeForFormatting(); | 395 bool MigrateToVersion56AddProfileLanguageCodeForFormatting(); |
| 372 bool MigrateToVersion57AddFullNameField(); | 396 bool MigrateToVersion57AddFullNameField(); |
| 373 bool MigrateToVersion60AddServerCards(); | 397 bool MigrateToVersion60AddServerCards(); |
| 374 bool MigrateToVersion61AddUsageStats(); | 398 bool MigrateToVersion61AddUsageStats(); |
| 375 bool MigrateToVersion62AddUsageStatsForUnmaskedCards(); | 399 bool MigrateToVersion62AddUsageStatsForUnmaskedCards(); |
| 376 bool MigrateToVersion63AddServerRecipientName(); | 400 bool MigrateToVersion63AddServerRecipientName(); |
| 377 bool MigrateToVersion64AddUnmaskDate(); | 401 bool MigrateToVersion64AddUnmaskDate(); |
| 402 bool MigrateToVersion65AddServerMetadataTables(); |
| 378 | 403 |
| 379 // Max data length saved in the table; | 404 // Max data length saved in the table; |
| 380 static const size_t kMaxDataLength; | 405 static const size_t kMaxDataLength; |
| 381 | 406 |
| 382 private: | 407 private: |
| 383 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, Autofill); | 408 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, Autofill); |
| 384 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, Autofill_AddChanges); | 409 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, Autofill_AddChanges); |
| 385 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, Autofill_RemoveBetweenChanges); | 410 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, Autofill_RemoveBetweenChanges); |
| 386 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, Autofill_UpdateDontReplace); | 411 FRIEND_TEST_ALL_PREFIXES(AutofillTableTest, Autofill_UpdateDontReplace); |
| 387 FRIEND_TEST_ALL_PREFIXES( | 412 FRIEND_TEST_ALL_PREFIXES( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 bool InitMainTable(); | 462 bool InitMainTable(); |
| 438 bool InitCreditCardsTable(); | 463 bool InitCreditCardsTable(); |
| 439 bool InitDatesTable(); | 464 bool InitDatesTable(); |
| 440 bool InitProfilesTable(); | 465 bool InitProfilesTable(); |
| 441 bool InitProfileNamesTable(); | 466 bool InitProfileNamesTable(); |
| 442 bool InitProfileEmailsTable(); | 467 bool InitProfileEmailsTable(); |
| 443 bool InitProfilePhonesTable(); | 468 bool InitProfilePhonesTable(); |
| 444 bool InitProfileTrashTable(); | 469 bool InitProfileTrashTable(); |
| 445 bool InitMaskedCreditCardsTable(); | 470 bool InitMaskedCreditCardsTable(); |
| 446 bool InitUnmaskedCreditCardsTable(); | 471 bool InitUnmaskedCreditCardsTable(); |
| 472 bool InitServerCardMetadataTable(); |
| 447 bool InitServerAddressesTable(); | 473 bool InitServerAddressesTable(); |
| 474 bool InitServerAddressMetadataTable(); |
| 448 | 475 |
| 449 // The application locale. The locale is needed for the migration to version | 476 // The application locale. The locale is needed for the migration to version |
| 450 // 35. Since it must be read on the UI thread, it is set when the table is | 477 // 35. Since it must be read on the UI thread, it is set when the table is |
| 451 // created (on the UI thread), and cached here so that it can be used for | 478 // created (on the UI thread), and cached here so that it can be used for |
| 452 // migrations (on the DB thread). | 479 // migrations (on the DB thread). |
| 453 std::string app_locale_; | 480 std::string app_locale_; |
| 454 | 481 |
| 455 DISALLOW_COPY_AND_ASSIGN(AutofillTable); | 482 DISALLOW_COPY_AND_ASSIGN(AutofillTable); |
| 456 }; | 483 }; |
| 457 | 484 |
| 458 } // namespace autofill | 485 } // namespace autofill |
| 459 | 486 |
| 460 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ | 487 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_TABLE_H_ |
| OLD | NEW |