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

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

Issue 310463005: Fill in more name fields with requestAutocomplete (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: dumb test is dumb Created 6 years, 6 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 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 index++; 160 index++;
161 } 161 }
162 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, credit_card_number); 162 credit_card->SetRawInfo(CREDIT_CARD_NUMBER, credit_card_number);
163 // Intentionally skip column 5, which stores the modification date. 163 // Intentionally skip column 5, which stores the modification date.
164 index++; 164 index++;
165 credit_card->set_origin(s.ColumnString(index++)); 165 credit_card->set_origin(s.ColumnString(index++));
166 166
167 return credit_card.Pass(); 167 return credit_card.Pass();
168 } 168 }
169 169
170 // Obsolete version of AddAutofillProfileNamesToProfile, but still needed
171 // for MigrateToVersion37MergeAndCullOlderProfiles().
172 bool AddAutofillProfileNamesToProfileForVersion37(sql::Connection* db,
173 AutofillProfile* profile) {
174 sql::Statement s(db->GetUniqueStatement(
175 "SELECT guid, first_name, middle_name, last_name "
176 "FROM autofill_profile_names "
177 "WHERE guid=?"));
178 s.BindString(0, profile->guid());
179
180 if (!s.is_valid())
181 return false;
182
183 std::vector<base::string16> first_names;
184 std::vector<base::string16> middle_names;
185 std::vector<base::string16> last_names;
186 while (s.Step()) {
187 DCHECK_EQ(profile->guid(), s.ColumnString(0));
188 first_names.push_back(s.ColumnString16(1));
189 middle_names.push_back(s.ColumnString16(2));
190 last_names.push_back(s.ColumnString16(3));
191 }
192 if (!s.Succeeded())
193 return false;
194
195 profile->SetRawMultiInfo(NAME_FIRST, first_names);
196 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names);
197 profile->SetRawMultiInfo(NAME_LAST, last_names);
198 return true;
199 }
200
170 bool AddAutofillProfileNamesToProfile(sql::Connection* db, 201 bool AddAutofillProfileNamesToProfile(sql::Connection* db,
171 AutofillProfile* profile) { 202 AutofillProfile* profile) {
172 sql::Statement s(db->GetUniqueStatement( 203 sql::Statement s(db->GetUniqueStatement(
173 "SELECT guid, first_name, middle_name, last_name " 204 "SELECT guid, first_name, middle_name, last_name, full_name "
174 "FROM autofill_profile_names " 205 "FROM autofill_profile_names "
175 "WHERE guid=?")); 206 "WHERE guid=?"));
176 s.BindString(0, profile->guid()); 207 s.BindString(0, profile->guid());
177 208
178 if (!s.is_valid()) 209 if (!s.is_valid())
179 return false; 210 return false;
180 211
181 std::vector<base::string16> first_names; 212 std::vector<base::string16> first_names;
182 std::vector<base::string16> middle_names; 213 std::vector<base::string16> middle_names;
183 std::vector<base::string16> last_names; 214 std::vector<base::string16> last_names;
215 std::vector<base::string16> full_names;
184 while (s.Step()) { 216 while (s.Step()) {
185 DCHECK_EQ(profile->guid(), s.ColumnString(0)); 217 DCHECK_EQ(profile->guid(), s.ColumnString(0));
186 first_names.push_back(s.ColumnString16(1)); 218 first_names.push_back(s.ColumnString16(1));
187 middle_names.push_back(s.ColumnString16(2)); 219 middle_names.push_back(s.ColumnString16(2));
188 last_names.push_back(s.ColumnString16(3)); 220 last_names.push_back(s.ColumnString16(3));
221 full_names.push_back(s.ColumnString16(4));
189 } 222 }
190 if (!s.Succeeded()) 223 if (!s.Succeeded())
191 return false; 224 return false;
192 225
193 profile->SetRawMultiInfo(NAME_FIRST, first_names); 226 profile->SetRawMultiInfo(NAME_FIRST, first_names);
194 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names); 227 profile->SetRawMultiInfo(NAME_MIDDLE, middle_names);
195 profile->SetRawMultiInfo(NAME_LAST, last_names); 228 profile->SetRawMultiInfo(NAME_LAST, last_names);
229 profile->SetRawMultiInfo(NAME_FULL, full_names);
196 return true; 230 return true;
197 } 231 }
198 232
199 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, 233 bool AddAutofillProfileEmailsToProfile(sql::Connection* db,
200 AutofillProfile* profile) { 234 AutofillProfile* profile) {
201 sql::Statement s(db->GetUniqueStatement( 235 sql::Statement s(db->GetUniqueStatement(
202 "SELECT guid, email " 236 "SELECT guid, email "
203 "FROM autofill_profile_emails " 237 "FROM autofill_profile_emails "
204 "WHERE guid=?")); 238 "WHERE guid=?"));
205 s.BindString(0, profile->guid()); 239 s.BindString(0, profile->guid());
(...skipping 29 matching lines...) Expand all
235 DCHECK_EQ(profile->guid(), s.ColumnString(0)); 269 DCHECK_EQ(profile->guid(), s.ColumnString(0));
236 numbers.push_back(s.ColumnString16(1)); 270 numbers.push_back(s.ColumnString16(1));
237 } 271 }
238 if (!s.Succeeded()) 272 if (!s.Succeeded())
239 return false; 273 return false;
240 274
241 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers); 275 profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers);
242 return true; 276 return true;
243 } 277 }
244 278
279 // Obsolete version of AddAutofillProfileNames needed for
280 // MigrateToVersion33ProfilesBasedOnFirstName() and
281 // MigrateToVersion37MergeAndCullOlderProfiles().
282 bool AddAutofillProfileNamesForVersion3x(
283 const AutofillProfile& profile,
284 sql::Connection* db) {
285 std::vector<base::string16> first_names;
286 profile.GetRawMultiInfo(NAME_FIRST, &first_names);
287 std::vector<base::string16> middle_names;
288 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names);
289 std::vector<base::string16> last_names;
290 profile.GetRawMultiInfo(NAME_LAST, &last_names);
291 DCHECK_EQ(first_names.size(), middle_names.size());
292 DCHECK_EQ(first_names.size(), last_names.size());
293
294 for (size_t i = 0; i < first_names.size(); ++i) {
295 // Add the new name.
296 sql::Statement s(db->GetUniqueStatement(
297 "INSERT INTO autofill_profile_names"
298 " (guid, first_name, middle_name, last_name) "
299 "VALUES (?,?,?,?)"));
300 s.BindString(0, profile.guid());
301 s.BindString16(1, first_names[i]);
302 s.BindString16(2, middle_names[i]);
303 s.BindString16(3, last_names[i]);
304
305 if (!s.Run())
306 return false;
307 }
308 return true;
309 }
310
245 bool AddAutofillProfileNames(const AutofillProfile& profile, 311 bool AddAutofillProfileNames(const AutofillProfile& profile,
246 sql::Connection* db) { 312 sql::Connection* db) {
247 std::vector<base::string16> first_names; 313 std::vector<base::string16> first_names;
248 profile.GetRawMultiInfo(NAME_FIRST, &first_names); 314 profile.GetRawMultiInfo(NAME_FIRST, &first_names);
249 std::vector<base::string16> middle_names; 315 std::vector<base::string16> middle_names;
250 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names); 316 profile.GetRawMultiInfo(NAME_MIDDLE, &middle_names);
251 std::vector<base::string16> last_names; 317 std::vector<base::string16> last_names;
252 profile.GetRawMultiInfo(NAME_LAST, &last_names); 318 profile.GetRawMultiInfo(NAME_LAST, &last_names);
319 std::vector<base::string16> full_names;
320 profile.GetRawMultiInfo(NAME_FULL, &full_names);
253 DCHECK_EQ(first_names.size(), middle_names.size()); 321 DCHECK_EQ(first_names.size(), middle_names.size());
254 DCHECK_EQ(middle_names.size(), last_names.size()); 322 DCHECK_EQ(first_names.size(), last_names.size());
323 DCHECK_EQ(first_names.size(), full_names.size());
255 324
256 for (size_t i = 0; i < first_names.size(); ++i) { 325 for (size_t i = 0; i < first_names.size(); ++i) {
257 // Add the new name. 326 // Add the new name.
258 sql::Statement s(db->GetUniqueStatement( 327 sql::Statement s(db->GetUniqueStatement(
259 "INSERT INTO autofill_profile_names" 328 "INSERT INTO autofill_profile_names"
260 " (guid, first_name, middle_name, last_name) " 329 " (guid, first_name, middle_name, last_name, full_name) "
261 "VALUES (?,?,?,?)")); 330 "VALUES (?,?,?,?,?)"));
262 s.BindString(0, profile.guid()); 331 s.BindString(0, profile.guid());
263 s.BindString16(1, first_names[i]); 332 s.BindString16(1, first_names[i]);
264 s.BindString16(2, middle_names[i]); 333 s.BindString16(2, middle_names[i]);
265 s.BindString16(3, last_names[i]); 334 s.BindString16(3, last_names[i]);
335 s.BindString16(4, full_names[i]);
266 336
267 if (!s.Run()) 337 if (!s.Run())
268 return false; 338 return false;
269 } 339 }
270 return true; 340 return true;
271 } 341 }
272 342
273 bool AddAutofillProfileEmails(const AutofillProfile& profile, 343 bool AddAutofillProfileEmails(const AutofillProfile& profile,
274 sql::Connection* db) { 344 sql::Connection* db) {
275 std::vector<base::string16> emails; 345 std::vector<base::string16> emails;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 return MigrateToVersion51AddOriginColumn(); 510 return MigrateToVersion51AddOriginColumn();
441 case 54: 511 case 54:
442 *update_compatible_version = true; 512 *update_compatible_version = true;
443 return MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields(); 513 return MigrateToVersion54AddI18nFieldsAndRemoveDeprecatedFields();
444 case 55: 514 case 55:
445 *update_compatible_version = true; 515 *update_compatible_version = true;
446 return MigrateToVersion55MergeAutofillDatesTable(); 516 return MigrateToVersion55MergeAutofillDatesTable();
447 case 56: 517 case 56:
448 *update_compatible_version = true; 518 *update_compatible_version = true;
449 return MigrateToVersion56AddProfileLanguageCodeForFormatting(); 519 return MigrateToVersion56AddProfileLanguageCodeForFormatting();
520 case 57:
521 *update_compatible_version = true;
522 return MigrateToVersion57AddFullNameField();
450 } 523 }
451 return true; 524 return true;
452 } 525 }
453 526
454 bool AutofillTable::AddFormFieldValues( 527 bool AutofillTable::AddFormFieldValues(
455 const std::vector<FormFieldData>& elements, 528 const std::vector<FormFieldData>& elements,
456 std::vector<AutofillChange>* changes) { 529 std::vector<AutofillChange>* changes) {
457 return AddFormFieldValuesTime(elements, changes, Time::Now()); 530 return AddFormFieldValuesTime(elements, changes, Time::Now());
458 } 531 }
459 532
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 } 1358 }
1286 return true; 1359 return true;
1287 } 1360 }
1288 1361
1289 bool AutofillTable::InitProfileNamesTable() { 1362 bool AutofillTable::InitProfileNamesTable() {
1290 if (!db_->DoesTableExist("autofill_profile_names")) { 1363 if (!db_->DoesTableExist("autofill_profile_names")) {
1291 if (!db_->Execute("CREATE TABLE autofill_profile_names ( " 1364 if (!db_->Execute("CREATE TABLE autofill_profile_names ( "
1292 "guid VARCHAR, " 1365 "guid VARCHAR, "
1293 "first_name VARCHAR, " 1366 "first_name VARCHAR, "
1294 "middle_name VARCHAR, " 1367 "middle_name VARCHAR, "
1295 "last_name VARCHAR)")) { 1368 "last_name VARCHAR, "
1369 "full_name VARCHAR)")) {
1296 NOTREACHED(); 1370 NOTREACHED();
1297 return false; 1371 return false;
1298 } 1372 }
1299 } 1373 }
1300 return true; 1374 return true;
1301 } 1375 }
1302 1376
1303 bool AutofillTable::InitProfileEmailsTable() { 1377 bool AutofillTable::InitProfileEmailsTable() {
1304 if (!db_->DoesTableExist("autofill_profile_emails")) { 1378 if (!db_->DoesTableExist("autofill_profile_emails")) {
1305 if (!db_->Execute("CREATE TABLE autofill_profile_emails ( " 1379 if (!db_->Execute("CREATE TABLE autofill_profile_emails ( "
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 s_insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_CITY)); 1932 s_insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_CITY));
1859 s_insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_STATE)); 1933 s_insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_STATE));
1860 s_insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_ZIP)); 1934 s_insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_ZIP));
1861 s_insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_COUNTRY)); 1935 s_insert.BindString16(index++, profile.GetRawInfo(ADDRESS_HOME_COUNTRY));
1862 s_insert.BindInt64(index++, date_modified); 1936 s_insert.BindInt64(index++, date_modified);
1863 1937
1864 if (!s_insert.Run()) 1938 if (!s_insert.Run())
1865 return false; 1939 return false;
1866 1940
1867 // Add the other bits: names, emails, and phone numbers. 1941 // Add the other bits: names, emails, and phone numbers.
1868 if (!AddAutofillProfilePieces(profile, db_)) 1942 if (!AddAutofillProfileNamesForVersion3x(profile, db_) ||
1943 !AddAutofillProfileEmails(profile, db_) ||
1944 !AddAutofillProfilePhones(profile, db_)) {
1869 return false; 1945 return false;
1946 }
1870 } // endwhile 1947 } // endwhile
1871 if (!s.Succeeded()) 1948 if (!s.Succeeded())
1872 return false; 1949 return false;
1873 1950
1874 if (!db_->Execute("DROP TABLE autofill_profiles")) 1951 if (!db_->Execute("DROP TABLE autofill_profiles"))
1875 return false; 1952 return false;
1876 1953
1877 if (!db_->Execute( 1954 if (!db_->Execute(
1878 "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) { 1955 "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) {
1879 return false; 1956 return false;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); 2075 profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++));
1999 // Intentionally skip column 7, which stores the localized country name. 2076 // Intentionally skip column 7, which stores the localized country name.
2000 index++; 2077 index++;
2001 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); 2078 profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++));
2002 // Intentionally skip column 9, which stores the profile's modification 2079 // Intentionally skip column 9, which stores the profile's modification
2003 // date. 2080 // date.
2004 index++; 2081 index++;
2005 profile->set_origin(s.ColumnString(index++)); 2082 profile->set_origin(s.ColumnString(index++));
2006 2083
2007 // Get associated name info. 2084 // Get associated name info.
2008 AddAutofillProfileNamesToProfile(db_, profile.get()); 2085 AddAutofillProfileNamesToProfileForVersion37(db_, profile.get());
2009 2086
2010 // Get associated email info. 2087 // Get associated email info.
2011 AddAutofillProfileEmailsToProfile(db_, profile.get()); 2088 AddAutofillProfileEmailsToProfile(db_, profile.get());
2012 2089
2013 // Get associated phone info. 2090 // Get associated phone info.
2014 AddAutofillProfilePhonesToProfile(db_, profile.get()); 2091 AddAutofillProfilePhonesToProfile(db_, profile.get());
2015 2092
2016 if (PersonalDataManager::IsValidLearnableProfile(*profile, app_locale_)) { 2093 if (PersonalDataManager::IsValidLearnableProfile(*profile, app_locale_)) {
2017 std::vector<AutofillProfile> merged_profiles; 2094 std::vector<AutofillProfile> merged_profiles;
2018 std::string merged_guid = PersonalDataManager::MergeProfile( 2095 std::string merged_guid = PersonalDataManager::MergeProfile(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 s.BindString16(index++, GetInfo(*iter, ADDRESS_HOME_CITY)); 2143 s.BindString16(index++, GetInfo(*iter, ADDRESS_HOME_CITY));
2067 s.BindString16(index++, GetInfo(*iter, ADDRESS_HOME_STATE)); 2144 s.BindString16(index++, GetInfo(*iter, ADDRESS_HOME_STATE));
2068 s.BindString16(index++, GetInfo(*iter, ADDRESS_HOME_ZIP)); 2145 s.BindString16(index++, GetInfo(*iter, ADDRESS_HOME_ZIP));
2069 s.BindString16(index++, base::string16()); // This column is deprecated. 2146 s.BindString16(index++, base::string16()); // This column is deprecated.
2070 s.BindString16(index++, GetInfo(*iter, ADDRESS_HOME_COUNTRY)); 2147 s.BindString16(index++, GetInfo(*iter, ADDRESS_HOME_COUNTRY));
2071 s.BindInt64(index++, date_item->second); 2148 s.BindInt64(index++, date_item->second);
2072 2149
2073 if (!s.Run()) 2150 if (!s.Run())
2074 return false; 2151 return false;
2075 2152
2076 if (!AddAutofillProfilePieces(*iter, db_)) 2153 if (!AddAutofillProfileNamesForVersion3x(*iter, db_) ||
2154 !AddAutofillProfileEmails(*iter, db_) ||
2155 !AddAutofillProfilePhones(*iter, db_)) {
2077 return false; 2156 return false;
2157 }
2078 } 2158 }
2079 2159
2080 return true; 2160 return true;
2081 } 2161 }
2082 2162
2083 bool AutofillTable::MigrateToVersion51AddOriginColumn() { 2163 bool AutofillTable::MigrateToVersion51AddOriginColumn() {
2084 sql::Transaction transaction(db_); 2164 sql::Transaction transaction(db_);
2085 if (!transaction.Begin()) 2165 if (!transaction.Begin())
2086 return false; 2166 return false;
2087 2167
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2265 2345
2266 2346
2267 return transaction.Commit(); 2347 return transaction.Commit();
2268 } 2348 }
2269 2349
2270 bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() { 2350 bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() {
2271 return db_->Execute("ALTER TABLE autofill_profiles " 2351 return db_->Execute("ALTER TABLE autofill_profiles "
2272 "ADD COLUMN language_code VARCHAR"); 2352 "ADD COLUMN language_code VARCHAR");
2273 } 2353 }
2274 2354
2355 bool AutofillTable::MigrateToVersion57AddFullNameField() {
2356 return db_->Execute("ALTER TABLE autofill_profile_names "
2357 "ADD COLUMN full_name VARCHAR");
2358 }
2359
2275 } // namespace autofill 2360 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/webdata/autofill_table.h ('k') | components/test/data/web_database/version_56.sql » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698