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 "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> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } | 44 } |
45 | 45 |
46 string16 LimitDataSize(const string16& data) { | 46 string16 LimitDataSize(const string16& data) { |
47 if (data.size() > AutofillTable::kMaxDataLength) | 47 if (data.size() > AutofillTable::kMaxDataLength) |
48 return data.substr(0, AutofillTable::kMaxDataLength); | 48 return data.substr(0, AutofillTable::kMaxDataLength); |
49 | 49 |
50 return data; | 50 return data; |
51 } | 51 } |
52 | 52 |
53 void BindAutofillProfileToStatement(const AutofillProfile& profile, | 53 void BindAutofillProfileToStatement(const AutofillProfile& profile, |
54 sql::Statement* s) { | 54 sql::Statement* s, |
| 55 const std::string& app_locale) { |
55 DCHECK(base::IsValidGUID(profile.guid())); | 56 DCHECK(base::IsValidGUID(profile.guid())); |
56 s->BindString(0, profile.guid()); | 57 s->BindString(0, profile.guid()); |
57 | 58 |
58 string16 text = profile.GetRawInfo(COMPANY_NAME); | 59 string16 text = profile.GetRawInfo(COMPANY_NAME); |
59 s->BindString16(1, LimitDataSize(text)); | 60 s->BindString16(1, LimitDataSize(text)); |
60 text = profile.GetRawInfo(ADDRESS_HOME_LINE1); | 61 text = profile.GetRawInfo(ADDRESS_HOME_LINE1); |
61 s->BindString16(2, LimitDataSize(text)); | 62 s->BindString16(2, LimitDataSize(text)); |
62 text = profile.GetRawInfo(ADDRESS_HOME_LINE2); | 63 text = profile.GetRawInfo(ADDRESS_HOME_LINE2); |
63 s->BindString16(3, LimitDataSize(text)); | 64 s->BindString16(3, LimitDataSize(text)); |
64 text = profile.GetRawInfo(ADDRESS_HOME_CITY); | 65 text = profile.GetRawInfo(ADDRESS_HOME_CITY); |
65 s->BindString16(4, LimitDataSize(text)); | 66 s->BindString16(4, LimitDataSize(text)); |
66 text = profile.GetRawInfo(ADDRESS_HOME_STATE); | 67 text = profile.GetRawInfo(ADDRESS_HOME_STATE); |
67 s->BindString16(5, LimitDataSize(text)); | 68 s->BindString16(5, LimitDataSize(text)); |
68 text = profile.GetRawInfo(ADDRESS_HOME_ZIP); | 69 text = profile.GetRawInfo(ADDRESS_HOME_ZIP); |
69 s->BindString16(6, LimitDataSize(text)); | 70 s->BindString16(6, LimitDataSize(text)); |
| 71 text = profile.GetInfo(ADDRESS_HOME_COUNTRY, app_locale); |
| 72 s->BindString16(7, LimitDataSize(text)); |
70 text = profile.GetRawInfo(ADDRESS_HOME_COUNTRY); | 73 text = profile.GetRawInfo(ADDRESS_HOME_COUNTRY); |
71 s->BindString16(7, LimitDataSize(text)); | 74 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()); | 75 s->BindInt64(9, Time::Now().ToTimeT()); |
75 } | 76 } |
76 | 77 |
77 AutofillProfile* AutofillProfileFromStatement(const sql::Statement& s) { | 78 AutofillProfile* AutofillProfileFromStatement(const sql::Statement& s, |
| 79 const std::string& app_locale) { |
78 AutofillProfile* profile = new AutofillProfile; | 80 AutofillProfile* profile = new AutofillProfile; |
79 profile->set_guid(s.ColumnString(0)); | 81 profile->set_guid(s.ColumnString(0)); |
80 DCHECK(base::IsValidGUID(profile->guid())); | 82 DCHECK(base::IsValidGUID(profile->guid())); |
81 | 83 |
82 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(1)); | 84 profile->SetRawInfo(COMPANY_NAME, s.ColumnString16(1)); |
83 profile->SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); | 85 profile->SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(2)); |
84 profile->SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); | 86 profile->SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(3)); |
85 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); | 87 profile->SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(4)); |
86 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); | 88 profile->SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(5)); |
87 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); | 89 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(6)); |
88 // Intentionally skip column 7, which stores the localized country name. | 90 // Intentionally skip column 7, which stores the localized country name. |
89 profile->SetCountryCode(s.ColumnString(8)); | 91 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(8)); |
90 // Intentionally skip column 9, which stores the profile's modification date. | 92 // Intentionally skip column 9, which stores the profile's modification date. |
91 | 93 |
92 return profile; | 94 return profile; |
93 } | 95 } |
94 | 96 |
95 void BindCreditCardToStatement(const CreditCard& credit_card, | 97 void BindCreditCardToStatement(const CreditCard& credit_card, |
96 sql::Statement* s) { | 98 sql::Statement* s) { |
97 DCHECK(base::IsValidGUID(credit_card.guid())); | 99 DCHECK(base::IsValidGUID(credit_card.guid())); |
98 s->BindString(0, credit_card.guid()); | 100 s->BindString(0, credit_card.guid()); |
99 | 101 |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 | 928 |
927 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { | 929 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { |
928 if (IsAutofillGUIDInTrash(profile.guid())) | 930 if (IsAutofillGUIDInTrash(profile.guid())) |
929 return true; | 931 return true; |
930 | 932 |
931 sql::Statement s(db_->GetUniqueStatement( | 933 sql::Statement s(db_->GetUniqueStatement( |
932 "INSERT INTO autofill_profiles" | 934 "INSERT INTO autofill_profiles" |
933 "(guid, company_name, address_line_1, address_line_2, city, state," | 935 "(guid, company_name, address_line_1, address_line_2, city, state," |
934 " zipcode, country, country_code, date_modified)" | 936 " zipcode, country, country_code, date_modified)" |
935 "VALUES (?,?,?,?,?,?,?,?,?,?)")); | 937 "VALUES (?,?,?,?,?,?,?,?,?,?)")); |
936 BindAutofillProfileToStatement(profile, &s); | 938 BindAutofillProfileToStatement(profile, &s, app_locale_); |
937 | 939 |
938 if (!s.Run()) | 940 if (!s.Run()) |
939 return false; | 941 return false; |
940 | 942 |
941 return AddAutofillProfilePieces(profile, db_); | 943 return AddAutofillProfilePieces(profile, db_); |
942 } | 944 } |
943 | 945 |
944 bool AutofillTable::GetAutofillProfile(const std::string& guid, | 946 bool AutofillTable::GetAutofillProfile(const std::string& guid, |
945 AutofillProfile** profile) { | 947 AutofillProfile** profile) { |
946 DCHECK(base::IsValidGUID(guid)); | 948 DCHECK(base::IsValidGUID(guid)); |
947 DCHECK(profile); | 949 DCHECK(profile); |
948 sql::Statement s(db_->GetUniqueStatement( | 950 sql::Statement s(db_->GetUniqueStatement( |
949 "SELECT guid, company_name, address_line_1, address_line_2, city, state," | 951 "SELECT guid, company_name, address_line_1, address_line_2, city, state," |
950 " zipcode, country, country_code, date_modified " | 952 " zipcode, country, country_code, date_modified " |
951 "FROM autofill_profiles " | 953 "FROM autofill_profiles " |
952 "WHERE guid=?")); | 954 "WHERE guid=?")); |
953 s.BindString(0, guid); | 955 s.BindString(0, guid); |
954 | 956 |
955 if (!s.Step()) | 957 if (!s.Step()) |
956 return false; | 958 return false; |
957 | 959 |
958 scoped_ptr<AutofillProfile> p(AutofillProfileFromStatement(s)); | 960 scoped_ptr<AutofillProfile> p(AutofillProfileFromStatement(s, app_locale_)); |
959 | 961 |
960 // Get associated name info. | 962 // Get associated name info. |
961 AddAutofillProfileNamesToProfile(db_, p.get()); | 963 AddAutofillProfileNamesToProfile(db_, p.get()); |
962 | 964 |
963 // Get associated email info. | 965 // Get associated email info. |
964 AddAutofillProfileEmailsToProfile(db_, p.get()); | 966 AddAutofillProfileEmailsToProfile(db_, p.get()); |
965 | 967 |
966 // Get associated phone info. | 968 // Get associated phone info. |
967 AddAutofillProfilePhonesToProfile(db_, p.get()); | 969 AddAutofillProfilePhonesToProfile(db_, p.get()); |
968 | 970 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 scoped_ptr<AutofillProfile> old_profile(tmp_profile); | 1043 scoped_ptr<AutofillProfile> old_profile(tmp_profile); |
1042 if (old_profile->Compare(profile) == 0) | 1044 if (old_profile->Compare(profile) == 0) |
1043 return true; | 1045 return true; |
1044 | 1046 |
1045 sql::Statement s(db_->GetUniqueStatement( | 1047 sql::Statement s(db_->GetUniqueStatement( |
1046 "UPDATE autofill_profiles " | 1048 "UPDATE autofill_profiles " |
1047 "SET guid=?, company_name=?, address_line_1=?, address_line_2=?, " | 1049 "SET guid=?, company_name=?, address_line_1=?, address_line_2=?, " |
1048 " city=?, state=?, zipcode=?, country=?, country_code=?, " | 1050 " city=?, state=?, zipcode=?, country=?, country_code=?, " |
1049 " date_modified=? " | 1051 " date_modified=? " |
1050 "WHERE guid=?")); | 1052 "WHERE guid=?")); |
1051 BindAutofillProfileToStatement(profile, &s); | 1053 BindAutofillProfileToStatement(profile, &s, app_locale_); |
1052 s.BindString(10, profile.guid()); | 1054 s.BindString(10, profile.guid()); |
1053 | 1055 |
1054 bool result = s.Run(); | 1056 bool result = s.Run(); |
1055 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1057 DCHECK_GT(db_->GetLastChangeCount(), 0); |
1056 if (!result) | 1058 if (!result) |
1057 return result; | 1059 return result; |
1058 | 1060 |
1059 // Remove the old names, emails, and phone numbers. | 1061 // Remove the old names, emails, and phone numbers. |
1060 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) | 1062 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) |
1061 return false; | 1063 return false; |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1848 profile.SetRawInfo(NAME_FIRST, s.ColumnString16(1)); | 1850 profile.SetRawInfo(NAME_FIRST, s.ColumnString16(1)); |
1849 profile.SetRawInfo(NAME_MIDDLE, s.ColumnString16(2)); | 1851 profile.SetRawInfo(NAME_MIDDLE, s.ColumnString16(2)); |
1850 profile.SetRawInfo(NAME_LAST, s.ColumnString16(3)); | 1852 profile.SetRawInfo(NAME_LAST, s.ColumnString16(3)); |
1851 profile.SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(4)); | 1853 profile.SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(4)); |
1852 profile.SetRawInfo(COMPANY_NAME, s.ColumnString16(5)); | 1854 profile.SetRawInfo(COMPANY_NAME, s.ColumnString16(5)); |
1853 profile.SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); | 1855 profile.SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); |
1854 profile.SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); | 1856 profile.SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); |
1855 profile.SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); | 1857 profile.SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); |
1856 profile.SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); | 1858 profile.SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); |
1857 profile.SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); | 1859 profile.SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); |
1858 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); | 1860 profile.SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11), app_locale_); |
1859 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); | 1861 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); |
1860 int64 date_modified = s.ColumnInt64(13); | 1862 int64 date_modified = s.ColumnInt64(13); |
1861 | 1863 |
1862 sql::Statement s_insert(db_->GetUniqueStatement( | 1864 sql::Statement s_insert(db_->GetUniqueStatement( |
1863 "INSERT INTO autofill_profiles_temp" | 1865 "INSERT INTO autofill_profiles_temp" |
1864 "(guid, company_name, address_line_1, address_line_2, city," | 1866 "(guid, company_name, address_line_1, address_line_2, city," |
1865 " state, zipcode, country, date_modified)" | 1867 " state, zipcode, country, date_modified)" |
1866 "VALUES (?,?,?,?,?,?,?,?,?)")); | 1868 "VALUES (?,?,?,?,?,?,?,?,?)")); |
1867 s_insert.BindString(0, profile.guid()); | 1869 s_insert.BindString(0, profile.guid()); |
1868 s_insert.BindString16(1, profile.GetRawInfo(COMPANY_NAME)); | 1870 s_insert.BindString16(1, profile.GetRawInfo(COMPANY_NAME)); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2038 "WHERE guid=?")); | 2040 "WHERE guid=?")); |
2039 s_date.BindInt64(0, date_item->second); | 2041 s_date.BindInt64(0, date_item->second); |
2040 s_date.BindString(1, iter->guid()); | 2042 s_date.BindString(1, iter->guid()); |
2041 | 2043 |
2042 if (!s_date.Run()) | 2044 if (!s_date.Run()) |
2043 return false; | 2045 return false; |
2044 } | 2046 } |
2045 | 2047 |
2046 return true; | 2048 return true; |
2047 } | 2049 } |
OLD | NEW |