| 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 #include "components/autofill/core/browser/webdata/autofill_table.h" | 5 #include "components/autofill/core/browser/webdata/autofill_table.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 | 943 |
| 944 return s.Succeeded(); | 944 return s.Succeeded(); |
| 945 } | 945 } |
| 946 | 946 |
| 947 bool AutofillTable::GetServerProfiles( | 947 bool AutofillTable::GetServerProfiles( |
| 948 std::vector<std::unique_ptr<AutofillProfile>>* profiles) const { | 948 std::vector<std::unique_ptr<AutofillProfile>>* profiles) const { |
| 949 profiles->clear(); | 949 profiles->clear(); |
| 950 | 950 |
| 951 sql::Statement s(db_->GetUniqueStatement( | 951 sql::Statement s(db_->GetUniqueStatement( |
| 952 "SELECT " | 952 "SELECT " |
| 953 "id," | 953 "id," |
| 954 "use_count," | 954 "use_count," |
| 955 "use_date," | 955 "use_date," |
| 956 "recipient_name," | 956 "recipient_name," |
| 957 "company_name," | 957 "company_name," |
| 958 "street_address," | 958 "street_address," |
| 959 "address_1," // ADDRESS_HOME_STATE | 959 "address_1," // ADDRESS_HOME_STATE |
| 960 "address_2," // ADDRESS_HOME_CITY | 960 "address_2," // ADDRESS_HOME_CITY |
| 961 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY | 961 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY |
| 962 "address_4," // Not supported in AutofillProfile yet. | 962 "address_4," // Not supported in AutofillProfile yet. |
| 963 "postal_code," // ADDRESS_HOME_ZIP | 963 "postal_code," // ADDRESS_HOME_ZIP |
| 964 "sorting_code," // ADDRESS_HOME_SORTING_CODE | 964 "sorting_code," // ADDRESS_HOME_SORTING_CODE |
| 965 "country_code," // ADDRESS_HOME_COUNTRY | 965 "country_code," // ADDRESS_HOME_COUNTRY |
| 966 "phone_number," // PHONE_HOME_WHOLE_NUMBER | 966 "phone_number," // PHONE_HOME_WHOLE_NUMBER |
| 967 "language_code " | 967 "language_code, " |
| 968 "has_converted " |
| 968 "FROM server_addresses addresses " | 969 "FROM server_addresses addresses " |
| 969 "LEFT OUTER JOIN server_address_metadata USING (id)")); | 970 "LEFT OUTER JOIN server_address_metadata USING (id)")); |
| 970 | 971 |
| 971 while (s.Step()) { | 972 while (s.Step()) { |
| 972 int index = 0; | 973 int index = 0; |
| 973 std::unique_ptr<AutofillProfile> profile = | 974 std::unique_ptr<AutofillProfile> profile = |
| 974 base::MakeUnique<AutofillProfile>(AutofillProfile::SERVER_PROFILE, | 975 base::MakeUnique<AutofillProfile>(AutofillProfile::SERVER_PROFILE, |
| 975 s.ColumnString(index++)); | 976 s.ColumnString(index++)); |
| 976 profile->set_use_count(s.ColumnInt64(index++)); | 977 profile->set_use_count(s.ColumnInt64(index++)); |
| 977 profile->set_use_date(Time::FromInternalValue(s.ColumnInt64(index++))); | 978 profile->set_use_date(Time::FromInternalValue(s.ColumnInt64(index++))); |
| 978 // Modification date is not tracked for server profiles. Explicitly set it | 979 // Modification date is not tracked for server profiles. Explicitly set it |
| 979 // here to override the default value of Time::Now(). | 980 // here to override the default value of Time::Now(). |
| 980 profile->set_modification_date(Time()); | 981 profile->set_modification_date(Time()); |
| 981 | 982 |
| 982 base::string16 recipient_name = s.ColumnString16(index++); | 983 base::string16 recipient_name = s.ColumnString16(index++); |
| 983 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); | 984 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); |
| 984 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); | 985 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); |
| 985 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); | 986 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); |
| 986 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); | 987 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); |
| 987 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, | 988 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, |
| 988 s.ColumnString16(index++)); | 989 s.ColumnString16(index++)); |
| 989 index++; // Skip address_4 which we haven't added to AutofillProfile yet. | 990 index++; // Skip address_4 which we haven't added to AutofillProfile yet. |
| 990 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); | 991 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); |
| 991 profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++)); | 992 profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++)); |
| 992 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); | 993 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); |
| 993 base::string16 phone_number = s.ColumnString16(index++); | 994 base::string16 phone_number = s.ColumnString16(index++); |
| 994 profile->set_language_code(s.ColumnString(index++)); | 995 profile->set_language_code(s.ColumnString(index++)); |
| 996 profile->set_has_converted(s.ColumnBool(index++)); |
| 995 | 997 |
| 996 // SetInfo instead of SetRawInfo so the constituent pieces will be parsed | 998 // SetInfo instead of SetRawInfo so the constituent pieces will be parsed |
| 997 // for these data types. | 999 // for these data types. |
| 998 profile->SetInfo(AutofillType(NAME_FULL), recipient_name, | 1000 profile->SetInfo(AutofillType(NAME_FULL), recipient_name, |
| 999 profile->language_code()); | 1001 profile->language_code()); |
| 1000 profile->SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), phone_number, | 1002 profile->SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), phone_number, |
| 1001 profile->language_code()); | 1003 profile->language_code()); |
| 1002 | 1004 |
| 1003 profiles->push_back(std::move(profile)); | 1005 profiles->push_back(std::move(profile)); |
| 1004 } | 1006 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)); | 1050 profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)); |
| 1049 index++; // SKip address_4 which we haven't added to AutofillProfile yet. | 1051 index++; // SKip address_4 which we haven't added to AutofillProfile yet. |
| 1050 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_ZIP)); | 1052 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_ZIP)); |
| 1051 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)); | 1053 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)); |
| 1052 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_COUNTRY)); | 1054 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 1053 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); | 1055 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); |
| 1054 insert.BindString(index++, profile.language_code()); | 1056 insert.BindString(index++, profile.language_code()); |
| 1055 | 1057 |
| 1056 insert.Run(); | 1058 insert.Run(); |
| 1057 insert.Reset(true); | 1059 insert.Reset(true); |
| 1060 |
| 1061 // Save the use count and use date of the profile. |
| 1062 UpdateServerAddressMetadata(profile); |
| 1058 } | 1063 } |
| 1059 | 1064 |
| 1060 // Delete metadata that's no longer relevant. | 1065 // Delete metadata that's no longer relevant. |
| 1061 sql::Statement metadata_delete(db_->GetUniqueStatement( | 1066 sql::Statement metadata_delete(db_->GetUniqueStatement( |
| 1062 "DELETE FROM server_address_metadata WHERE id NOT IN " | 1067 "DELETE FROM server_address_metadata WHERE id NOT IN " |
| 1063 "(SELECT id FROM server_addresses)")); | 1068 "(SELECT id FROM server_addresses)")); |
| 1064 metadata_delete.Run(); | 1069 metadata_delete.Run(); |
| 1065 | 1070 |
| 1066 transaction.Commit(); | 1071 transaction.Commit(); |
| 1067 } | 1072 } |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 "DELETE FROM server_address_metadata WHERE id = ?")); | 1408 "DELETE FROM server_address_metadata WHERE id = ?")); |
| 1404 remove.BindString(0, profile.server_id()); | 1409 remove.BindString(0, profile.server_id()); |
| 1405 remove.Run(); | 1410 remove.Run(); |
| 1406 | 1411 |
| 1407 sql::Statement s( | 1412 sql::Statement s( |
| 1408 db_->GetUniqueStatement("INSERT INTO server_address_metadata(use_count, " | 1413 db_->GetUniqueStatement("INSERT INTO server_address_metadata(use_count, " |
| 1409 "use_date, has_converted, id)" | 1414 "use_date, has_converted, id)" |
| 1410 "VALUES (?,?,?,?)")); | 1415 "VALUES (?,?,?,?)")); |
| 1411 s.BindInt64(0, profile.use_count()); | 1416 s.BindInt64(0, profile.use_count()); |
| 1412 s.BindInt64(1, profile.use_date().ToInternalValue()); | 1417 s.BindInt64(1, profile.use_date().ToInternalValue()); |
| 1413 s.BindBool(2, false); | 1418 s.BindBool(2, profile.has_converted()); |
| 1414 s.BindString(3, profile.server_id()); | 1419 s.BindString(3, profile.server_id()); |
| 1415 s.Run(); | 1420 s.Run(); |
| 1416 | 1421 |
| 1417 transaction.Commit(); | 1422 transaction.Commit(); |
| 1418 | 1423 |
| 1419 return db_->GetLastChangeCount() > 0; | 1424 return db_->GetLastChangeCount() > 0; |
| 1420 } | 1425 } |
| 1421 | 1426 |
| 1422 bool AutofillTable::ClearAllServerData() { | 1427 bool AutofillTable::ClearAllServerData() { |
| 1423 sql::Transaction transaction(db_); | 1428 sql::Transaction transaction(db_); |
| (...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2521 if (!db_->Execute("DROP TABLE masked_credit_cards") || | 2526 if (!db_->Execute("DROP TABLE masked_credit_cards") || |
| 2522 !db_->Execute("ALTER TABLE masked_credit_cards_temp " | 2527 !db_->Execute("ALTER TABLE masked_credit_cards_temp " |
| 2523 "RENAME TO masked_credit_cards")) { | 2528 "RENAME TO masked_credit_cards")) { |
| 2524 return false; | 2529 return false; |
| 2525 } | 2530 } |
| 2526 | 2531 |
| 2527 return transaction.Commit(); | 2532 return transaction.Commit(); |
| 2528 } | 2533 } |
| 2529 | 2534 |
| 2530 } // namespace autofill | 2535 } // namespace autofill |
| OLD | NEW |