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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/content/browser/wallet/wallet_client.cc
diff --git a/components/autofill/content/browser/wallet/wallet_client.cc b/components/autofill/content/browser/wallet/wallet_client.cc
index 30fd6186abc7d722691239ed852b332db559d0f7..b00a4f0fea7ca824b07ac648763ba24c84bf8b85 100644
--- a/components/autofill/content/browser/wallet/wallet_client.cc
+++ b/components/autofill/content/browser/wallet/wallet_client.cc
@@ -283,17 +283,6 @@ void WalletClient::AcceptLegalDocuments(
void WalletClient::AuthenticateInstrument(
const std::string& instrument_id,
const std::string& card_verification_number) {
- if (HasRequestInProgress()) {
- pending_requests_.push(base::Bind(&WalletClient::AuthenticateInstrument,
- base::Unretained(this),
- instrument_id,
- card_verification_number));
- return;
- }
-
- DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
- request_type_ = AUTHENTICATE_INSTRUMENT;
-
base::DictionaryValue request_dict;
request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData());
@@ -312,20 +301,11 @@ void WalletClient::AuthenticateInstrument(
MakeWalletRequest(GetAuthenticateInstrumentUrl(user_index_),
post_body,
- kFormEncodedMimeType);
+ kFormEncodedMimeType,
+ AUTHENTICATE_INSTRUMENT);
}
void WalletClient::GetFullWallet(const FullWalletRequest& full_wallet_request) {
- if (HasRequestInProgress()) {
- pending_requests_.push(base::Bind(&WalletClient::GetFullWallet,
- base::Unretained(this),
- full_wallet_request));
- return;
- }
-
- DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
- request_type_ = GET_FULL_WALLET;
-
base::DictionaryValue request_dict;
request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData());
@@ -369,22 +349,16 @@ void WalletClient::GetFullWallet(const FullWalletRequest& full_wallet_request) {
MakeWalletRequest(GetGetFullWalletUrl(user_index_),
post_body,
- kFormEncodedMimeType);
+ kFormEncodedMimeType,
+ GET_FULL_WALLET);
}
-void WalletClient::SaveToWallet(scoped_ptr<Instrument> instrument,
- scoped_ptr<Address> address) {
+void WalletClient::SaveToWallet(
+ scoped_ptr<Instrument> instrument,
+ scoped_ptr<Address> address,
+ const WalletItems::MaskedInstrument* reference_instrument,
+ const Address* reference_address) {
DCHECK(instrument || address);
- if (HasRequestInProgress()) {
- pending_requests_.push(base::Bind(&WalletClient::SaveToWallet,
- base::Unretained(this),
- base::Passed(&instrument),
- base::Passed(&address)));
- return;
- }
-
- DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
- request_type_ = SAVE_TO_WALLET;
base::DictionaryValue request_dict;
request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
@@ -402,17 +376,23 @@ void WalletClient::SaveToWallet(scoped_ptr<Instrument> instrument,
card_verification_number = net::EscapeUrlEncodedData(
UTF16ToUTF8(instrument->card_verification_number()), true);
- if (instrument->object_id().empty()) {
+ if (!reference_instrument) {
request_dict.Set(kInstrumentKey, instrument->ToDictionary().release());
request_dict.SetString(kInstrumentPhoneNumberKey,
instrument->address()->phone_number());
} else {
- DCHECK(instrument->address() ||
- (instrument->expiration_month() > 0 &&
- instrument->expiration_year() > 0));
+ DCHECK(!reference_instrument->object_id().empty());
+
+ int new_month = instrument->expiration_month();
+ int new_year = instrument->expiration_year();
+ bool expiration_date_changed =
+ new_month != reference_instrument->expiration_month() ||
+ new_year != reference_instrument->expiration_year();
+
+ DCHECK(instrument->address() || expiration_date_changed);
request_dict.SetString(kUpgradedInstrumentIdKey,
- instrument->object_id());
+ reference_instrument->object_id());
if (instrument->address()) {
request_dict.SetString(kInstrumentPhoneNumberKey,
@@ -422,8 +402,8 @@ void WalletClient::SaveToWallet(scoped_ptr<Instrument> instrument,
instrument->address()->ToDictionaryWithoutID().release());
}
- if (instrument->expiration_month() > 0 &&
- instrument->expiration_year() > 0) {
+ if (expiration_date_changed) {
+ // Updating expiration date requires a CVC.
DCHECK(!instrument->card_verification_number().empty());
request_dict.SetInteger(kInstrumentExpMonthKey,
instrument->expiration_month());
@@ -436,6 +416,10 @@ void WalletClient::SaveToWallet(scoped_ptr<Instrument> instrument,
}
}
if (address) {
+ if (reference_address) {
+ address->set_object_id(reference_address->object_id());
+ DCHECK(!address->object_id().empty());
+ }
request_dict.Set(kShippingAddressKey,
address->ToDictionaryWithID().release());
}
@@ -459,24 +443,17 @@ void WalletClient::SaveToWallet(scoped_ptr<Instrument> instrument,
}
MakeWalletRequest(GetSaveToWalletUrl(user_index_),
post_body,
- kFormEncodedMimeType);
+ kFormEncodedMimeType,
+ SAVE_TO_WALLET);
} else {
MakeWalletRequest(GetSaveToWalletNoEscrowUrl(user_index_),
json_payload,
- kJsonMimeType);
+ kJsonMimeType,
+ SAVE_TO_WALLET);
}
}
void WalletClient::GetWalletItems() {
- if (HasRequestInProgress()) {
- pending_requests_.push(base::Bind(&WalletClient::GetWalletItems,
- base::Unretained(this)));
- return;
- }
-
- DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
- request_type_ = GET_WALLET_ITEMS;
-
base::DictionaryValue request_dict;
request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
request_dict.SetString(kMerchantDomainKey,
@@ -491,7 +468,8 @@ void WalletClient::GetWalletItems() {
MakeWalletRequest(GetGetWalletItemsUrl(user_index_),
post_body,
- kJsonMimeType);
+ kJsonMimeType,
+ GET_WALLET_ITEMS);
}
bool WalletClient::HasRequestInProgress() const {
@@ -509,17 +487,6 @@ void WalletClient::CancelRequests() {
void WalletClient::DoAcceptLegalDocuments(
const std::vector<std::string>& document_ids,
const std::string& google_transaction_id) {
- if (HasRequestInProgress()) {
- pending_requests_.push(base::Bind(&WalletClient::DoAcceptLegalDocuments,
- base::Unretained(this),
- document_ids,
- google_transaction_id));
- return;
- }
-
- DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
- request_type_ = ACCEPT_LEGAL_DOCUMENTS;
-
base::DictionaryValue request_dict;
request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
request_dict.SetString(kGoogleTransactionIdKey, google_transaction_id);
@@ -538,13 +505,26 @@ void WalletClient::DoAcceptLegalDocuments(
MakeWalletRequest(GetAcceptLegalDocumentsUrl(user_index_),
post_body,
- kJsonMimeType);
+ kJsonMimeType,
+ ACCEPT_LEGAL_DOCUMENTS);
}
void WalletClient::MakeWalletRequest(const GURL& url,
const std::string& post_body,
- const std::string& mime_type) {
- DCHECK(!HasRequestInProgress());
+ const std::string& mime_type,
+ RequestType request_type) {
+ if (HasRequestInProgress()) {
+ pending_requests_.push(base::Bind(&WalletClient::MakeWalletRequest,
+ base::Unretained(this),
+ url,
+ post_body,
+ mime_type,
+ request_type));
+ return;
+ }
+
+ DCHECK_EQ(request_type_, NO_PENDING_REQUEST);
+ request_type_ = request_type;
request_.reset(net::URLFetcher::Create(
0, url, net::URLFetcher::POST, this));

Powered by Google App Engine
This is Rietveld 408576698