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

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

Issue 1198013002: Avoiding Vectors usage while setting info in AutofillProfile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 credit_card->set_origin(s.ColumnString(index++)); 187 credit_card->set_origin(s.ColumnString(index++));
188 188
189 return credit_card.Pass(); 189 return credit_card.Pass();
190 } 190 }
191 191
192 bool AddAutofillProfileNamesToProfile(sql::Connection* db, 192 bool AddAutofillProfileNamesToProfile(sql::Connection* db,
193 AutofillProfile* profile) { 193 AutofillProfile* profile) {
194 sql::Statement s(db->GetUniqueStatement( 194 sql::Statement s(db->GetUniqueStatement(
195 "SELECT guid, first_name, middle_name, last_name, full_name " 195 "SELECT guid, first_name, middle_name, last_name, full_name "
196 "FROM autofill_profile_names " 196 "FROM autofill_profile_names "
197 "WHERE guid=?")); 197 "WHERE guid=?"
198 "LIMIT 1"));
198 s.BindString(0, profile->guid()); 199 s.BindString(0, profile->guid());
199 200
200 if (!s.is_valid()) 201 if (!s.is_valid())
201 return false; 202 return false;
202 203
203 std::vector<base::string16> first_names; 204 // TODO(estade): update schema so that multiple names are not associated per
204 std::vector<base::string16> middle_names; 205 // unique profile guid. Please refer https://crbug.com/497934.
Evan Stade 2015/06/26 14:31:14 nit, move comment to above statement that has LIMI
Deepak 2015/06/26 14:40:43 Done.
205 std::vector<base::string16> last_names; 206 if (s.Step()) {
206 std::vector<base::string16> full_names;
207 while (s.Step()) {
208 DCHECK_EQ(profile->guid(), s.ColumnString(0)); 207 DCHECK_EQ(profile->guid(), s.ColumnString(0));
209 first_names.push_back(s.ColumnString16(1)); 208 profile->SetRawInfo(NAME_FIRST, s.ColumnString16(1));
210 middle_names.push_back(s.ColumnString16(2)); 209 profile->SetRawInfo(NAME_MIDDLE, s.ColumnString16(2));
211 last_names.push_back(s.ColumnString16(3)); 210 profile->SetRawInfo(NAME_LAST, s.ColumnString16(3));
212 full_names.push_back(s.ColumnString16(4)); 211 profile->SetRawInfo(NAME_FULL, s.ColumnString16(4));
213 } 212 }
214 if (!s.Succeeded()) 213 return s.Succeeded();
215 return false;
216
217 // TODO(estade): update schema so these aren't vectors.
218 first_names.resize(1);
219 middle_names.resize(1);
220 last_names.resize(1);
221 full_names.resize(1);
222
223 profile->SetRawInfo(NAME_FIRST, first_names[0]);
224 profile->SetRawInfo(NAME_MIDDLE, middle_names[0]);
225 profile->SetRawInfo(NAME_LAST, last_names[0]);
226 profile->SetRawInfo(NAME_FULL, full_names[0]);
227 return true;
228 } 214 }
229 215
230 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, 216 bool AddAutofillProfileEmailsToProfile(sql::Connection* db,
231 AutofillProfile* profile) { 217 AutofillProfile* profile) {
232 sql::Statement s(db->GetUniqueStatement( 218 sql::Statement s(db->GetUniqueStatement(
233 "SELECT guid, email " 219 "SELECT guid, email "
234 "FROM autofill_profile_emails " 220 "FROM autofill_profile_emails "
235 "WHERE guid=?")); 221 "WHERE guid=?"
222 "LIMIT 1"));
236 s.BindString(0, profile->guid()); 223 s.BindString(0, profile->guid());
237 224
238 if (!s.is_valid()) 225 if (!s.is_valid())
239 return false; 226 return false;
240 227
241 std::vector<base::string16> emails; 228 // TODO(estade): update schema so that multiple emails are not associated per
242 while (s.Step()) { 229 // unique profile guid. Please refer https://crbug.com/497934.
230 if (s.Step()) {
243 DCHECK_EQ(profile->guid(), s.ColumnString(0)); 231 DCHECK_EQ(profile->guid(), s.ColumnString(0));
244 emails.push_back(s.ColumnString16(1)); 232 profile->SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(1));
245 } 233 }
246 if (!s.Succeeded()) 234 return s.Succeeded();
247 return false;
248
249 // TODO(estade): update schema so this is not a vector.
250 emails.resize(1);
251 profile->SetRawInfo(EMAIL_ADDRESS, emails[0]);
252 return true;
253 } 235 }
254 236
255 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, 237 bool AddAutofillProfilePhonesToProfile(sql::Connection* db,
256 AutofillProfile* profile) { 238 AutofillProfile* profile) {
257 sql::Statement s(db->GetUniqueStatement( 239 sql::Statement s(db->GetUniqueStatement(
258 "SELECT guid, number " 240 "SELECT guid, number "
259 "FROM autofill_profile_phones " 241 "FROM autofill_profile_phones "
260 "WHERE guid=?")); 242 "WHERE guid=?"
243 "LIMIT 1"));
261 s.BindString(0, profile->guid()); 244 s.BindString(0, profile->guid());
262 245
263 if (!s.is_valid()) 246 if (!s.is_valid())
264 return false; 247 return false;
265 248
266 std::vector<base::string16> numbers; 249 // TODO(estade): update schema so that multiple phone numbers are not
267 while (s.Step()) { 250 // associated per unique profile guid. Please refer https://crbug.com/497934.
251 if (s.Step()) {
268 DCHECK_EQ(profile->guid(), s.ColumnString(0)); 252 DCHECK_EQ(profile->guid(), s.ColumnString(0));
269 numbers.push_back(s.ColumnString16(1)); 253 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(1));
270 } 254 }
271 if (!s.Succeeded()) 255 return s.Succeeded();
272 return false;
273
274 // TODO(estade): update schema so this isn't a vector.
275 numbers.resize(1);
276 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, numbers[0]);
277 return true;
278 } 256 }
279 257
280 bool AddAutofillProfileNames(const AutofillProfile& profile, 258 bool AddAutofillProfileNames(const AutofillProfile& profile,
281 sql::Connection* db) { 259 sql::Connection* db) {
282 // Add the new name. 260 // Add the new name.
283 sql::Statement s(db->GetUniqueStatement( 261 sql::Statement s(db->GetUniqueStatement(
284 "INSERT INTO autofill_profile_names" 262 "INSERT INTO autofill_profile_names"
285 " (guid, first_name, middle_name, last_name, full_name) " 263 " (guid, first_name, middle_name, last_name, full_name) "
286 "VALUES (?,?,?,?,?)")); 264 "VALUES (?,?,?,?,?)"));
287 s.BindString(0, profile.guid()); 265 s.BindString(0, profile.guid());
(...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 2192 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
2215 insert.BindString(index++, profile.language_code()); 2193 insert.BindString(index++, profile.language_code());
2216 insert.Run(); 2194 insert.Run();
2217 insert.Reset(true); 2195 insert.Reset(true);
2218 } 2196 }
2219 2197
2220 return transaction.Commit(); 2198 return transaction.Commit();
2221 } 2199 }
2222 2200
2223 } // namespace autofill 2201 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698