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

Side by Side Diff: chrome/browser/ui/webui/options/autofill_options_handler.cc

Issue 6673079: Reduce boxing and unboxing of AutofillFieldType (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compile on Windows. Created 9 years, 9 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/webui/options/autofill_options_handler.h" 5 #include "chrome/browser/ui/webui/options/autofill_options_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // There is a race where a user can click once on the close button and 259 // There is a race where a user can click once on the close button and
260 // quickly click again on the list item before the item is removed (since 260 // quickly click again on the list item before the item is removed (since
261 // the list is not updated until the model tells the list an item has been 261 // the list is not updated until the model tells the list an item has been
262 // removed). This will activate the editor for a profile that has been 262 // removed). This will activate the editor for a profile that has been
263 // removed. Do nothing in that case. 263 // removed. Do nothing in that case.
264 return; 264 return;
265 } 265 }
266 266
267 DictionaryValue address; 267 DictionaryValue address;
268 address.SetString("guid", profile->guid()); 268 address.SetString("guid", profile->guid());
269 address.SetString("fullName", 269 address.SetString("fullName",
dhollowa 2011/03/16 17:07:11 nit: A number of these should fit on single line n
Ilya Sherman 2011/03/17 03:42:29 Done.
270 profile->GetFieldText(AutofillType(NAME_FULL))); 270 profile->GetFieldText(NAME_FULL));
271 address.SetString("companyName", 271 address.SetString("companyName",
272 profile->GetFieldText(AutofillType(COMPANY_NAME))); 272 profile->GetFieldText(COMPANY_NAME));
273 address.SetString("addrLine1", 273 address.SetString("addrLine1",
274 profile->GetFieldText(AutofillType(ADDRESS_HOME_LINE1))); 274 profile->GetFieldText(ADDRESS_HOME_LINE1));
275 address.SetString("addrLine2", 275 address.SetString("addrLine2",
276 profile->GetFieldText(AutofillType(ADDRESS_HOME_LINE2))); 276 profile->GetFieldText(ADDRESS_HOME_LINE2));
277 address.SetString("city", 277 address.SetString("city",
278 profile->GetFieldText(AutofillType(ADDRESS_HOME_CITY))); 278 profile->GetFieldText(ADDRESS_HOME_CITY));
279 address.SetString("state", 279 address.SetString("state",
280 profile->GetFieldText(AutofillType(ADDRESS_HOME_STATE))); 280 profile->GetFieldText(ADDRESS_HOME_STATE));
281 address.SetString("postalCode", 281 address.SetString("postalCode",
282 profile->GetFieldText(AutofillType(ADDRESS_HOME_ZIP))); 282 profile->GetFieldText(ADDRESS_HOME_ZIP));
283 address.SetString("country", 283 address.SetString("country",
284 profile->CountryCode()); 284 profile->CountryCode());
285 address.SetString( 285 address.SetString(
286 "phone", 286 "phone",
287 profile->GetFieldText(AutofillType(PHONE_HOME_WHOLE_NUMBER))); 287 profile->GetFieldText(PHONE_HOME_WHOLE_NUMBER));
288 address.SetString( 288 address.SetString(
289 "fax", 289 "fax",
290 profile->GetFieldText(AutofillType(PHONE_FAX_WHOLE_NUMBER))); 290 profile->GetFieldText(PHONE_FAX_WHOLE_NUMBER));
291 address.SetString("email", 291 address.SetString("email",
292 profile->GetFieldText(AutofillType(EMAIL_ADDRESS))); 292 profile->GetFieldText(EMAIL_ADDRESS));
293 293
294 web_ui_->CallJavascriptFunction("AutoFillOptions.editAddress", address); 294 web_ui_->CallJavascriptFunction("AutoFillOptions.editAddress", address);
295 } 295 }
296 296
297 void AutoFillOptionsHandler::LoadCreditCardEditor(const ListValue* args) { 297 void AutoFillOptionsHandler::LoadCreditCardEditor(const ListValue* args) {
298 DCHECK(personal_data_->IsDataLoaded()); 298 DCHECK(personal_data_->IsDataLoaded());
299 299
300 std::string guid; 300 std::string guid;
301 if (!args->GetString(0, &guid)) { 301 if (!args->GetString(0, &guid)) {
302 NOTREACHED(); 302 NOTREACHED();
303 return; 303 return;
304 } 304 }
305 305
306 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); 306 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid);
307 if (!credit_card) { 307 if (!credit_card) {
308 // There is a race where a user can click once on the close button and 308 // There is a race where a user can click once on the close button and
309 // quickly click again on the list item before the item is removed (since 309 // quickly click again on the list item before the item is removed (since
310 // the list is not updated until the model tells the list an item has been 310 // the list is not updated until the model tells the list an item has been
311 // removed). This will activate the editor for a profile that has been 311 // removed). This will activate the editor for a profile that has been
312 // removed. Do nothing in that case. 312 // removed. Do nothing in that case.
313 return; 313 return;
314 } 314 }
315 315
316 DictionaryValue credit_card_data; 316 DictionaryValue credit_card_data;
317 credit_card_data.SetString("guid", credit_card->guid()); 317 credit_card_data.SetString("guid", credit_card->guid());
318 credit_card_data.SetString( 318 credit_card_data.SetString(
319 "nameOnCard", 319 "nameOnCard",
320 credit_card->GetFieldText(AutofillType(CREDIT_CARD_NAME))); 320 credit_card->GetFieldText(CREDIT_CARD_NAME));
321 credit_card_data.SetString( 321 credit_card_data.SetString(
322 "creditCardNumber", 322 "creditCardNumber",
323 credit_card->GetFieldText(AutofillType(CREDIT_CARD_NUMBER))); 323 credit_card->GetFieldText(CREDIT_CARD_NUMBER));
324 credit_card_data.SetString( 324 credit_card_data.SetString(
325 "expirationMonth", 325 "expirationMonth",
326 credit_card->GetFieldText(AutofillType(CREDIT_CARD_EXP_MONTH))); 326 credit_card->GetFieldText(CREDIT_CARD_EXP_MONTH));
327 credit_card_data.SetString( 327 credit_card_data.SetString(
328 "expirationYear", 328 "expirationYear",
329 credit_card->GetFieldText(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); 329 credit_card->GetFieldText(CREDIT_CARD_EXP_4_DIGIT_YEAR));
330 330
331 web_ui_->CallJavascriptFunction("AutoFillOptions.editCreditCard", 331 web_ui_->CallJavascriptFunction("AutoFillOptions.editCreditCard",
332 credit_card_data); 332 credit_card_data);
333 } 333 }
334 334
335 void AutoFillOptionsHandler::SetAddress(const ListValue* args) { 335 void AutoFillOptionsHandler::SetAddress(const ListValue* args) {
336 if (!personal_data_->IsDataLoaded()) 336 if (!personal_data_->IsDataLoaded())
337 return; 337 return;
338 338
339 std::string guid; 339 std::string guid;
340 if (!args->GetString(0, &guid)) { 340 if (!args->GetString(0, &guid)) {
341 NOTREACHED(); 341 NOTREACHED();
342 return; 342 return;
343 } 343 }
344 344
345 AutofillProfile profile(guid); 345 AutofillProfile profile(guid);
346 346
347 std::string country_code; 347 std::string country_code;
348 string16 value; 348 string16 value;
349 if (args->GetString(1, &value)) 349 if (args->GetString(1, &value))
350 profile.SetInfo(AutofillType(NAME_FULL), value); 350 profile.SetInfo(NAME_FULL, value);
351 if (args->GetString(2, &value)) 351 if (args->GetString(2, &value))
352 profile.SetInfo(AutofillType(COMPANY_NAME), value); 352 profile.SetInfo(COMPANY_NAME, value);
353 if (args->GetString(3, &value)) 353 if (args->GetString(3, &value))
354 profile.SetInfo(AutofillType(ADDRESS_HOME_LINE1), value); 354 profile.SetInfo(ADDRESS_HOME_LINE1, value);
355 if (args->GetString(4, &value)) 355 if (args->GetString(4, &value))
356 profile.SetInfo(AutofillType(ADDRESS_HOME_LINE2), value); 356 profile.SetInfo(ADDRESS_HOME_LINE2, value);
357 if (args->GetString(5, &value)) 357 if (args->GetString(5, &value))
358 profile.SetInfo(AutofillType(ADDRESS_HOME_CITY), value); 358 profile.SetInfo(ADDRESS_HOME_CITY, value);
359 if (args->GetString(6, &value)) 359 if (args->GetString(6, &value))
360 profile.SetInfo(AutofillType(ADDRESS_HOME_STATE), value); 360 profile.SetInfo(ADDRESS_HOME_STATE, value);
361 if (args->GetString(7, &value)) 361 if (args->GetString(7, &value))
362 profile.SetInfo(AutofillType(ADDRESS_HOME_ZIP), value); 362 profile.SetInfo(ADDRESS_HOME_ZIP, value);
363 if (args->GetString(8, &country_code)) 363 if (args->GetString(8, &country_code))
364 profile.SetCountryCode(country_code); 364 profile.SetCountryCode(country_code);
365 if (args->GetString(9, &value)) 365 if (args->GetString(9, &value))
366 profile.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), value); 366 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, value);
367 if (args->GetString(10, &value)) 367 if (args->GetString(10, &value))
368 profile.SetInfo(AutofillType(PHONE_FAX_WHOLE_NUMBER), value); 368 profile.SetInfo(PHONE_FAX_WHOLE_NUMBER, value);
369 if (args->GetString(11, &value)) 369 if (args->GetString(11, &value))
370 profile.SetInfo(AutofillType(EMAIL_ADDRESS), value); 370 profile.SetInfo(EMAIL_ADDRESS, value);
371 371
372 if (!guid::IsValidGUID(profile.guid())) { 372 if (!guid::IsValidGUID(profile.guid())) {
373 profile.set_guid(guid::GenerateGUID()); 373 profile.set_guid(guid::GenerateGUID());
374 personal_data_->AddProfile(profile); 374 personal_data_->AddProfile(profile);
375 } else { 375 } else {
376 personal_data_->UpdateProfile(profile); 376 personal_data_->UpdateProfile(profile);
377 } 377 }
378 } 378 }
379 379
380 void AutoFillOptionsHandler::SetCreditCard(const ListValue* args) { 380 void AutoFillOptionsHandler::SetCreditCard(const ListValue* args) {
381 if (!personal_data_->IsDataLoaded()) 381 if (!personal_data_->IsDataLoaded())
382 return; 382 return;
383 383
384 std::string guid; 384 std::string guid;
385 if (!args->GetString(0, &guid)) { 385 if (!args->GetString(0, &guid)) {
386 NOTREACHED(); 386 NOTREACHED();
387 return; 387 return;
388 } 388 }
389 389
390 CreditCard credit_card(guid); 390 CreditCard credit_card(guid);
391 391
392 string16 value; 392 string16 value;
393 if (args->GetString(1, &value)) 393 if (args->GetString(1, &value))
394 credit_card.SetInfo(AutofillType(CREDIT_CARD_NAME), value); 394 credit_card.SetInfo(CREDIT_CARD_NAME, value);
395 if (args->GetString(2, &value)) 395 if (args->GetString(2, &value))
396 credit_card.SetInfo(AutofillType(CREDIT_CARD_NUMBER), value); 396 credit_card.SetInfo(CREDIT_CARD_NUMBER, value);
397 if (args->GetString(3, &value)) 397 if (args->GetString(3, &value))
398 credit_card.SetInfo(AutofillType(CREDIT_CARD_EXP_MONTH), value); 398 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, value);
399 if (args->GetString(4, &value)) 399 if (args->GetString(4, &value))
400 credit_card.SetInfo(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); 400 credit_card.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, value);
401 401
402 if (!guid::IsValidGUID(credit_card.guid())) { 402 if (!guid::IsValidGUID(credit_card.guid())) {
403 credit_card.set_guid(guid::GenerateGUID()); 403 credit_card.set_guid(guid::GenerateGUID());
404 personal_data_->AddCreditCard(credit_card); 404 personal_data_->AddCreditCard(credit_card);
405 } else { 405 } else {
406 personal_data_->UpdateCreditCard(credit_card); 406 personal_data_->UpdateCreditCard(credit_card);
407 } 407 }
408 } 408 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698