Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: components/autofill/core/browser/webdata/autofill_table.cc

Issue 2658843004: [Autofill] Convert wallet addresses to local autofill profiles. (Closed)
Patch Set: Change how to get server cards Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 942
943 return s.Succeeded(); 943 return s.Succeeded();
944 } 944 }
945 945
946 bool AutofillTable::GetServerProfiles( 946 bool AutofillTable::GetServerProfiles(
947 std::vector<std::unique_ptr<AutofillProfile>>* profiles) const { 947 std::vector<std::unique_ptr<AutofillProfile>>* profiles) const {
948 profiles->clear(); 948 profiles->clear();
949 949
950 sql::Statement s(db_->GetUniqueStatement( 950 sql::Statement s(db_->GetUniqueStatement(
951 "SELECT " 951 "SELECT "
952 "id," 952 "id,"
953 "use_count," 953 "use_count,"
954 "use_date," 954 "use_date,"
955 "recipient_name," 955 "recipient_name,"
956 "company_name," 956 "company_name,"
957 "street_address," 957 "street_address,"
958 "address_1," // ADDRESS_HOME_STATE 958 "address_1," // ADDRESS_HOME_STATE
959 "address_2," // ADDRESS_HOME_CITY 959 "address_2," // ADDRESS_HOME_CITY
960 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY 960 "address_3," // ADDRESS_HOME_DEPENDENT_LOCALITY
961 "address_4," // Not supported in AutofillProfile yet. 961 "address_4," // Not supported in AutofillProfile yet.
962 "postal_code," // ADDRESS_HOME_ZIP 962 "postal_code," // ADDRESS_HOME_ZIP
963 "sorting_code," // ADDRESS_HOME_SORTING_CODE 963 "sorting_code," // ADDRESS_HOME_SORTING_CODE
964 "country_code," // ADDRESS_HOME_COUNTRY 964 "country_code," // ADDRESS_HOME_COUNTRY
965 "phone_number," // PHONE_HOME_WHOLE_NUMBER 965 "phone_number," // PHONE_HOME_WHOLE_NUMBER
966 "language_code " 966 "language_code, "
967 "has_converted "
967 "FROM server_addresses addresses " 968 "FROM server_addresses addresses "
968 "LEFT OUTER JOIN server_address_metadata USING (id)")); 969 "LEFT OUTER JOIN server_address_metadata USING (id)"));
969 970
970 while (s.Step()) { 971 while (s.Step()) {
971 int index = 0; 972 int index = 0;
972 std::unique_ptr<AutofillProfile> profile = 973 std::unique_ptr<AutofillProfile> profile =
973 base::MakeUnique<AutofillProfile>(AutofillProfile::SERVER_PROFILE, 974 base::MakeUnique<AutofillProfile>(AutofillProfile::SERVER_PROFILE,
974 s.ColumnString(index++)); 975 s.ColumnString(index++));
975 profile->set_use_count(s.ColumnInt64(index++)); 976 profile->set_use_count(s.ColumnInt64(index++));
976 profile->set_use_date(Time::FromInternalValue(s.ColumnInt64(index++))); 977 profile->set_use_date(Time::FromInternalValue(s.ColumnInt64(index++)));
977 // Modification date is not tracked for server profiles. Explicitly set it 978 // Modification date is not tracked for server profiles. Explicitly set it
978 // here to override the default value of AutofillClock::Now(). 979 // here to override the default value of AutofillClock::Now().
979 profile->set_modification_date(Time()); 980 profile->set_modification_date(Time());
980 981
981 base::string16 recipient_name = s.ColumnString16(index++); 982 base::string16 recipient_name = s.ColumnString16(index++);
982 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++)); 983 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(index++));
983 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++)); 984 profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, s.ColumnString16(index++));
984 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++)); 985 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(index++));
985 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++)); 986 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(index++));
986 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, 987 profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY,
987 s.ColumnString16(index++)); 988 s.ColumnString16(index++));
988 index++; // Skip address_4 which we haven't added to AutofillProfile yet. 989 index++; // Skip address_4 which we haven't added to AutofillProfile yet.
989 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); 990 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++));
990 profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++)); 991 profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++));
991 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); 992 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++));
992 base::string16 phone_number = s.ColumnString16(index++); 993 base::string16 phone_number = s.ColumnString16(index++);
993 profile->set_language_code(s.ColumnString(index++)); 994 profile->set_language_code(s.ColumnString(index++));
995 profile->set_has_converted(s.ColumnBool(index++));
994 996
995 // SetInfo instead of SetRawInfo so the constituent pieces will be parsed 997 // SetInfo instead of SetRawInfo so the constituent pieces will be parsed
996 // for these data types. 998 // for these data types.
997 profile->SetInfo(AutofillType(NAME_FULL), recipient_name, 999 profile->SetInfo(AutofillType(NAME_FULL), recipient_name,
998 profile->language_code()); 1000 profile->language_code());
999 profile->SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), phone_number, 1001 profile->SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), phone_number,
1000 profile->language_code()); 1002 profile->language_code());
1001 1003
1002 profiles->push_back(std::move(profile)); 1004 profiles->push_back(std::move(profile));
1003 } 1005 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)); 1049 profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY));
1048 index++; // SKip address_4 which we haven't added to AutofillProfile yet. 1050 index++; // SKip address_4 which we haven't added to AutofillProfile yet.
1049 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_ZIP)); 1051 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_ZIP));
1050 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)); 1052 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE));
1051 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_COUNTRY)); 1053 insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_COUNTRY));
1052 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 1054 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
1053 insert.BindString(index++, profile.language_code()); 1055 insert.BindString(index++, profile.language_code());
1054 1056
1055 insert.Run(); 1057 insert.Run();
1056 insert.Reset(true); 1058 insert.Reset(true);
1059
1060 // Save the use count and use date of the profile.
1061 UpdateServerAddressMetadata(profile);
1057 } 1062 }
1058 1063
1059 // Delete metadata that's no longer relevant. 1064 // Delete metadata that's no longer relevant.
1060 sql::Statement metadata_delete(db_->GetUniqueStatement( 1065 sql::Statement metadata_delete(db_->GetUniqueStatement(
1061 "DELETE FROM server_address_metadata WHERE id NOT IN " 1066 "DELETE FROM server_address_metadata WHERE id NOT IN "
1062 "(SELECT id FROM server_addresses)")); 1067 "(SELECT id FROM server_addresses)"));
1063 metadata_delete.Run(); 1068 metadata_delete.Run();
1064 1069
1065 transaction.Commit(); 1070 transaction.Commit();
1066 } 1071 }
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698