Chromium Code Reviews| 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> |
| 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" | |
|
Ilya Sherman
2013/04/05 07:18:41
nit: Not needed now?
jam
2013/04/05 07:35:35
Done.
jam
2013/04/05 07:35:35
Done.
| |
| 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 Loading... | |
| 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); |
|
Ilya Sherman
2013/04/05 07:18:41
nit: Probably no need for this expression to have
jam
2013/04/05 07:35:35
Done.
| |
| 93 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, country_code); | |
| 90 // Intentionally skip column 9, which stores the profile's modification date. | 94 // Intentionally skip column 9, which stores the profile's modification date. |
| 91 | 95 |
| 92 return profile; | 96 return profile; |
| 93 } | 97 } |
| 94 | 98 |
| 95 void BindCreditCardToStatement(const CreditCard& credit_card, | 99 void BindCreditCardToStatement(const CreditCard& credit_card, |
| 96 sql::Statement* s) { | 100 sql::Statement* s) { |
| 97 DCHECK(base::IsValidGUID(credit_card.guid())); | 101 DCHECK(base::IsValidGUID(credit_card.guid())); |
| 98 s->BindString(0, credit_card.guid()); | 102 s->BindString(0, credit_card.guid()); |
| 99 | 103 |
| (...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 926 | 930 |
| 927 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { | 931 bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { |
| 928 if (IsAutofillGUIDInTrash(profile.guid())) | 932 if (IsAutofillGUIDInTrash(profile.guid())) |
| 929 return true; | 933 return true; |
| 930 | 934 |
| 931 sql::Statement s(db_->GetUniqueStatement( | 935 sql::Statement s(db_->GetUniqueStatement( |
| 932 "INSERT INTO autofill_profiles" | 936 "INSERT INTO autofill_profiles" |
| 933 "(guid, company_name, address_line_1, address_line_2, city, state," | 937 "(guid, company_name, address_line_1, address_line_2, city, state," |
| 934 " zipcode, country, country_code, date_modified)" | 938 " zipcode, country, country_code, date_modified)" |
| 935 "VALUES (?,?,?,?,?,?,?,?,?,?)")); | 939 "VALUES (?,?,?,?,?,?,?,?,?,?)")); |
| 936 BindAutofillProfileToStatement(profile, &s); | 940 BindAutofillProfileToStatement(profile, &s, app_locale_); |
| 937 | 941 |
| 938 if (!s.Run()) | 942 if (!s.Run()) |
| 939 return false; | 943 return false; |
| 940 | 944 |
| 941 return AddAutofillProfilePieces(profile, db_); | 945 return AddAutofillProfilePieces(profile, db_); |
| 942 } | 946 } |
| 943 | 947 |
| 944 bool AutofillTable::GetAutofillProfile(const std::string& guid, | 948 bool AutofillTable::GetAutofillProfile(const std::string& guid, |
| 945 AutofillProfile** profile) { | 949 AutofillProfile** profile) { |
| 946 DCHECK(base::IsValidGUID(guid)); | 950 DCHECK(base::IsValidGUID(guid)); |
| 947 DCHECK(profile); | 951 DCHECK(profile); |
| 948 sql::Statement s(db_->GetUniqueStatement( | 952 sql::Statement s(db_->GetUniqueStatement( |
| 949 "SELECT guid, company_name, address_line_1, address_line_2, city, state," | 953 "SELECT guid, company_name, address_line_1, address_line_2, city, state," |
| 950 " zipcode, country, country_code, date_modified " | 954 " zipcode, country, country_code, date_modified " |
| 951 "FROM autofill_profiles " | 955 "FROM autofill_profiles " |
| 952 "WHERE guid=?")); | 956 "WHERE guid=?")); |
| 953 s.BindString(0, guid); | 957 s.BindString(0, guid); |
| 954 | 958 |
| 955 if (!s.Step()) | 959 if (!s.Step()) |
| 956 return false; | 960 return false; |
| 957 | 961 |
| 958 scoped_ptr<AutofillProfile> p(AutofillProfileFromStatement(s)); | 962 scoped_ptr<AutofillProfile> p(AutofillProfileFromStatement(s, app_locale_)); |
| 959 | 963 |
| 960 // Get associated name info. | 964 // Get associated name info. |
| 961 AddAutofillProfileNamesToProfile(db_, p.get()); | 965 AddAutofillProfileNamesToProfile(db_, p.get()); |
| 962 | 966 |
| 963 // Get associated email info. | 967 // Get associated email info. |
| 964 AddAutofillProfileEmailsToProfile(db_, p.get()); | 968 AddAutofillProfileEmailsToProfile(db_, p.get()); |
| 965 | 969 |
| 966 // Get associated phone info. | 970 // Get associated phone info. |
| 967 AddAutofillProfilePhonesToProfile(db_, p.get()); | 971 AddAutofillProfilePhonesToProfile(db_, p.get()); |
| 968 | 972 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1041 scoped_ptr<AutofillProfile> old_profile(tmp_profile); | 1045 scoped_ptr<AutofillProfile> old_profile(tmp_profile); |
| 1042 if (old_profile->Compare(profile) == 0) | 1046 if (old_profile->Compare(profile) == 0) |
| 1043 return true; | 1047 return true; |
| 1044 | 1048 |
| 1045 sql::Statement s(db_->GetUniqueStatement( | 1049 sql::Statement s(db_->GetUniqueStatement( |
| 1046 "UPDATE autofill_profiles " | 1050 "UPDATE autofill_profiles " |
| 1047 "SET guid=?, company_name=?, address_line_1=?, address_line_2=?, " | 1051 "SET guid=?, company_name=?, address_line_1=?, address_line_2=?, " |
| 1048 " city=?, state=?, zipcode=?, country=?, country_code=?, " | 1052 " city=?, state=?, zipcode=?, country=?, country_code=?, " |
| 1049 " date_modified=? " | 1053 " date_modified=? " |
| 1050 "WHERE guid=?")); | 1054 "WHERE guid=?")); |
| 1051 BindAutofillProfileToStatement(profile, &s); | 1055 BindAutofillProfileToStatement(profile, &s, app_locale_); |
| 1052 s.BindString(10, profile.guid()); | 1056 s.BindString(10, profile.guid()); |
| 1053 | 1057 |
| 1054 bool result = s.Run(); | 1058 bool result = s.Run(); |
| 1055 DCHECK_GT(db_->GetLastChangeCount(), 0); | 1059 DCHECK_GT(db_->GetLastChangeCount(), 0); |
| 1056 if (!result) | 1060 if (!result) |
| 1057 return result; | 1061 return result; |
| 1058 | 1062 |
| 1059 // Remove the old names, emails, and phone numbers. | 1063 // Remove the old names, emails, and phone numbers. |
| 1060 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) | 1064 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) |
| 1061 return false; | 1065 return false; |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1848 profile.SetRawInfo(NAME_FIRST, s.ColumnString16(1)); | 1852 profile.SetRawInfo(NAME_FIRST, s.ColumnString16(1)); |
| 1849 profile.SetRawInfo(NAME_MIDDLE, s.ColumnString16(2)); | 1853 profile.SetRawInfo(NAME_MIDDLE, s.ColumnString16(2)); |
| 1850 profile.SetRawInfo(NAME_LAST, s.ColumnString16(3)); | 1854 profile.SetRawInfo(NAME_LAST, s.ColumnString16(3)); |
| 1851 profile.SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(4)); | 1855 profile.SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(4)); |
| 1852 profile.SetRawInfo(COMPANY_NAME, s.ColumnString16(5)); | 1856 profile.SetRawInfo(COMPANY_NAME, s.ColumnString16(5)); |
| 1853 profile.SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); | 1857 profile.SetRawInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); |
| 1854 profile.SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); | 1858 profile.SetRawInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); |
| 1855 profile.SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); | 1859 profile.SetRawInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); |
| 1856 profile.SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); | 1860 profile.SetRawInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); |
| 1857 profile.SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); | 1861 profile.SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); |
| 1858 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); | 1862 profile.SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11), app_locale_); |
| 1859 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); | 1863 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); |
| 1860 int64 date_modified = s.ColumnInt64(13); | 1864 int64 date_modified = s.ColumnInt64(13); |
| 1861 | 1865 |
| 1862 sql::Statement s_insert(db_->GetUniqueStatement( | 1866 sql::Statement s_insert(db_->GetUniqueStatement( |
| 1863 "INSERT INTO autofill_profiles_temp" | 1867 "INSERT INTO autofill_profiles_temp" |
| 1864 "(guid, company_name, address_line_1, address_line_2, city," | 1868 "(guid, company_name, address_line_1, address_line_2, city," |
| 1865 " state, zipcode, country, date_modified)" | 1869 " state, zipcode, country, date_modified)" |
| 1866 "VALUES (?,?,?,?,?,?,?,?,?)")); | 1870 "VALUES (?,?,?,?,?,?,?,?,?)")); |
| 1867 s_insert.BindString(0, profile.guid()); | 1871 s_insert.BindString(0, profile.guid()); |
| 1868 s_insert.BindString16(1, profile.GetRawInfo(COMPANY_NAME)); | 1872 s_insert.BindString16(1, profile.GetRawInfo(COMPANY_NAME)); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2038 "WHERE guid=?")); | 2042 "WHERE guid=?")); |
| 2039 s_date.BindInt64(0, date_item->second); | 2043 s_date.BindInt64(0, date_item->second); |
| 2040 s_date.BindString(1, iter->guid()); | 2044 s_date.BindString(1, iter->guid()); |
| 2041 | 2045 |
| 2042 if (!s_date.Run()) | 2046 if (!s_date.Run()) |
| 2043 return false; | 2047 return false; |
| 2044 } | 2048 } |
| 2045 | 2049 |
| 2046 return true; | 2050 return true; |
| 2047 } | 2051 } |
| OLD | NEW |