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 #include "chrome/browser/webdata/autofill_table.h" | 5 #include "chrome/browser/webdata/autofill_table.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 324 |
325 WebDatabaseTable::TypeKey GetKey() { | 325 WebDatabaseTable::TypeKey GetKey() { |
326 return reinterpret_cast<void*>(&table_key); | 326 return reinterpret_cast<void*>(&table_key); |
327 } | 327 } |
328 | 328 |
329 } // namespace | 329 } // namespace |
330 | 330 |
331 // The maximum length allowed for form data. | 331 // The maximum length allowed for form data. |
332 const size_t AutofillTable::kMaxDataLength = 1024; | 332 const size_t AutofillTable::kMaxDataLength = 1024; |
333 | 333 |
334 AutofillTable::AutofillTable() { | 334 AutofillTable::AutofillTable() |
| 335 : app_locale_(AutofillCountry::ApplicationLocale()) { |
335 } | 336 } |
336 | 337 |
337 AutofillTable::~AutofillTable() { | 338 AutofillTable::~AutofillTable() { |
338 } | 339 } |
339 | 340 |
340 AutofillTable* AutofillTable::FromWebDatabase(WebDatabase* db) { | 341 AutofillTable* AutofillTable::FromWebDatabase(WebDatabase* db) { |
341 return static_cast<AutofillTable*>(db->GetTable(GetKey())); | 342 return static_cast<AutofillTable*>(db->GetTable(GetKey())); |
342 } | 343 } |
343 | 344 |
344 WebDatabaseTable::TypeKey AutofillTable::GetTypeKey() const { | 345 WebDatabaseTable::TypeKey AutofillTable::GetTypeKey() const { |
345 return GetKey(); | 346 return GetKey(); |
346 } | 347 } |
347 | 348 |
348 bool AutofillTable::Init(sql::Connection* db, sql::MetaTable* meta_table) { | 349 bool AutofillTable::Init(sql::Connection* db, sql::MetaTable* meta_table) { |
349 WebDatabaseTable::Init(db, meta_table); | 350 WebDatabaseTable::Init(db, meta_table); |
350 return (InitMainTable() && InitCreditCardsTable() && InitDatesTable() && | 351 return (InitMainTable() && InitCreditCardsTable() && InitDatesTable() && |
351 InitProfilesTable() && InitProfileNamesTable() && | 352 InitProfilesTable() && InitProfileNamesTable() && |
352 InitProfileEmailsTable() && InitProfilePhonesTable() && | 353 InitProfileEmailsTable() && InitProfilePhonesTable() && |
353 InitProfileTrashTable()); | 354 InitProfileTrashTable()); |
354 } | 355 } |
355 | 356 |
356 bool AutofillTable::IsSyncable() { | 357 bool AutofillTable::IsSyncable() { |
357 return true; | 358 return true; |
358 } | 359 } |
359 | 360 |
360 bool AutofillTable::MigrateToVersion(int version, | 361 bool AutofillTable::MigrateToVersion(int version, |
361 const std::string& app_locale, | |
362 bool* update_compatible_version) { | 362 bool* update_compatible_version) { |
363 // Migrate if necessary. | 363 // Migrate if necessary. |
364 switch (version) { | 364 switch (version) { |
365 case 22: | 365 case 22: |
366 return ClearAutofillEmptyValueElements(); | 366 return ClearAutofillEmptyValueElements(); |
367 case 23: | 367 case 23: |
368 return MigrateToVersion23AddCardNumberEncryptedColumn(); | 368 return MigrateToVersion23AddCardNumberEncryptedColumn(); |
369 case 24: | 369 case 24: |
370 return MigrateToVersion24CleanupOversizedStringFields(); | 370 return MigrateToVersion24CleanupOversizedStringFields(); |
371 case 27: | 371 case 27: |
372 *update_compatible_version = true; | 372 *update_compatible_version = true; |
373 return MigrateToVersion27UpdateLegacyCreditCards(); | 373 return MigrateToVersion27UpdateLegacyCreditCards(); |
374 case 30: | 374 case 30: |
375 *update_compatible_version = true; | 375 *update_compatible_version = true; |
376 return MigrateToVersion30AddDateModifed(); | 376 return MigrateToVersion30AddDateModifed(); |
377 case 31: | 377 case 31: |
378 *update_compatible_version = true; | 378 *update_compatible_version = true; |
379 return MigrateToVersion31AddGUIDToCreditCardsAndProfiles(); | 379 return MigrateToVersion31AddGUIDToCreditCardsAndProfiles(); |
380 case 32: | 380 case 32: |
381 *update_compatible_version = true; | 381 *update_compatible_version = true; |
382 return MigrateToVersion32UpdateProfilesAndCreditCards(); | 382 return MigrateToVersion32UpdateProfilesAndCreditCards(); |
383 case 33: | 383 case 33: |
384 *update_compatible_version = true; | 384 *update_compatible_version = true; |
385 return MigrateToVersion33ProfilesBasedOnFirstName(); | 385 return MigrateToVersion33ProfilesBasedOnFirstName(); |
386 case 34: | 386 case 34: |
387 *update_compatible_version = true; | 387 *update_compatible_version = true; |
388 return MigrateToVersion34ProfilesBasedOnCountryCode(app_locale); | 388 return MigrateToVersion34ProfilesBasedOnCountryCode(); |
389 case 35: | 389 case 35: |
390 *update_compatible_version = true; | 390 *update_compatible_version = true; |
391 return MigrateToVersion35GreatBritainCountryCodes(); | 391 return MigrateToVersion35GreatBritainCountryCodes(); |
392 // Combine migrations 36 and 37. This is due to enhancements to the merge | 392 // Combine migrations 36 and 37. This is due to enhancements to the merge |
393 // step when migrating profiles. The original migration from 35 to 36 did | 393 // step when migrating profiles. The original migration from 35 to 36 did |
394 // not merge profiles with identical addresses, but the migration from 36 to | 394 // not merge profiles with identical addresses, but the migration from 36 to |
395 // 37 does. The step from 35 to 36 should only happen on the Chrome 12 dev | 395 // 37 does. The step from 35 to 36 should only happen on the Chrome 12 dev |
396 // channel. Chrome 12 beta and release users will jump from 35 to 37 | 396 // channel. Chrome 12 beta and release users will jump from 35 to 37 |
397 // directly getting the full benefits of the multi-valued merge as well as | 397 // directly getting the full benefits of the multi-valued merge as well as |
398 // the culling of bad data. | 398 // the culling of bad data. |
(...skipping 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1920 return false; | 1920 return false; |
1921 } | 1921 } |
1922 | 1922 |
1923 return true; | 1923 return true; |
1924 } | 1924 } |
1925 | 1925 |
1926 // Test the existence of the |country_code| column as an indication that | 1926 // Test the existence of the |country_code| column as an indication that |
1927 // we need a migration. It is possible that the new |autofill_profiles| | 1927 // we need a migration. It is possible that the new |autofill_profiles| |
1928 // schema is in place because the table was newly created when migrating | 1928 // schema is in place because the table was newly created when migrating |
1929 // from a pre-version-22 database. | 1929 // from a pre-version-22 database. |
1930 bool AutofillTable::MigrateToVersion34ProfilesBasedOnCountryCode( | 1930 bool AutofillTable::MigrateToVersion34ProfilesBasedOnCountryCode() { |
1931 const std::string& app_locale) { | |
1932 if (!db_->DoesColumnExist("autofill_profiles", "country_code")) { | 1931 if (!db_->DoesColumnExist("autofill_profiles", "country_code")) { |
1933 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " | 1932 if (!db_->Execute("ALTER TABLE autofill_profiles ADD COLUMN " |
1934 "country_code VARCHAR")) { | 1933 "country_code VARCHAR")) { |
1935 return false; | 1934 return false; |
1936 } | 1935 } |
1937 | 1936 |
1938 // Set all the |country_code| fields to match existing |country| values. | 1937 // Set all the |country_code| fields to match existing |country| values. |
1939 sql::Statement s(db_->GetUniqueStatement("SELECT guid, country " | 1938 sql::Statement s(db_->GetUniqueStatement("SELECT guid, country " |
1940 "FROM autofill_profiles")); | 1939 "FROM autofill_profiles")); |
1941 | 1940 |
1942 while (s.Step()) { | 1941 while (s.Step()) { |
1943 sql::Statement update_s( | 1942 sql::Statement update_s( |
1944 db_->GetUniqueStatement("UPDATE autofill_profiles " | 1943 db_->GetUniqueStatement("UPDATE autofill_profiles " |
1945 "SET country_code=? WHERE guid=?")); | 1944 "SET country_code=? WHERE guid=?")); |
1946 | 1945 |
1947 string16 country = s.ColumnString16(1); | 1946 string16 country = s.ColumnString16(1); |
1948 update_s.BindString(0, AutofillCountry::GetCountryCode(country, | 1947 update_s.BindString(0, AutofillCountry::GetCountryCode(country, |
1949 app_locale)); | 1948 app_locale_)); |
1950 update_s.BindString(1, s.ColumnString(0)); | 1949 update_s.BindString(1, s.ColumnString(0)); |
1951 | 1950 |
1952 if (!update_s.Run()) | 1951 if (!update_s.Run()) |
1953 return false; | 1952 return false; |
1954 } | 1953 } |
1955 if (!s.Succeeded()) | 1954 if (!s.Succeeded()) |
1956 return false; | 1955 return false; |
1957 } | 1956 } |
1958 | 1957 |
1959 return true; | 1958 return true; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 "WHERE guid=?")); | 2038 "WHERE guid=?")); |
2040 s_date.BindInt64(0, date_item->second); | 2039 s_date.BindInt64(0, date_item->second); |
2041 s_date.BindString(1, iter->guid()); | 2040 s_date.BindString(1, iter->guid()); |
2042 | 2041 |
2043 if (!s_date.Run()) | 2042 if (!s_date.Run()) |
2044 return false; | 2043 return false; |
2045 } | 2044 } |
2046 | 2045 |
2047 return true; | 2046 return true; |
2048 } | 2047 } |
OLD | NEW |