Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 int response_code = source->GetResponseCode(); | 571 int response_code = source->GetResponseCode(); |
| 572 delegate_->GetMetricLogger().LogWalletResponseCode(response_code); | 572 delegate_->GetMetricLogger().LogWalletResponseCode(response_code); |
| 573 | 573 |
| 574 switch (response_code) { | 574 switch (response_code) { |
| 575 // HTTP_BAD_REQUEST means the arguments are invalid. No point retrying. | 575 // HTTP_BAD_REQUEST means the arguments are invalid. No point retrying. |
| 576 case net::HTTP_BAD_REQUEST: { | 576 case net::HTTP_BAD_REQUEST: { |
| 577 request_type_ = NO_REQUEST; | 577 request_type_ = NO_REQUEST; |
| 578 HandleWalletError(BAD_REQUEST); | 578 HandleWalletError(BAD_REQUEST); |
| 579 return; | 579 return; |
| 580 } | 580 } |
| 581 // HTTP_OK holds a valid response and HTTP_INTERNAL_SERVER_ERROR holds an | 581 |
| 582 // error code and message for the user. | 582 // Valid response. |
| 583 case net::HTTP_OK: | 583 case net::HTTP_OK: { |
| 584 scoped_ptr<base::Value> message_value(base::JSONReader::Read(data)); | |
| 585 if (message_value.get() && | |
| 586 message_value->IsType(base::Value::TYPE_DICTIONARY)) { | |
| 587 response_dict.reset( | |
| 588 static_cast<base::DictionaryValue*>(message_value.release())); | |
| 589 } | |
| 590 break; | |
| 591 } | |
| 592 | |
| 593 // Response contains an error to show the user. | |
| 594 case net::HTTP_FORBIDDEN: | |
| 584 case net::HTTP_INTERNAL_SERVER_ERROR: { | 595 case net::HTTP_INTERNAL_SERVER_ERROR: { |
| 585 scoped_ptr<base::Value> message_value(base::JSONReader::Read(data)); | 596 scoped_ptr<base::Value> message_value(base::JSONReader::Read(data)); |
| 586 if (message_value.get() && | 597 if (message_value.get() && |
| 587 message_value->IsType(base::Value::TYPE_DICTIONARY)) { | 598 message_value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 588 response_dict.reset( | 599 response_dict.reset( |
| 589 static_cast<base::DictionaryValue*>(message_value.release())); | 600 static_cast<base::DictionaryValue*>(message_value.release())); |
| 590 } | 601 } |
| 591 if (response_code == net::HTTP_INTERNAL_SERVER_ERROR) { | |
|
Evan Stade
2014/09/02 16:41:26
no changes to this block of code --- just changed
| |
| 592 request_type_ = NO_REQUEST; | |
| 593 | 602 |
| 594 std::string error_type_string; | 603 request_type_ = NO_REQUEST; |
| 595 if (!response_dict->GetString(kErrorTypeKey, &error_type_string)) { | |
| 596 HandleWalletError(UNKNOWN_ERROR); | |
| 597 return; | |
| 598 } | |
| 599 WalletClient::ErrorType error_type = | |
| 600 StringToErrorType(error_type_string); | |
| 601 if (error_type == BUYER_ACCOUNT_ERROR) { | |
| 602 // If the error_type is |BUYER_ACCOUNT_ERROR|, then | |
| 603 // message_type_for_buyer field contains more specific information | |
| 604 // about the error. | |
| 605 std::string message_type_for_buyer_string; | |
| 606 if (response_dict->GetString(kMessageTypeForBuyerKey, | |
| 607 &message_type_for_buyer_string)) { | |
| 608 error_type = BuyerErrorStringToErrorType( | |
| 609 message_type_for_buyer_string); | |
| 610 } | |
| 611 } | |
| 612 | 604 |
| 613 HandleWalletError(error_type); | 605 std::string error_type_string; |
| 606 if (!response_dict->GetString(kErrorTypeKey, &error_type_string)) { | |
| 607 HandleWalletError(UNKNOWN_ERROR); | |
| 614 return; | 608 return; |
| 615 } | 609 } |
| 616 break; | 610 WalletClient::ErrorType error_type = |
| 611 StringToErrorType(error_type_string); | |
|
Dan Beam
2014/09/04 01:04:19
unwrap
Evan Stade
2014/09/04 18:16:19
Done.
| |
| 612 if (error_type == BUYER_ACCOUNT_ERROR) { | |
| 613 // If the error_type is |BUYER_ACCOUNT_ERROR|, then | |
| 614 // message_type_for_buyer field contains more specific information | |
| 615 // about the error. | |
| 616 std::string message_type_for_buyer_string; | |
| 617 if (response_dict->GetString(kMessageTypeForBuyerKey, | |
| 618 &message_type_for_buyer_string)) { | |
| 619 error_type = BuyerErrorStringToErrorType( | |
| 620 message_type_for_buyer_string); | |
| 621 } | |
| 622 } | |
| 623 | |
| 624 HandleWalletError(error_type); | |
| 625 return; | |
| 617 } | 626 } |
| 618 | 627 |
| 619 // Anything else is an error. | 628 // Handle anything else as a generic error. |
| 620 default: | 629 default: |
| 621 request_type_ = NO_REQUEST; | 630 request_type_ = NO_REQUEST; |
| 622 HandleWalletError(NETWORK_ERROR); | 631 HandleWalletError(NETWORK_ERROR); |
| 623 return; | 632 return; |
| 624 } | 633 } |
| 625 | 634 |
| 626 RequestType type = request_type_; | 635 RequestType type = request_type_; |
| 627 request_type_ = NO_REQUEST; | 636 request_type_ = NO_REQUEST; |
| 628 | 637 |
| 629 if (type != ACCEPT_LEGAL_DOCUMENTS && !response_dict) { | 638 if (type != ACCEPT_LEGAL_DOCUMENTS && !response_dict) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 792 NOTREACHED(); | 801 NOTREACHED(); |
| 793 return AutofillMetrics::UNKNOWN_API_CALL; | 802 return AutofillMetrics::UNKNOWN_API_CALL; |
| 794 } | 803 } |
| 795 | 804 |
| 796 NOTREACHED(); | 805 NOTREACHED(); |
| 797 return AutofillMetrics::UNKNOWN_API_CALL; | 806 return AutofillMetrics::UNKNOWN_API_CALL; |
| 798 } | 807 } |
| 799 | 808 |
| 800 } // namespace wallet | 809 } // namespace wallet |
| 801 } // namespace autofill | 810 } // namespace autofill |
| OLD | NEW |