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

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: 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=?"));
AKV 2015/06/22 10:00:38 Can we restrict the retrieval limit by 1 instead o
Deepak 2015/06/22 11:31:51 Done.
198 s.BindString(0, profile->guid()); 198 s.BindString(0, profile->guid());
199 199
200 if (!s.is_valid()) 200 if (!s.is_valid())
201 return false; 201 return false;
202 202
203 std::vector<base::string16> first_names; 203 if (s.Step()) {
204 std::vector<base::string16> middle_names;
205 std::vector<base::string16> last_names;
206 std::vector<base::string16> full_names;
207 while (s.Step()) {
208 DCHECK_EQ(profile->guid(), s.ColumnString(0)); 204 DCHECK_EQ(profile->guid(), s.ColumnString(0));
209 first_names.push_back(s.ColumnString16(1)); 205 profile->SetRawInfo(NAME_FIRST, s.ColumnString16(1));
210 middle_names.push_back(s.ColumnString16(2)); 206 profile->SetRawInfo(NAME_MIDDLE, s.ColumnString16(2));
211 last_names.push_back(s.ColumnString16(3)); 207 profile->SetRawInfo(NAME_LAST, s.ColumnString16(3));
212 full_names.push_back(s.ColumnString16(4)); 208 profile->SetRawInfo(NAME_FULL, s.ColumnString16(4));
AKV 2015/06/22 10:00:38 s.Succeded() needs to be checked whether Query for
Deepak 2015/06/22 11:31:51 Done.
209 return true;
213 } 210 }
214 if (!s.Succeeded()) 211 return false;
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 } 212 }
229 213
230 bool AddAutofillProfileEmailsToProfile(sql::Connection* db, 214 bool AddAutofillProfileEmailsToProfile(sql::Connection* db,
231 AutofillProfile* profile) { 215 AutofillProfile* profile) {
232 sql::Statement s(db->GetUniqueStatement( 216 sql::Statement s(db->GetUniqueStatement(
233 "SELECT guid, email " 217 "SELECT guid, email "
234 "FROM autofill_profile_emails " 218 "FROM autofill_profile_emails "
235 "WHERE guid=?")); 219 "WHERE guid=?"));
236 s.BindString(0, profile->guid()); 220 s.BindString(0, profile->guid());
237 221
238 if (!s.is_valid()) 222 if (!s.is_valid())
239 return false; 223 return false;
240 224
241 std::vector<base::string16> emails; 225 if (s.Step()) {
242 while (s.Step()) {
243 DCHECK_EQ(profile->guid(), s.ColumnString(0)); 226 DCHECK_EQ(profile->guid(), s.ColumnString(0));
244 emails.push_back(s.ColumnString16(1)); 227 profile->SetRawInfo(EMAIL_ADDRESS, s.ColumnString16(1));
228 return true;
245 } 229 }
246 if (!s.Succeeded()) 230 return false;
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 } 231 }
254 232
255 bool AddAutofillProfilePhonesToProfile(sql::Connection* db, 233 bool AddAutofillProfilePhonesToProfile(sql::Connection* db,
256 AutofillProfile* profile) { 234 AutofillProfile* profile) {
257 sql::Statement s(db->GetUniqueStatement( 235 sql::Statement s(db->GetUniqueStatement(
258 "SELECT guid, number " 236 "SELECT guid, number "
259 "FROM autofill_profile_phones " 237 "FROM autofill_profile_phones "
260 "WHERE guid=?")); 238 "WHERE guid=?"));
261 s.BindString(0, profile->guid()); 239 s.BindString(0, profile->guid());
262 240
263 if (!s.is_valid()) 241 if (!s.is_valid())
264 return false; 242 return false;
265 243
266 std::vector<base::string16> numbers; 244 if (s.Step()) {
267 while (s.Step()) {
268 DCHECK_EQ(profile->guid(), s.ColumnString(0)); 245 DCHECK_EQ(profile->guid(), s.ColumnString(0));
269 numbers.push_back(s.ColumnString16(1)); 246 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(1));
247 return true;
270 } 248 }
271 if (!s.Succeeded()) 249 return false;
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 } 250 }
279 251
280 bool AddAutofillProfileNames(const AutofillProfile& profile, 252 bool AddAutofillProfileNames(const AutofillProfile& profile,
281 sql::Connection* db) { 253 sql::Connection* db) {
282 // Add the new name. 254 // Add the new name.
283 sql::Statement s(db->GetUniqueStatement( 255 sql::Statement s(db->GetUniqueStatement(
284 "INSERT INTO autofill_profile_names" 256 "INSERT INTO autofill_profile_names"
285 " (guid, first_name, middle_name, last_name, full_name) " 257 " (guid, first_name, middle_name, last_name, full_name) "
286 "VALUES (?,?,?,?,?)")); 258 "VALUES (?,?,?,?,?)"));
287 s.BindString(0, profile.guid()); 259 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)); 2186 insert.BindString16(index++, profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
2215 insert.BindString(index++, profile.language_code()); 2187 insert.BindString(index++, profile.language_code());
2216 insert.Run(); 2188 insert.Run();
2217 insert.Reset(true); 2189 insert.Reset(true);
2218 } 2190 }
2219 2191
2220 return transaction.Commit(); 2192 return transaction.Commit();
2221 } 2193 }
2222 2194
2223 } // namespace autofill 2195 } // 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