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

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

Issue 13697002: Make autofill's Address store country using the country code so that app locale isn't needed for th… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
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 "components/webdata/autofill/autofill_table.h" 5 #include "components/webdata/autofill/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>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/guid.h" 14 #include "base/guid.h"
15 #include "base/i18n/case_conversion.h" 15 #include "base/i18n/case_conversion.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 #include "base/tuple.h" 19 #include "base/tuple.h"
20 #include "base/utf_string_conversions.h"
20 #include "components/autofill/browser/autofill_country.h" 21 #include "components/autofill/browser/autofill_country.h"
21 #include "components/autofill/browser/autofill_profile.h" 22 #include "components/autofill/browser/autofill_profile.h"
22 #include "components/autofill/browser/autofill_type.h" 23 #include "components/autofill/browser/autofill_type.h"
23 #include "components/autofill/browser/credit_card.h" 24 #include "components/autofill/browser/credit_card.h"
24 #include "components/autofill/browser/personal_data_manager.h" 25 #include "components/autofill/browser/personal_data_manager.h"
25 #include "components/autofill/common/form_field_data.h" 26 #include "components/autofill/common/form_field_data.h"
26 #include "components/webdata/autofill/autofill_change.h" 27 #include "components/webdata/autofill/autofill_change.h"
27 #include "components/webdata/autofill/autofill_entry.h" 28 #include "components/webdata/autofill/autofill_entry.h"
28 #include "components/webdata/common/web_database.h" 29 #include "components/webdata/common/web_database.h"
29 #include "components/webdata/encryptor/encryptor.h" 30 #include "components/webdata/encryptor/encryptor.h"
(...skipping 14 matching lines...) Expand all
44 } 45 }
45 46
46 string16 LimitDataSize(const string16& data) { 47 string16 LimitDataSize(const string16& data) {
47 if (data.size() > AutofillTable::kMaxDataLength) 48 if (data.size() > AutofillTable::kMaxDataLength)
48 return data.substr(0, AutofillTable::kMaxDataLength); 49 return data.substr(0, AutofillTable::kMaxDataLength);
49 50
50 return data; 51 return data;
51 } 52 }
52 53
53 void BindAutofillProfileToStatement(const AutofillProfile& profile, 54 void BindAutofillProfileToStatement(const AutofillProfile& profile,
54 sql::Statement* s) { 55 sql::Statement* s,
56 const std::string& app_locale) {
55 DCHECK(base::IsValidGUID(profile.guid())); 57 DCHECK(base::IsValidGUID(profile.guid()));
56 s->BindString(0, profile.guid()); 58 s->BindString(0, profile.guid());
57 59
58 string16 text = profile.GetRawInfo(COMPANY_NAME); 60 string16 text = profile.GetRawInfo(COMPANY_NAME);
59 s->BindString16(1, LimitDataSize(text)); 61 s->BindString16(1, LimitDataSize(text));
60 text = profile.GetRawInfo(ADDRESS_HOME_LINE1); 62 text = profile.GetRawInfo(ADDRESS_HOME_LINE1);
61 s->BindString16(2, LimitDataSize(text)); 63 s->BindString16(2, LimitDataSize(text));
62 text = profile.GetRawInfo(ADDRESS_HOME_LINE2); 64 text = profile.GetRawInfo(ADDRESS_HOME_LINE2);
63 s->BindString16(3, LimitDataSize(text)); 65 s->BindString16(3, LimitDataSize(text));
64 text = profile.GetRawInfo(ADDRESS_HOME_CITY); 66 text = profile.GetRawInfo(ADDRESS_HOME_CITY);
65 s->BindString16(4, LimitDataSize(text)); 67 s->BindString16(4, LimitDataSize(text));
66 text = profile.GetRawInfo(ADDRESS_HOME_STATE); 68 text = profile.GetRawInfo(ADDRESS_HOME_STATE);
67 s->BindString16(5, LimitDataSize(text)); 69 s->BindString16(5, LimitDataSize(text));
68 text = profile.GetRawInfo(ADDRESS_HOME_ZIP); 70 text = profile.GetRawInfo(ADDRESS_HOME_ZIP);
69 s->BindString16(6, LimitDataSize(text)); 71 s->BindString16(6, LimitDataSize(text));
72 text = profile.GetInfo(ADDRESS_HOME_COUNTRY, app_locale);
73 s->BindString16(7, LimitDataSize(text));
70 text = profile.GetRawInfo(ADDRESS_HOME_COUNTRY); 74 text = profile.GetRawInfo(ADDRESS_HOME_COUNTRY);
71 s->BindString16(7, LimitDataSize(text)); 75 s->BindString16(8, LimitDataSize(text));
72 std::string country_code = profile.CountryCode();
73 s->BindString(8, country_code);
74 s->BindInt64(9, Time::Now().ToTimeT()); 76 s->BindInt64(9, Time::Now().ToTimeT());
75 } 77 }
76 78
77 AutofillProfile* AutofillProfileFromStatement(const sql::Statement& s) { 79 AutofillProfile* AutofillProfileFromStatement(const sql::Statement& s,
80 const std::string& app_locale) {
78 AutofillProfile* profile = new AutofillProfile; 81 AutofillProfile* profile = new AutofillProfile;
79 profile->set_guid(s.ColumnString(0)); 82 profile->set_guid(s.ColumnString(0));
80 DCHECK(base::IsValidGUID(profile->guid())); 83 DCHECK(base::IsValidGUID(profile->guid()));
81 84
82 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(1)); 85 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(1));
83 profile->SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); 86 profile->SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2));
84 profile->SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); 87 profile->SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3));
85 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); 88 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(4));
86 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); 89 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(5));
87 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); 90 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6));
88 // Intentionally skip column 7, which stores the localized country name. 91 // Intentionally skip column 7, which stores the localized country name.
89 profile->SetCountryCode(s.ColumnString(8)); 92 string16 country_code = s.ColumnString16(8);
93 if (country_code.empty()) {
94 // Old versions put the localized country name in column 7.
jam 2013/04/05 02:27:26 This is the first time I look at the webdata code.
Ilya Sherman 2013/04/05 05:18:01 We should be able to just keep this code as it was
jam 2013/04/05 06:45:54 Done.
95 country_code = ASCIIToUTF16(AutofillCountry::GetCountryCode(
96 s.ColumnString16(7), app_locale));
97 }
98 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, country_code);
90 // Intentionally skip column 9, which stores the profile's modification date. 99 // Intentionally skip column 9, which stores the profile's modification date.
91 100
92 return profile; 101 return profile;
93 } 102 }
94 103
95 void BindCreditCardToStatement(const CreditCard& credit_card, 104 void BindCreditCardToStatement(const CreditCard& credit_card,
96 sql::Statement* s) { 105 sql::Statement* s) {
97 DCHECK(base::IsValidGUID(credit_card.guid())); 106 DCHECK(base::IsValidGUID(credit_card.guid()));
98 s->BindString(0, credit_card.guid()); 107 s->BindString(0, credit_card.guid());
99 108
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 935
927 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { 936 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) {
928 if (IsAutofillGUIDInTrash(profile.guid())) 937 if (IsAutofillGUIDInTrash(profile.guid()))
929 return true; 938 return true;
930 939
931 sql::Statement s(db_->GetUniqueStatement( 940 sql::Statement s(db_->GetUniqueStatement(
932 "INSERT INTO autofill_profiles" 941 "INSERT INTO autofill_profiles"
933 "(guid, company_name, address_line_1, address_line_2, city, state," 942 "(guid, company_name, address_line_1, address_line_2, city, state,"
934 " zipcode, country, country_code, date_modified)" 943 " zipcode, country, country_code, date_modified)"
935 "VALUES (?,?,?,?,?,?,?,?,?,?)")); 944 "VALUES (?,?,?,?,?,?,?,?,?,?)"));
936 BindAutofillProfileToStatement(profile, &s); 945 BindAutofillProfileToStatement(profile, &s, app_locale_);
937 946
938 if (!s.Run()) 947 if (!s.Run())
939 return false; 948 return false;
940 949
941 return AddAutofillProfilePieces(profile, db_); 950 return AddAutofillProfilePieces(profile, db_);
942 } 951 }
943 952
944 bool AutofillTable::GetAutofillProfile(const std::string& guid, 953 bool AutofillTable::GetAutofillProfile(const std::string& guid,
945 AutofillProfile** profile) { 954 AutofillProfile** profile) {
946 DCHECK(base::IsValidGUID(guid)); 955 DCHECK(base::IsValidGUID(guid));
947 DCHECK(profile); 956 DCHECK(profile);
948 sql::Statement s(db_->GetUniqueStatement( 957 sql::Statement s(db_->GetUniqueStatement(
949 "SELECT guid, company_name, address_line_1, address_line_2, city, state," 958 "SELECT guid, company_name, address_line_1, address_line_2, city, state,"
950 " zipcode, country, country_code, date_modified " 959 " zipcode, country, country_code, date_modified "
951 "FROM autofill_profiles " 960 "FROM autofill_profiles "
952 "WHERE guid=?")); 961 "WHERE guid=?"));
953 s.BindString(0, guid); 962 s.BindString(0, guid);
954 963
955 if (!s.Step()) 964 if (!s.Step())
956 return false; 965 return false;
957 966
958 scoped_ptr<AutofillProfile> p(AutofillProfileFromStatement(s)); 967 scoped_ptr<AutofillProfile> p(AutofillProfileFromStatement(s, app_locale_));
959 968
960 // Get associated name info. 969 // Get associated name info.
961 AddAutofillProfileNamesToProfile(db_, p.get()); 970 AddAutofillProfileNamesToProfile(db_, p.get());
962 971
963 // Get associated email info. 972 // Get associated email info.
964 AddAutofillProfileEmailsToProfile(db_, p.get()); 973 AddAutofillProfileEmailsToProfile(db_, p.get());
965 974
966 // Get associated phone info. 975 // Get associated phone info.
967 AddAutofillProfilePhonesToProfile(db_, p.get()); 976 AddAutofillProfilePhonesToProfile(db_, p.get());
968 977
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 scoped_ptr<AutofillProfile> old_profile(tmp_profile); 1050 scoped_ptr<AutofillProfile> old_profile(tmp_profile);
1042 if (old_profile->Compare(profile) == 0) 1051 if (old_profile->Compare(profile) == 0)
1043 return true; 1052 return true;
1044 1053
1045 sql::Statement s(db_->GetUniqueStatement( 1054 sql::Statement s(db_->GetUniqueStatement(
1046 "UPDATE autofill_profiles " 1055 "UPDATE autofill_profiles "
1047 "SET guid=?, company_name=?, address_line_1=?, address_line_2=?, " 1056 "SET guid=?, company_name=?, address_line_1=?, address_line_2=?, "
1048 " city=?, state=?, zipcode=?, country=?, country_code=?, " 1057 " city=?, state=?, zipcode=?, country=?, country_code=?, "
1049 " date_modified=? " 1058 " date_modified=? "
1050 "WHERE guid=?")); 1059 "WHERE guid=?"));
1051 BindAutofillProfileToStatement(profile, &s); 1060 BindAutofillProfileToStatement(profile, &s, app_locale_);
1052 s.BindString(10, profile.guid()); 1061 s.BindString(10, profile.guid());
1053 1062
1054 bool result = s.Run(); 1063 bool result = s.Run();
1055 DCHECK_GT(db_->GetLastChangeCount(), 0); 1064 DCHECK_GT(db_->GetLastChangeCount(), 0);
1056 if (!result) 1065 if (!result)
1057 return result; 1066 return result;
1058 1067
1059 // Remove the old names, emails, and phone numbers. 1068 // Remove the old names, emails, and phone numbers.
1060 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) 1069 if (!RemoveAutofillProfilePieces(profile.guid(), db_))
1061 return false; 1070 return false;
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 "middle_name VARCHAR, " 1761 "middle_name VARCHAR, "
1753 "last_name VARCHAR, " 1762 "last_name VARCHAR, "
1754 "email VARCHAR, " 1763 "email VARCHAR, "
1755 "company_name VARCHAR, " 1764 "company_name VARCHAR, "
1756 "address_line_1 VARCHAR, " 1765 "address_line_1 VARCHAR, "
1757 "address_line_2 VARCHAR, " 1766 "address_line_2 VARCHAR, "
1758 "city VARCHAR, " 1767 "city VARCHAR, "
1759 "state VARCHAR, " 1768 "state VARCHAR, "
1760 "zipcode VARCHAR, " 1769 "zipcode VARCHAR, "
1761 "country VARCHAR, " 1770 "country VARCHAR, "
1771 "country_code VARCHAR, "
Ilya Sherman 2013/04/05 05:18:01 You shouldn't change this migration code. The sem
jam 2013/04/05 06:45:54 Done.
1762 "phone VARCHAR, " 1772 "phone VARCHAR, "
1763 "date_modified INTEGER NOT NULL DEFAULT 0)")) { 1773 "date_modified INTEGER NOT NULL DEFAULT 0)")) {
1764 return false; 1774 return false;
1765 } 1775 }
1766 1776
1767 if (!db_->Execute( 1777 if (!db_->Execute(
1768 "INSERT INTO autofill_profiles_temp " 1778 "INSERT INTO autofill_profiles_temp "
1769 "SELECT guid, label, first_name, middle_name, last_name, email, " 1779 "SELECT guid, label, first_name, middle_name, last_name, email, "
1770 "company_name, address_line_1, address_line_2, city, state, " 1780 "company_name, address_line_1, address_line_2, city, state, "
1771 "zipcode, country, phone, date_modified " 1781 "zipcode, country, country, phone, date_modified "
Ilya Sherman 2013/04/05 05:18:01 Ditto.
jam 2013/04/05 06:45:54 Done.
1772 "FROM autofill_profiles")) { 1782 "FROM autofill_profiles")) {
1773 return false; 1783 return false;
1774 } 1784 }
1775 1785
1776 if (!db_->Execute("DROP TABLE autofill_profiles")) 1786 if (!db_->Execute("DROP TABLE autofill_profiles"))
1777 return false; 1787 return false;
1778 1788
1779 if (!db_->Execute( 1789 if (!db_->Execute(
1780 "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) { 1790 "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) {
1781 return false; 1791 return false;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 if (!db_->DoesTableExist("autofill_profiles_temp")) { 1832 if (!db_->DoesTableExist("autofill_profiles_temp")) {
1823 if (!db_->Execute("CREATE TABLE autofill_profiles_temp ( " 1833 if (!db_->Execute("CREATE TABLE autofill_profiles_temp ( "
1824 "guid VARCHAR PRIMARY KEY, " 1834 "guid VARCHAR PRIMARY KEY, "
1825 "company_name VARCHAR, " 1835 "company_name VARCHAR, "
1826 "address_line_1 VARCHAR, " 1836 "address_line_1 VARCHAR, "
1827 "address_line_2 VARCHAR, " 1837 "address_line_2 VARCHAR, "
1828 "city VARCHAR, " 1838 "city VARCHAR, "
1829 "state VARCHAR, " 1839 "state VARCHAR, "
1830 "zipcode VARCHAR, " 1840 "zipcode VARCHAR, "
1831 "country VARCHAR, " 1841 "country VARCHAR, "
1842 "country_code VARCHAR, "
Ilya Sherman 2013/04/05 05:18:01 Ditto.
jam 2013/04/05 06:45:54 Done.
1832 "date_modified INTEGER NOT NULL DEFAULT 0)")) { 1843 "date_modified INTEGER NOT NULL DEFAULT 0)")) {
1833 return false; 1844 return false;
1834 } 1845 }
1835 } 1846 }
1836 1847
1837 sql::Statement s(db_->GetUniqueStatement( 1848 sql::Statement s(db_->GetUniqueStatement(
1838 "SELECT guid, first_name, middle_name, last_name, email, " 1849 "SELECT guid, first_name, middle_name, last_name, email, "
1839 "company_name, address_line_1, address_line_2, city, state, " 1850 "company_name, address_line_1, address_line_2, city, state, "
1840 "zipcode, country, phone, date_modified " 1851 "zipcode, country, phone, date_modified "
1841 "FROM autofill_profiles")); 1852 "FROM autofill_profiles"));
1842 1853
1843 while (s.Step()) { 1854 while (s.Step()) {
1844 AutofillProfile profile; 1855 AutofillProfile profile;
1845 profile.set_guid(s.ColumnString(0)); 1856 profile.set_guid(s.ColumnString(0));
1846 DCHECK(base::IsValidGUID(profile.guid())); 1857 DCHECK(base::IsValidGUID(profile.guid()));
1847 1858
1848 profile.SetRawInfo(NAME_FIRST, s.ColumnString16(1)); 1859 profile.SetRawInfo(NAME_FIRST, s.ColumnString16(1));
1849 profile.SetRawInfo(NAME_MIDDLE, s.ColumnString16(2)); 1860 profile.SetRawInfo(NAME_MIDDLE, s.ColumnString16(2));
1850 profile.SetRawInfo(NAME_LAST, s.ColumnString16(3)); 1861 profile.SetRawInfo(NAME_LAST, s.ColumnString16(3));
1851 profile.SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(4)); 1862 profile.SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(4));
1852 profile.SetRawInfo(COMPANY_NAME, s.ColumnString16(5)); 1863 profile.SetRawInfo(COMPANY_NAME, s.ColumnString16(5));
1853 profile.SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); 1864 profile.SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6));
1854 profile.SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); 1865 profile.SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7));
1855 profile.SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); 1866 profile.SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(8));
1856 profile.SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); 1867 profile.SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(9));
1857 profile.SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); 1868 profile.SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10));
1858 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); 1869 std::string country_code =
1870 AutofillCountry::GetCountryCode(s.ColumnString16(11), app_locale_);
1871 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16(country_code));
Ilya Sherman 2013/04/05 05:18:01 Please call SetInfo() here instead.
jam 2013/04/05 06:45:54 Done.
1859 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); 1872 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12));
1860 int64 date_modified = s.ColumnInt64(13); 1873 int64 date_modified = s.ColumnInt64(13);
1861 1874
1862 sql::Statement s_insert(db_->GetUniqueStatement( 1875 sql::Statement s_insert(db_->GetUniqueStatement(
1863 "INSERT INTO autofill_profiles_temp" 1876 "INSERT INTO autofill_profiles_temp"
1864 "(guid, company_name, address_line_1, address_line_2, city," 1877 "(guid, company_name, address_line_1, address_line_2, city,"
1865 " state, zipcode, country, date_modified)" 1878 " state, zipcode, country, date_modified)"
1866 "VALUES (?,?,?,?,?,?,?,?,?)")); 1879 "VALUES (?,?,?,?,?,?,?,?,?)"));
1867 s_insert.BindString(0, profile.guid()); 1880 s_insert.BindString(0, profile.guid());
1868 s_insert.BindString16(1, profile.GetRawInfo(COMPANY_NAME)); 1881 s_insert.BindString16(1, profile.GetRawInfo(COMPANY_NAME));
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 "WHERE guid=?")); 2051 "WHERE guid=?"));
2039 s_date.BindInt64(0, date_item->second); 2052 s_date.BindInt64(0, date_item->second);
2040 s_date.BindString(1, iter->guid()); 2053 s_date.BindString(1, iter->guid());
2041 2054
2042 if (!s_date.Run()) 2055 if (!s_date.Run())
2043 return false; 2056 return false;
2044 } 2057 }
2045 2058
2046 return true; 2059 return true;
2047 } 2060 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698