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

Side by Side Diff: components/autofill/content/browser/wallet/wallet_client.cc

Issue 100743006: Fix DCHECK() when updating instruments with no phone number. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: estade@ review Created 7 years 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/content/browser/wallet/wallet_client.h" 5 #include "components/autofill/content/browser/wallet/wallet_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 std::vector<std::string> document_ids; 276 std::vector<std::string> document_ids;
277 for (size_t i = 0; i < documents.size(); ++i) { 277 for (size_t i = 0; i < documents.size(); ++i) {
278 document_ids.push_back(documents[i]->id()); 278 document_ids.push_back(documents[i]->id());
279 } 279 }
280 DoAcceptLegalDocuments(document_ids, google_transaction_id); 280 DoAcceptLegalDocuments(document_ids, google_transaction_id);
281 } 281 }
282 282
283 void WalletClient::AuthenticateInstrument( 283 void WalletClient::AuthenticateInstrument(
284 const std::string& instrument_id, 284 const std::string& instrument_id,
285 const std::string& card_verification_number) { 285 const std::string& card_verification_number) {
286 if (HasRequestInProgress()) {
287 pending_requests_.push(base::Bind(&WalletClient::AuthenticateInstrument,
288 base::Unretained(this),
289 instrument_id,
290 card_verification_number));
291 return;
292 }
293
294 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
295 request_type_ = AUTHENTICATE_INSTRUMENT;
296
297 base::DictionaryValue request_dict; 286 base::DictionaryValue request_dict;
298 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey()); 287 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
299 request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData()); 288 request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData());
300 request_dict.SetString(kInstrumentIdKey, instrument_id); 289 request_dict.SetString(kInstrumentIdKey, instrument_id);
301 290
302 std::string json_payload; 291 std::string json_payload;
303 base::JSONWriter::Write(&request_dict, &json_payload); 292 base::JSONWriter::Write(&request_dict, &json_payload);
304 293
305 std::string escaped_card_verification_number = net::EscapeUrlEncodedData( 294 std::string escaped_card_verification_number = net::EscapeUrlEncodedData(
306 card_verification_number, true); 295 card_verification_number, true);
307 296
308 std::string post_body = base::StringPrintf( 297 std::string post_body = base::StringPrintf(
309 kEscrowCardVerificationNumberFormat, 298 kEscrowCardVerificationNumberFormat,
310 net::EscapeUrlEncodedData(json_payload, true).c_str(), 299 net::EscapeUrlEncodedData(json_payload, true).c_str(),
311 escaped_card_verification_number.c_str()); 300 escaped_card_verification_number.c_str());
312 301
313 MakeWalletRequest(GetAuthenticateInstrumentUrl(user_index_), 302 MakeWalletRequest(GetAuthenticateInstrumentUrl(user_index_),
314 post_body, 303 post_body,
315 kFormEncodedMimeType); 304 kFormEncodedMimeType,
305 AUTHENTICATE_INSTRUMENT);
316 } 306 }
317 307
318 void WalletClient::GetFullWallet(const FullWalletRequest& full_wallet_request) { 308 void WalletClient::GetFullWallet(const FullWalletRequest& full_wallet_request) {
319 if (HasRequestInProgress()) {
320 pending_requests_.push(base::Bind(&WalletClient::GetFullWallet,
321 base::Unretained(this),
322 full_wallet_request));
323 return;
324 }
325
326 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
327 request_type_ = GET_FULL_WALLET;
328
329 base::DictionaryValue request_dict; 309 base::DictionaryValue request_dict;
330 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey()); 310 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
331 request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData()); 311 request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData());
332 request_dict.SetBoolean(kUseMinimalAddresses, false); 312 request_dict.SetBoolean(kUseMinimalAddresses, false);
333 request_dict.SetBoolean(kPhoneNumberRequired, true); 313 request_dict.SetBoolean(kPhoneNumberRequired, true);
334 request_dict.SetBoolean(kNewWalletUser, full_wallet_request.new_wallet_user); 314 request_dict.SetBoolean(kNewWalletUser, full_wallet_request.new_wallet_user);
335 315
336 request_dict.SetString(kSelectedInstrumentIdKey, 316 request_dict.SetString(kSelectedInstrumentIdKey,
337 full_wallet_request.instrument_id); 317 full_wallet_request.instrument_id);
338 request_dict.SetString(kSelectedAddressIdKey, full_wallet_request.address_id); 318 request_dict.SetString(kSelectedAddressIdKey, full_wallet_request.address_id);
(...skipping 23 matching lines...) Expand all
362 DCHECK_GE(num_bits, kMinBits); 342 DCHECK_GE(num_bits, kMinBits);
363 343
364 std::string post_body = base::StringPrintf( 344 std::string post_body = base::StringPrintf(
365 kGetFullWalletRequestFormat, 345 kGetFullWalletRequestFormat,
366 net::EscapeUrlEncodedData(json_payload, true).c_str(), 346 net::EscapeUrlEncodedData(json_payload, true).c_str(),
367 base::HexEncode(&num_bits, 1).c_str(), 347 base::HexEncode(&num_bits, 1).c_str(),
368 base::HexEncode(&(one_time_pad_[0]), one_time_pad_.size()).c_str()); 348 base::HexEncode(&(one_time_pad_[0]), one_time_pad_.size()).c_str());
369 349
370 MakeWalletRequest(GetGetFullWalletUrl(user_index_), 350 MakeWalletRequest(GetGetFullWalletUrl(user_index_),
371 post_body, 351 post_body,
372 kFormEncodedMimeType); 352 kFormEncodedMimeType,
353 GET_FULL_WALLET);
373 } 354 }
374 355
375 void WalletClient::SaveToWallet(scoped_ptr<Instrument> instrument, 356 void WalletClient::SaveToWallet(
376 scoped_ptr<Address> address) { 357 scoped_ptr<Instrument> instrument,
358 scoped_ptr<Address> address,
359 const WalletItems::MaskedInstrument* reference_instrument,
360 const Address* reference_address) {
377 DCHECK(instrument || address); 361 DCHECK(instrument || address);
378 if (HasRequestInProgress()) {
379 pending_requests_.push(base::Bind(&WalletClient::SaveToWallet,
380 base::Unretained(this),
381 base::Passed(&instrument),
382 base::Passed(&address)));
383 return;
384 }
385
386 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
387 request_type_ = SAVE_TO_WALLET;
388 362
389 base::DictionaryValue request_dict; 363 base::DictionaryValue request_dict;
390 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey()); 364 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
391 request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData()); 365 request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData());
392 request_dict.SetString(kMerchantDomainKey, 366 request_dict.SetString(kMerchantDomainKey,
393 source_url_.GetWithEmptyPath().spec()); 367 source_url_.GetWithEmptyPath().spec());
394 request_dict.SetBoolean(kUseMinimalAddresses, false); 368 request_dict.SetBoolean(kUseMinimalAddresses, false);
395 request_dict.SetBoolean(kPhoneNumberRequired, true); 369 request_dict.SetBoolean(kPhoneNumberRequired, true);
396 370
397 std::string primary_account_number; 371 std::string primary_account_number;
398 std::string card_verification_number; 372 std::string card_verification_number;
399 if (instrument) { 373 if (instrument) {
400 primary_account_number = net::EscapeUrlEncodedData( 374 primary_account_number = net::EscapeUrlEncodedData(
401 UTF16ToUTF8(instrument->primary_account_number()), true); 375 UTF16ToUTF8(instrument->primary_account_number()), true);
402 card_verification_number = net::EscapeUrlEncodedData( 376 card_verification_number = net::EscapeUrlEncodedData(
403 UTF16ToUTF8(instrument->card_verification_number()), true); 377 UTF16ToUTF8(instrument->card_verification_number()), true);
404 378
405 if (instrument->object_id().empty()) { 379 if (!reference_instrument) {
406 request_dict.Set(kInstrumentKey, instrument->ToDictionary().release()); 380 request_dict.Set(kInstrumentKey, instrument->ToDictionary().release());
407 request_dict.SetString(kInstrumentPhoneNumberKey, 381 request_dict.SetString(kInstrumentPhoneNumberKey,
408 instrument->address()->phone_number()); 382 instrument->address()->phone_number());
409 } else { 383 } else {
410 DCHECK(instrument->address() || 384 DCHECK(!reference_instrument->object_id().empty());
411 (instrument->expiration_month() > 0 && 385
412 instrument->expiration_year() > 0)); 386 int new_month = instrument->expiration_month();
387 int new_year = instrument->expiration_year();
388 bool expiration_date_changed =
389 new_month != reference_instrument->expiration_month() ||
390 new_year != reference_instrument->expiration_year();
391
392 DCHECK(instrument->address() || expiration_date_changed);
413 393
414 request_dict.SetString(kUpgradedInstrumentIdKey, 394 request_dict.SetString(kUpgradedInstrumentIdKey,
415 instrument->object_id()); 395 reference_instrument->object_id());
416 396
417 if (instrument->address()) { 397 if (instrument->address()) {
418 request_dict.SetString(kInstrumentPhoneNumberKey, 398 request_dict.SetString(kInstrumentPhoneNumberKey,
419 instrument->address()->phone_number()); 399 instrument->address()->phone_number());
420 request_dict.Set( 400 request_dict.Set(
421 kUpgradedBillingAddressKey, 401 kUpgradedBillingAddressKey,
422 instrument->address()->ToDictionaryWithoutID().release()); 402 instrument->address()->ToDictionaryWithoutID().release());
423 } 403 }
424 404
425 if (instrument->expiration_month() > 0 && 405 if (expiration_date_changed) {
426 instrument->expiration_year() > 0) { 406 // Updating expiration date requires a CVC.
427 DCHECK(!instrument->card_verification_number().empty()); 407 DCHECK(!instrument->card_verification_number().empty());
428 request_dict.SetInteger(kInstrumentExpMonthKey, 408 request_dict.SetInteger(kInstrumentExpMonthKey,
429 instrument->expiration_month()); 409 instrument->expiration_month());
430 request_dict.SetInteger(kInstrumentExpYearKey, 410 request_dict.SetInteger(kInstrumentExpYearKey,
431 instrument->expiration_year()); 411 instrument->expiration_year());
432 } 412 }
433 413
434 if (request_dict.HasKey(kInstrumentKey)) 414 if (request_dict.HasKey(kInstrumentKey))
435 request_dict.SetString(kInstrumentType, "CREDIT_CARD"); 415 request_dict.SetString(kInstrumentType, "CREDIT_CARD");
436 } 416 }
437 } 417 }
438 if (address) { 418 if (address) {
419 if (reference_address) {
420 address->set_object_id(reference_address->object_id());
421 DCHECK(!address->object_id().empty());
422 }
439 request_dict.Set(kShippingAddressKey, 423 request_dict.Set(kShippingAddressKey,
440 address->ToDictionaryWithID().release()); 424 address->ToDictionaryWithID().release());
441 } 425 }
442 426
443 std::string json_payload; 427 std::string json_payload;
444 base::JSONWriter::Write(&request_dict, &json_payload); 428 base::JSONWriter::Write(&request_dict, &json_payload);
445 429
446 if (!card_verification_number.empty()) { 430 if (!card_verification_number.empty()) {
447 std::string post_body; 431 std::string post_body;
448 if (!primary_account_number.empty()) { 432 if (!primary_account_number.empty()) {
449 post_body = base::StringPrintf( 433 post_body = base::StringPrintf(
450 kEscrowNewInstrumentFormat, 434 kEscrowNewInstrumentFormat,
451 net::EscapeUrlEncodedData(json_payload, true).c_str(), 435 net::EscapeUrlEncodedData(json_payload, true).c_str(),
452 card_verification_number.c_str(), 436 card_verification_number.c_str(),
453 primary_account_number.c_str()); 437 primary_account_number.c_str());
454 } else { 438 } else {
455 post_body = base::StringPrintf( 439 post_body = base::StringPrintf(
456 kEscrowCardVerificationNumberFormat, 440 kEscrowCardVerificationNumberFormat,
457 net::EscapeUrlEncodedData(json_payload, true).c_str(), 441 net::EscapeUrlEncodedData(json_payload, true).c_str(),
458 card_verification_number.c_str()); 442 card_verification_number.c_str());
459 } 443 }
460 MakeWalletRequest(GetSaveToWalletUrl(user_index_), 444 MakeWalletRequest(GetSaveToWalletUrl(user_index_),
461 post_body, 445 post_body,
462 kFormEncodedMimeType); 446 kFormEncodedMimeType,
447 SAVE_TO_WALLET);
463 } else { 448 } else {
464 MakeWalletRequest(GetSaveToWalletNoEscrowUrl(user_index_), 449 MakeWalletRequest(GetSaveToWalletNoEscrowUrl(user_index_),
465 json_payload, 450 json_payload,
466 kJsonMimeType); 451 kJsonMimeType,
452 SAVE_TO_WALLET);
467 } 453 }
468 } 454 }
469 455
470 void WalletClient::GetWalletItems() { 456 void WalletClient::GetWalletItems() {
471 if (HasRequestInProgress()) {
472 pending_requests_.push(base::Bind(&WalletClient::GetWalletItems,
473 base::Unretained(this)));
474 return;
475 }
476
477 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
478 request_type_ = GET_WALLET_ITEMS;
479
480 base::DictionaryValue request_dict; 457 base::DictionaryValue request_dict;
481 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey()); 458 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
482 request_dict.SetString(kMerchantDomainKey, 459 request_dict.SetString(kMerchantDomainKey,
483 source_url_.GetWithEmptyPath().spec()); 460 source_url_.GetWithEmptyPath().spec());
484 request_dict.SetBoolean(kShippingAddressRequired, 461 request_dict.SetBoolean(kShippingAddressRequired,
485 delegate_->IsShippingAddressRequired()); 462 delegate_->IsShippingAddressRequired());
486 request_dict.SetBoolean(kUseMinimalAddresses, false); 463 request_dict.SetBoolean(kUseMinimalAddresses, false);
487 request_dict.SetBoolean(kPhoneNumberRequired, true); 464 request_dict.SetBoolean(kPhoneNumberRequired, true);
488 465
489 std::string post_body; 466 std::string post_body;
490 base::JSONWriter::Write(&request_dict, &post_body); 467 base::JSONWriter::Write(&request_dict, &post_body);
491 468
492 MakeWalletRequest(GetGetWalletItemsUrl(user_index_), 469 MakeWalletRequest(GetGetWalletItemsUrl(user_index_),
493 post_body, 470 post_body,
494 kJsonMimeType); 471 kJsonMimeType,
472 GET_WALLET_ITEMS);
495 } 473 }
496 474
497 bool WalletClient::HasRequestInProgress() const { 475 bool WalletClient::HasRequestInProgress() const {
498 return request_; 476 return request_;
499 } 477 }
500 478
501 void WalletClient::CancelRequests() { 479 void WalletClient::CancelRequests() {
502 request_.reset(); 480 request_.reset();
503 request_type_ = NO_PENDING_REQUEST; 481 request_type_ = NO_PENDING_REQUEST;
504 while (!pending_requests_.empty()) { 482 while (!pending_requests_.empty()) {
505 pending_requests_.pop(); 483 pending_requests_.pop();
506 } 484 }
507 } 485 }
508 486
509 void WalletClient::DoAcceptLegalDocuments( 487 void WalletClient::DoAcceptLegalDocuments(
510 const std::vector<std::string>& document_ids, 488 const std::vector<std::string>& document_ids,
511 const std::string& google_transaction_id) { 489 const std::string& google_transaction_id) {
512 if (HasRequestInProgress()) {
513 pending_requests_.push(base::Bind(&WalletClient::DoAcceptLegalDocuments,
514 base::Unretained(this),
515 document_ids,
516 google_transaction_id));
517 return;
518 }
519
520 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
521 request_type_ = ACCEPT_LEGAL_DOCUMENTS;
522
523 base::DictionaryValue request_dict; 490 base::DictionaryValue request_dict;
524 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey()); 491 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
525 request_dict.SetString(kGoogleTransactionIdKey, google_transaction_id); 492 request_dict.SetString(kGoogleTransactionIdKey, google_transaction_id);
526 request_dict.SetString(kMerchantDomainKey, 493 request_dict.SetString(kMerchantDomainKey,
527 source_url_.GetWithEmptyPath().spec()); 494 source_url_.GetWithEmptyPath().spec());
528 scoped_ptr<base::ListValue> docs_list(new base::ListValue()); 495 scoped_ptr<base::ListValue> docs_list(new base::ListValue());
529 for (std::vector<std::string>::const_iterator it = document_ids.begin(); 496 for (std::vector<std::string>::const_iterator it = document_ids.begin();
530 it != document_ids.end(); ++it) { 497 it != document_ids.end(); ++it) {
531 if (!it->empty()) 498 if (!it->empty())
532 docs_list->AppendString(*it); 499 docs_list->AppendString(*it);
533 } 500 }
534 request_dict.Set(kAcceptedLegalDocumentKey, docs_list.release()); 501 request_dict.Set(kAcceptedLegalDocumentKey, docs_list.release());
535 502
536 std::string post_body; 503 std::string post_body;
537 base::JSONWriter::Write(&request_dict, &post_body); 504 base::JSONWriter::Write(&request_dict, &post_body);
538 505
539 MakeWalletRequest(GetAcceptLegalDocumentsUrl(user_index_), 506 MakeWalletRequest(GetAcceptLegalDocumentsUrl(user_index_),
540 post_body, 507 post_body,
541 kJsonMimeType); 508 kJsonMimeType,
509 ACCEPT_LEGAL_DOCUMENTS);
542 } 510 }
543 511
544 void WalletClient::MakeWalletRequest(const GURL& url, 512 void WalletClient::MakeWalletRequest(const GURL& url,
545 const std::string& post_body, 513 const std::string& post_body,
546 const std::string& mime_type) { 514 const std::string& mime_type,
547 DCHECK(!HasRequestInProgress()); 515 RequestType request_type) {
516 if (HasRequestInProgress()) {
517 pending_requests_.push(base::Bind(&WalletClient::MakeWalletRequest,
518 base::Unretained(this),
519 url,
520 post_body,
521 mime_type,
522 request_type));
523 return;
524 }
525
526 DCHECK_EQ(request_type_, NO_PENDING_REQUEST);
527 request_type_ = request_type;
548 528
549 request_.reset(net::URLFetcher::Create( 529 request_.reset(net::URLFetcher::Create(
550 0, url, net::URLFetcher::POST, this)); 530 0, url, net::URLFetcher::POST, this));
551 request_->SetRequestContext(context_getter_.get()); 531 request_->SetRequestContext(context_getter_.get());
552 VLOG(1) << "Making request to " << url << " with post_body=" << post_body; 532 VLOG(1) << "Making request to " << url << " with post_body=" << post_body;
553 request_->SetUploadData(mime_type, post_body); 533 request_->SetUploadData(mime_type, post_body);
554 request_->AddExtraRequestHeader("Authorization: GoogleLogin auth=" + 534 request_->AddExtraRequestHeader("Authorization: GoogleLogin auth=" +
555 delegate_->GetWalletCookieValue()); 535 delegate_->GetWalletCookieValue());
556 DVLOG(1) << "Setting authorization header value to " 536 DVLOG(1) << "Setting authorization header value to "
557 << delegate_->GetWalletCookieValue(); 537 << delegate_->GetWalletCookieValue();
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 NOTREACHED(); 801 NOTREACHED();
822 return AutofillMetrics::UNKNOWN_API_CALL; 802 return AutofillMetrics::UNKNOWN_API_CALL;
823 } 803 }
824 804
825 NOTREACHED(); 805 NOTREACHED();
826 return AutofillMetrics::UNKNOWN_API_CALL; 806 return AutofillMetrics::UNKNOWN_API_CALL;
827 } 807 }
828 808
829 } // namespace wallet 809 } // namespace wallet
830 } // namespace autofill 810 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698