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

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

Issue 23033016: Remove autocheckout code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 const size_t kOneTimePadLength = 6; 45 const size_t kOneTimePadLength = 6;
46 46
47 // The maximum number of bits in the one time pad that the server is willing to 47 // The maximum number of bits in the one time pad that the server is willing to
48 // accept. 48 // accept.
49 const size_t kMaxBits = 56; 49 const size_t kMaxBits = 56;
50 50
51 // The minimum number of bits in the one time pad that the server is willing to 51 // The minimum number of bits in the one time pad that the server is willing to
52 // accept. 52 // accept.
53 const size_t kMinBits = 40; 53 const size_t kMinBits = 40;
54 54
55 std::string AutocheckoutStatusToString(AutocheckoutStatus status) {
56 switch (status) {
57 case MISSING_FIELDMAPPING:
58 return "MISSING_FIELDMAPPING";
59 case MISSING_ADVANCE:
60 return "MISSING_ADVANCE";
61 case MISSING_CLICK_ELEMENT_BEFORE_FORM_FILLING:
62 return "MISSING_CLICK_ELEMENT_BEFORE_FORM_FILLING";
63 case MISSING_CLICK_ELEMENT_AFTER_FORM_FILLING:
64 return "MISSING_CLICK_ELEMENT_AFTER_FORM_FILLING";
65 case CANNOT_PROCEED:
66 return "CANNOT_PROCEED";
67 case SUCCESS:
68 // SUCCESS cannot be sent to the server as it will result in a failure.
69 NOTREACHED();
70 return "ERROR";
71 case AUTOCHECKOUT_STATUS_NUM_STATUS:
72 NOTREACHED();
73 }
74 NOTREACHED();
75 return "NOT_POSSIBLE";
76 }
77
78 std::string DialogTypeToFeatureString(autofill::DialogType dialog_type) { 55 std::string DialogTypeToFeatureString(autofill::DialogType dialog_type) {
79 switch (dialog_type) { 56 switch (dialog_type) {
80 case DIALOG_TYPE_REQUEST_AUTOCOMPLETE: 57 case DIALOG_TYPE_REQUEST_AUTOCOMPLETE:
81 return "REQUEST_AUTOCOMPLETE"; 58 return "REQUEST_AUTOCOMPLETE";
82 case DIALOG_TYPE_AUTOCHECKOUT: 59 case DIALOG_TYPE_AUTOCHECKOUT:
83 return "AUTOCHECKOUT"; 60 return "AUTOCHECKOUT";
84 } 61 }
85 NOTREACHED(); 62 NOTREACHED();
86 return "NOT_POSSIBLE"; 63 return "NOT_POSSIBLE";
87 } 64 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 const char kPhoneNumberRequired[] = "phone_number_required"; 238 const char kPhoneNumberRequired[] = "phone_number_required";
262 const char kReasonKey[] = "reason"; 239 const char kReasonKey[] = "reason";
263 const char kRiskCapabilitiesKey[] = "supported_risk_challenge"; 240 const char kRiskCapabilitiesKey[] = "supported_risk_challenge";
264 const char kRiskParamsKey[] = "risk_params"; 241 const char kRiskParamsKey[] = "risk_params";
265 const char kSelectedAddressIdKey[] = "selected_address_id"; 242 const char kSelectedAddressIdKey[] = "selected_address_id";
266 const char kSelectedInstrumentIdKey[] = "selected_instrument_id"; 243 const char kSelectedInstrumentIdKey[] = "selected_instrument_id";
267 const char kSessionMaterialKey[] = "session_material"; 244 const char kSessionMaterialKey[] = "session_material";
268 const char kShippingAddressIdKey[] = "shipping_address_id"; 245 const char kShippingAddressIdKey[] = "shipping_address_id";
269 const char kShippingAddressKey[] = "shipping_address"; 246 const char kShippingAddressKey[] = "shipping_address";
270 const char kShippingAddressRequired[] = "shipping_address_required"; 247 const char kShippingAddressRequired[] = "shipping_address_required";
271 const char kAutocheckoutStepsKey[] = "steps";
272 const char kSuccessKey[] = "success"; 248 const char kSuccessKey[] = "success";
273 const char kUpgradedBillingAddressKey[] = "upgraded_billing_address"; 249 const char kUpgradedBillingAddressKey[] = "upgraded_billing_address";
274 const char kUpgradedInstrumentIdKey[] = "upgraded_instrument_id"; 250 const char kUpgradedInstrumentIdKey[] = "upgraded_instrument_id";
275 const char kUseMinimalAddresses[] = "use_minimal_addresses"; 251 const char kUseMinimalAddresses[] = "use_minimal_addresses";
276 252
277 } // namespace 253 } // namespace
278 254
279 WalletClient::FullWalletRequest::FullWalletRequest( 255 WalletClient::FullWalletRequest::FullWalletRequest(
280 const std::string& instrument_id, 256 const std::string& instrument_id,
281 const std::string& address_id, 257 const std::string& address_id,
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 delegate_->IsShippingAddressRequired()); 497 delegate_->IsShippingAddressRequired());
522 request_dict.SetBoolean(kUseMinimalAddresses, false); 498 request_dict.SetBoolean(kUseMinimalAddresses, false);
523 request_dict.SetBoolean(kPhoneNumberRequired, true); 499 request_dict.SetBoolean(kPhoneNumberRequired, true);
524 500
525 std::string post_body; 501 std::string post_body;
526 base::JSONWriter::Write(&request_dict, &post_body); 502 base::JSONWriter::Write(&request_dict, &post_body);
527 503
528 MakeWalletRequest(GetGetWalletItemsUrl(), post_body, kJsonMimeType); 504 MakeWalletRequest(GetGetWalletItemsUrl(), post_body, kJsonMimeType);
529 } 505 }
530 506
531 void WalletClient::SendAutocheckoutStatus(
532 AutocheckoutStatus status,
533 const GURL& source_url,
534 const std::vector<AutocheckoutStatistic>& latency_statistics,
535 const std::string& google_transaction_id) {
536 DVLOG(1) << "Sending Autocheckout Status: " << status
537 << " for: " << source_url;
538 if (HasRequestInProgress()) {
539 pending_requests_.push(base::Bind(&WalletClient::SendAutocheckoutStatus,
540 base::Unretained(this),
541 status,
542 source_url,
543 latency_statistics,
544 google_transaction_id));
545 return;
546 }
547
548 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
549 request_type_ = SEND_STATUS;
550
551 base::DictionaryValue request_dict;
552 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
553 bool success = status == SUCCESS;
554 request_dict.SetBoolean(kSuccessKey, success);
555 request_dict.SetString(kMerchantDomainKey,
556 source_url.GetWithEmptyPath().spec());
557 if (!success)
558 request_dict.SetString(kReasonKey, AutocheckoutStatusToString(status));
559 if (!latency_statistics.empty()) {
560 scoped_ptr<base::ListValue> latency_statistics_json(
561 new base::ListValue());
562 for (size_t i = 0; i < latency_statistics.size(); ++i) {
563 latency_statistics_json->Append(
564 latency_statistics[i].ToDictionary().release());
565 }
566 request_dict.Set(kAutocheckoutStepsKey,
567 latency_statistics_json.release());
568 }
569 request_dict.SetString(kGoogleTransactionIdKey, google_transaction_id);
570
571 std::string post_body;
572 base::JSONWriter::Write(&request_dict, &post_body);
573
574 MakeWalletRequest(GetSendStatusUrl(), post_body, kJsonMimeType);
575 }
576
577 bool WalletClient::HasRequestInProgress() const { 507 bool WalletClient::HasRequestInProgress() const {
578 return request_; 508 return request_;
579 } 509 }
580 510
581 void WalletClient::CancelRequests() { 511 void WalletClient::CancelRequests() {
582 request_.reset(); 512 request_.reset();
583 request_type_ = NO_PENDING_REQUEST; 513 request_type_ = NO_PENDING_REQUEST;
584 while (!pending_requests_.empty()) { 514 while (!pending_requests_.empty()) {
585 pending_requests_.pop(); 515 pending_requests_.pop();
586 } 516 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 // Anything else is an error. 651 // Anything else is an error.
722 default: 652 default:
723 request_type_ = NO_PENDING_REQUEST; 653 request_type_ = NO_PENDING_REQUEST;
724 HandleWalletError(NETWORK_ERROR); 654 HandleWalletError(NETWORK_ERROR);
725 return; 655 return;
726 } 656 }
727 657
728 RequestType type = request_type_; 658 RequestType type = request_type_;
729 request_type_ = NO_PENDING_REQUEST; 659 request_type_ = NO_PENDING_REQUEST;
730 660
731 if (!(type == ACCEPT_LEGAL_DOCUMENTS || type == SEND_STATUS) && 661 if (type != ACCEPT_LEGAL_DOCUMENTS && !response_dict) {
732 !response_dict) {
733 HandleMalformedResponse(scoped_request.get()); 662 HandleMalformedResponse(scoped_request.get());
734 return; 663 return;
735 } 664 }
736 665
737 switch (type) { 666 switch (type) {
738 case ACCEPT_LEGAL_DOCUMENTS: 667 case ACCEPT_LEGAL_DOCUMENTS:
739 delegate_->OnDidAcceptLegalDocuments(); 668 delegate_->OnDidAcceptLegalDocuments();
740 break; 669 break;
741 670
742 case AUTHENTICATE_INSTRUMENT: { 671 case AUTHENTICATE_INSTRUMENT: {
743 std::string auth_result; 672 std::string auth_result;
744 if (response_dict->GetString(kAuthResultKey, &auth_result)) { 673 if (response_dict->GetString(kAuthResultKey, &auth_result)) {
745 std::string trimmed; 674 std::string trimmed;
746 TrimWhitespaceASCII(auth_result, 675 TrimWhitespaceASCII(auth_result,
747 TRIM_ALL, 676 TRIM_ALL,
748 &trimmed); 677 &trimmed);
749 delegate_->OnDidAuthenticateInstrument( 678 delegate_->OnDidAuthenticateInstrument(
750 LowerCaseEqualsASCII(trimmed, "success")); 679 LowerCaseEqualsASCII(trimmed, "success"));
751 } else { 680 } else {
752 HandleMalformedResponse(scoped_request.get()); 681 HandleMalformedResponse(scoped_request.get());
753 } 682 }
754 break; 683 break;
755 } 684 }
756 685
757 case SEND_STATUS:
758 break;
759
760 case GET_FULL_WALLET: { 686 case GET_FULL_WALLET: {
761 scoped_ptr<FullWallet> full_wallet( 687 scoped_ptr<FullWallet> full_wallet(
762 FullWallet::CreateFullWallet(*response_dict)); 688 FullWallet::CreateFullWallet(*response_dict));
763 if (full_wallet) { 689 if (full_wallet) {
764 full_wallet->set_one_time_pad(one_time_pad_); 690 full_wallet->set_one_time_pad(one_time_pad_);
765 LogRequiredActions(full_wallet->required_actions()); 691 LogRequiredActions(full_wallet->required_actions());
766 delegate_->OnDidGetFullWallet(full_wallet.Pass()); 692 delegate_->OnDidGetFullWallet(full_wallet.Pass());
767 } else { 693 } else {
768 HandleMalformedResponse(scoped_request.get()); 694 HandleMalformedResponse(scoped_request.get());
769 } 695 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 case ACCEPT_LEGAL_DOCUMENTS: 815 case ACCEPT_LEGAL_DOCUMENTS:
890 return AutofillMetrics::ACCEPT_LEGAL_DOCUMENTS; 816 return AutofillMetrics::ACCEPT_LEGAL_DOCUMENTS;
891 case AUTHENTICATE_INSTRUMENT: 817 case AUTHENTICATE_INSTRUMENT:
892 return AutofillMetrics::AUTHENTICATE_INSTRUMENT; 818 return AutofillMetrics::AUTHENTICATE_INSTRUMENT;
893 case GET_FULL_WALLET: 819 case GET_FULL_WALLET:
894 return AutofillMetrics::GET_FULL_WALLET; 820 return AutofillMetrics::GET_FULL_WALLET;
895 case GET_WALLET_ITEMS: 821 case GET_WALLET_ITEMS:
896 return AutofillMetrics::GET_WALLET_ITEMS; 822 return AutofillMetrics::GET_WALLET_ITEMS;
897 case SAVE_TO_WALLET: 823 case SAVE_TO_WALLET:
898 return AutofillMetrics::SAVE_TO_WALLET; 824 return AutofillMetrics::SAVE_TO_WALLET;
899 case SEND_STATUS:
900 return AutofillMetrics::SEND_STATUS;
901 case NO_PENDING_REQUEST: 825 case NO_PENDING_REQUEST:
902 NOTREACHED(); 826 NOTREACHED();
903 return AutofillMetrics::UNKNOWN_API_CALL; 827 return AutofillMetrics::UNKNOWN_API_CALL;
904 } 828 }
905 829
906 NOTREACHED(); 830 NOTREACHED();
907 return AutofillMetrics::UNKNOWN_API_CALL; 831 return AutofillMetrics::UNKNOWN_API_CALL;
908 } 832 }
909 833
910 } // namespace wallet 834 } // namespace wallet
911 } // namespace autofill 835 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698