OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/options/autofill_options_handler.h" | 5 #include "chrome/browser/dom_ui/options/autofill_options_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 void AutoFillOptionsHandler::LoadAddressEditor(const ListValue* args) { | 234 void AutoFillOptionsHandler::LoadAddressEditor(const ListValue* args) { |
235 DCHECK(personal_data_->IsDataLoaded()); | 235 DCHECK(personal_data_->IsDataLoaded()); |
236 | 236 |
237 std::string guid; | 237 std::string guid; |
238 if (!args->GetString(0, &guid)) { | 238 if (!args->GetString(0, &guid)) { |
239 NOTREACHED(); | 239 NOTREACHED(); |
240 return; | 240 return; |
241 } | 241 } |
242 | 242 |
243 AutoFillProfile* profile = personal_data_->GetProfileByGUID(guid); | 243 AutoFillProfile* profile = personal_data_->GetProfileByGUID(guid); |
244 DCHECK(profile); | 244 if (!profile) { |
| 245 // There is a race where a user can click once on the close button and |
| 246 // quickly click again on the list item before the item is removed (since |
| 247 // the list is not updated until the model tells the list an item has been |
| 248 // removed). This will activate the editor for a profile that has been |
| 249 // removed. Do nothing in that case. |
| 250 return; |
| 251 } |
245 | 252 |
246 // TODO(jhawkins): This is hacky because we can't send DictionaryValue | 253 // TODO(jhawkins): This is hacky because we can't send DictionaryValue |
247 // directly to CallJavascriptFunction(). | 254 // directly to CallJavascriptFunction(). |
248 ListValue addressList; | 255 ListValue addressList; |
249 DictionaryValue* address = new DictionaryValue(); | 256 DictionaryValue* address = new DictionaryValue(); |
250 address->SetString("guid", profile->guid()); | 257 address->SetString("guid", profile->guid()); |
251 address->SetString("fullName", | 258 address->SetString("fullName", |
252 profile->GetFieldText(AutoFillType(NAME_FULL))); | 259 profile->GetFieldText(AutoFillType(NAME_FULL))); |
253 address->SetString("companyName", | 260 address->SetString("companyName", |
254 profile->GetFieldText(AutoFillType(COMPANY_NAME))); | 261 profile->GetFieldText(AutoFillType(COMPANY_NAME))); |
(...skipping 26 matching lines...) Expand all Loading... |
281 void AutoFillOptionsHandler::LoadCreditCardEditor(const ListValue* args) { | 288 void AutoFillOptionsHandler::LoadCreditCardEditor(const ListValue* args) { |
282 DCHECK(personal_data_->IsDataLoaded()); | 289 DCHECK(personal_data_->IsDataLoaded()); |
283 | 290 |
284 std::string guid; | 291 std::string guid; |
285 if (!args->GetString(0, &guid)) { | 292 if (!args->GetString(0, &guid)) { |
286 NOTREACHED(); | 293 NOTREACHED(); |
287 return; | 294 return; |
288 } | 295 } |
289 | 296 |
290 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); | 297 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); |
291 DCHECK(credit_card); | 298 if (!credit_card) { |
| 299 // There is a race where a user can click once on the close button and |
| 300 // quickly click again on the list item before the item is removed (since |
| 301 // the list is not updated until the model tells the list an item has been |
| 302 // removed). This will activate the editor for a profile that has been |
| 303 // removed. Do nothing in that case. |
| 304 return; |
| 305 } |
292 | 306 |
293 // TODO(jhawkins): This is hacky because we can't send DictionaryValue | 307 // TODO(jhawkins): This is hacky because we can't send DictionaryValue |
294 // directly to CallJavascriptFunction(). | 308 // directly to CallJavascriptFunction(). |
295 ListValue credit_card_list; | 309 ListValue credit_card_list; |
296 DictionaryValue* credit_card_data = new DictionaryValue(); | 310 DictionaryValue* credit_card_data = new DictionaryValue(); |
297 credit_card_data->SetString("guid", credit_card->guid()); | 311 credit_card_data->SetString("guid", credit_card->guid()); |
298 credit_card_data->SetString( | 312 credit_card_data->SetString( |
299 "nameOnCard", | 313 "nameOnCard", |
300 credit_card->GetFieldText(AutoFillType(CREDIT_CARD_NAME))); | 314 credit_card->GetFieldText(AutoFillType(CREDIT_CARD_NAME))); |
301 credit_card_data->SetString( | 315 credit_card_data->SetString( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 if (args->GetString(4, &value)) | 393 if (args->GetString(4, &value)) |
380 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); | 394 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); |
381 | 395 |
382 if (!guid::IsValidGUID(credit_card.guid())) { | 396 if (!guid::IsValidGUID(credit_card.guid())) { |
383 credit_card.set_guid(guid::GenerateGUID()); | 397 credit_card.set_guid(guid::GenerateGUID()); |
384 personal_data_->AddCreditCard(credit_card); | 398 personal_data_->AddCreditCard(credit_card); |
385 } else { | 399 } else { |
386 personal_data_->UpdateCreditCard(credit_card); | 400 personal_data_->UpdateCreditCard(credit_card); |
387 } | 401 } |
388 } | 402 } |
OLD | NEW |