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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 const char kPhoneNumberRequired[] = "phone_number_required"; | 239 const char kPhoneNumberRequired[] = "phone_number_required"; |
263 const char kReasonKey[] = "reason"; | 240 const char kReasonKey[] = "reason"; |
264 const char kRiskCapabilitiesKey[] = "supported_risk_challenge"; | 241 const char kRiskCapabilitiesKey[] = "supported_risk_challenge"; |
265 const char kRiskParamsKey[] = "risk_params"; | 242 const char kRiskParamsKey[] = "risk_params"; |
266 const char kSelectedAddressIdKey[] = "selected_address_id"; | 243 const char kSelectedAddressIdKey[] = "selected_address_id"; |
267 const char kSelectedInstrumentIdKey[] = "selected_instrument_id"; | 244 const char kSelectedInstrumentIdKey[] = "selected_instrument_id"; |
268 const char kSessionMaterialKey[] = "session_material"; | 245 const char kSessionMaterialKey[] = "session_material"; |
269 const char kShippingAddressIdKey[] = "shipping_address_id"; | 246 const char kShippingAddressIdKey[] = "shipping_address_id"; |
270 const char kShippingAddressKey[] = "shipping_address"; | 247 const char kShippingAddressKey[] = "shipping_address"; |
271 const char kShippingAddressRequired[] = "shipping_address_required"; | 248 const char kShippingAddressRequired[] = "shipping_address_required"; |
272 const char kAutocheckoutStepsKey[] = "steps"; | |
273 const char kSuccessKey[] = "success"; | 249 const char kSuccessKey[] = "success"; |
274 const char kUpgradedBillingAddressKey[] = "upgraded_billing_address"; | 250 const char kUpgradedBillingAddressKey[] = "upgraded_billing_address"; |
275 const char kUpgradedInstrumentIdKey[] = "upgraded_instrument_id"; | 251 const char kUpgradedInstrumentIdKey[] = "upgraded_instrument_id"; |
276 const char kUseMinimalAddresses[] = "use_minimal_addresses"; | 252 const char kUseMinimalAddresses[] = "use_minimal_addresses"; |
277 | 253 |
278 } // namespace | 254 } // namespace |
279 | 255 |
280 WalletClient::FullWalletRequest::FullWalletRequest( | 256 WalletClient::FullWalletRequest::FullWalletRequest( |
281 const std::string& instrument_id, | 257 const std::string& instrument_id, |
282 const std::string& address_id, | 258 const std::string& address_id, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 delegate_->IsShippingAddressRequired()); | 501 delegate_->IsShippingAddressRequired()); |
526 request_dict.SetBoolean(kUseMinimalAddresses, false); | 502 request_dict.SetBoolean(kUseMinimalAddresses, false); |
527 request_dict.SetBoolean(kPhoneNumberRequired, true); | 503 request_dict.SetBoolean(kPhoneNumberRequired, true); |
528 | 504 |
529 std::string post_body; | 505 std::string post_body; |
530 base::JSONWriter::Write(&request_dict, &post_body); | 506 base::JSONWriter::Write(&request_dict, &post_body); |
531 | 507 |
532 MakeWalletRequest(GetGetWalletItemsUrl(), post_body, kJsonMimeType); | 508 MakeWalletRequest(GetGetWalletItemsUrl(), post_body, kJsonMimeType); |
533 } | 509 } |
534 | 510 |
535 void WalletClient::SendAutocheckoutStatus( | |
536 AutocheckoutStatus status, | |
537 const GURL& source_url, | |
538 const std::vector<AutocheckoutStatistic>& latency_statistics, | |
539 const std::string& google_transaction_id) { | |
540 DVLOG(1) << "Sending Autocheckout Status: " << status | |
541 << " for: " << source_url; | |
542 if (HasRequestInProgress()) { | |
543 pending_requests_.push(base::Bind(&WalletClient::SendAutocheckoutStatus, | |
544 base::Unretained(this), | |
545 status, | |
546 source_url, | |
547 latency_statistics, | |
548 google_transaction_id)); | |
549 return; | |
550 } | |
551 | |
552 DCHECK_EQ(NO_PENDING_REQUEST, request_type_); | |
553 request_type_ = SEND_STATUS; | |
554 | |
555 base::DictionaryValue request_dict; | |
556 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey()); | |
557 bool success = status == SUCCESS; | |
558 request_dict.SetBoolean(kSuccessKey, success); | |
559 request_dict.SetString(kMerchantDomainKey, | |
560 source_url.GetWithEmptyPath().spec()); | |
561 if (!success) | |
562 request_dict.SetString(kReasonKey, AutocheckoutStatusToString(status)); | |
563 if (!latency_statistics.empty()) { | |
564 scoped_ptr<base::ListValue> latency_statistics_json( | |
565 new base::ListValue()); | |
566 for (size_t i = 0; i < latency_statistics.size(); ++i) { | |
567 latency_statistics_json->Append( | |
568 latency_statistics[i].ToDictionary().release()); | |
569 } | |
570 request_dict.Set(kAutocheckoutStepsKey, | |
571 latency_statistics_json.release()); | |
572 } | |
573 request_dict.SetString(kGoogleTransactionIdKey, google_transaction_id); | |
574 | |
575 std::string post_body; | |
576 base::JSONWriter::Write(&request_dict, &post_body); | |
577 | |
578 MakeWalletRequest(GetSendStatusUrl(), post_body, kJsonMimeType); | |
579 } | |
580 | |
581 bool WalletClient::HasRequestInProgress() const { | 511 bool WalletClient::HasRequestInProgress() const { |
582 return request_; | 512 return request_; |
583 } | 513 } |
584 | 514 |
585 void WalletClient::CancelRequests() { | 515 void WalletClient::CancelRequests() { |
586 request_.reset(); | 516 request_.reset(); |
587 request_type_ = NO_PENDING_REQUEST; | 517 request_type_ = NO_PENDING_REQUEST; |
588 while (!pending_requests_.empty()) { | 518 while (!pending_requests_.empty()) { |
589 pending_requests_.pop(); | 519 pending_requests_.pop(); |
590 } | 520 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 // Anything else is an error. | 655 // Anything else is an error. |
726 default: | 656 default: |
727 request_type_ = NO_PENDING_REQUEST; | 657 request_type_ = NO_PENDING_REQUEST; |
728 HandleWalletError(NETWORK_ERROR); | 658 HandleWalletError(NETWORK_ERROR); |
729 return; | 659 return; |
730 } | 660 } |
731 | 661 |
732 RequestType type = request_type_; | 662 RequestType type = request_type_; |
733 request_type_ = NO_PENDING_REQUEST; | 663 request_type_ = NO_PENDING_REQUEST; |
734 | 664 |
735 if (!(type == ACCEPT_LEGAL_DOCUMENTS || type == SEND_STATUS) && | 665 if (type != ACCEPT_LEGAL_DOCUMENTS && !response_dict) { |
736 !response_dict) { | |
737 HandleMalformedResponse(scoped_request.get()); | 666 HandleMalformedResponse(scoped_request.get()); |
738 return; | 667 return; |
739 } | 668 } |
740 | 669 |
741 switch (type) { | 670 switch (type) { |
742 case ACCEPT_LEGAL_DOCUMENTS: | 671 case ACCEPT_LEGAL_DOCUMENTS: |
743 delegate_->OnDidAcceptLegalDocuments(); | 672 delegate_->OnDidAcceptLegalDocuments(); |
744 break; | 673 break; |
745 | 674 |
746 case AUTHENTICATE_INSTRUMENT: { | 675 case AUTHENTICATE_INSTRUMENT: { |
747 std::string auth_result; | 676 std::string auth_result; |
748 if (response_dict->GetString(kAuthResultKey, &auth_result)) { | 677 if (response_dict->GetString(kAuthResultKey, &auth_result)) { |
749 std::string trimmed; | 678 std::string trimmed; |
750 TrimWhitespaceASCII(auth_result, | 679 TrimWhitespaceASCII(auth_result, |
751 TRIM_ALL, | 680 TRIM_ALL, |
752 &trimmed); | 681 &trimmed); |
753 delegate_->OnDidAuthenticateInstrument( | 682 delegate_->OnDidAuthenticateInstrument( |
754 LowerCaseEqualsASCII(trimmed, "success")); | 683 LowerCaseEqualsASCII(trimmed, "success")); |
755 } else { | 684 } else { |
756 HandleMalformedResponse(scoped_request.get()); | 685 HandleMalformedResponse(scoped_request.get()); |
757 } | 686 } |
758 break; | 687 break; |
759 } | 688 } |
760 | 689 |
761 case SEND_STATUS: | |
762 break; | |
763 | |
764 case GET_FULL_WALLET: { | 690 case GET_FULL_WALLET: { |
765 scoped_ptr<FullWallet> full_wallet( | 691 scoped_ptr<FullWallet> full_wallet( |
766 FullWallet::CreateFullWallet(*response_dict)); | 692 FullWallet::CreateFullWallet(*response_dict)); |
767 if (full_wallet) { | 693 if (full_wallet) { |
768 full_wallet->set_one_time_pad(one_time_pad_); | 694 full_wallet->set_one_time_pad(one_time_pad_); |
769 LogRequiredActions(full_wallet->required_actions()); | 695 LogRequiredActions(full_wallet->required_actions()); |
770 delegate_->OnDidGetFullWallet(full_wallet.Pass()); | 696 delegate_->OnDidGetFullWallet(full_wallet.Pass()); |
771 } else { | 697 } else { |
772 HandleMalformedResponse(scoped_request.get()); | 698 HandleMalformedResponse(scoped_request.get()); |
773 } | 699 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 case ACCEPT_LEGAL_DOCUMENTS: | 819 case ACCEPT_LEGAL_DOCUMENTS: |
894 return AutofillMetrics::ACCEPT_LEGAL_DOCUMENTS; | 820 return AutofillMetrics::ACCEPT_LEGAL_DOCUMENTS; |
895 case AUTHENTICATE_INSTRUMENT: | 821 case AUTHENTICATE_INSTRUMENT: |
896 return AutofillMetrics::AUTHENTICATE_INSTRUMENT; | 822 return AutofillMetrics::AUTHENTICATE_INSTRUMENT; |
897 case GET_FULL_WALLET: | 823 case GET_FULL_WALLET: |
898 return AutofillMetrics::GET_FULL_WALLET; | 824 return AutofillMetrics::GET_FULL_WALLET; |
899 case GET_WALLET_ITEMS: | 825 case GET_WALLET_ITEMS: |
900 return AutofillMetrics::GET_WALLET_ITEMS; | 826 return AutofillMetrics::GET_WALLET_ITEMS; |
901 case SAVE_TO_WALLET: | 827 case SAVE_TO_WALLET: |
902 return AutofillMetrics::SAVE_TO_WALLET; | 828 return AutofillMetrics::SAVE_TO_WALLET; |
903 case SEND_STATUS: | |
904 return AutofillMetrics::SEND_STATUS; | |
905 case NO_PENDING_REQUEST: | 829 case NO_PENDING_REQUEST: |
906 NOTREACHED(); | 830 NOTREACHED(); |
907 return AutofillMetrics::UNKNOWN_API_CALL; | 831 return AutofillMetrics::UNKNOWN_API_CALL; |
908 } | 832 } |
909 | 833 |
910 NOTREACHED(); | 834 NOTREACHED(); |
911 return AutofillMetrics::UNKNOWN_API_CALL; | 835 return AutofillMetrics::UNKNOWN_API_CALL; |
912 } | 836 } |
913 | 837 |
914 } // namespace wallet | 838 } // namespace wallet |
915 } // namespace autofill | 839 } // namespace autofill |
OLD | NEW |