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

Unified Diff: components/autofill/core/browser/payments/payments_client.cc

Issue 2349033002: Include addresses with the getdetailsforsavecard Payments RPC. (Closed)
Patch Set: Eliminate static initializers, update a comment. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/core/browser/payments/payments_client.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/browser/payments/payments_client.cc
diff --git a/components/autofill/core/browser/payments/payments_client.cc b/components/autofill/core/browser/payments/payments_client.cc
index b34ad10a996fd51eb440a591320f2e2ca37fee4f..32b2cca0857d6b3c8f855f0535e02aeed6a44f27 100644
--- a/components/autofill/core/browser/payments/payments_client.cc
+++ b/components/autofill/core/browser/payments/payments_client.cc
@@ -6,6 +6,7 @@
#include <memory>
#include <utility>
+#include <vector>
#include "base/command_line.h"
#include "base/json/json_reader.h"
@@ -110,14 +111,21 @@ void AppendStringIfNotEmpty(const AutofillProfile& profile,
list->AppendString(value);
}
+// Returns a dictionary with the structure expected by Payments RPCs, containing
+// each of the fields in |profile|, formatted according to |app_locale|. If
+// |include_non_location_data| is false, the name and phone number in |profile|
+// are not included.
std::unique_ptr<base::DictionaryValue> BuildAddressDictionary(
const AutofillProfile& profile,
- const std::string& app_locale) {
+ const std::string& app_locale,
+ bool include_non_location_data) {
std::unique_ptr<base::DictionaryValue> postal_address(
new base::DictionaryValue());
- SetStringIfNotEmpty(profile, NAME_FULL, app_locale, "recipient_name",
- postal_address.get());
+ if (include_non_location_data) {
+ SetStringIfNotEmpty(profile, NAME_FULL, app_locale,
+ PaymentsClient::kRecipientName, postal_address.get());
+ }
std::unique_ptr<base::ListValue> address_lines(new base::ListValue());
AppendStringIfNotEmpty(profile, ADDRESS_HOME_LINE1, app_locale,
@@ -143,8 +151,11 @@ std::unique_ptr<base::DictionaryValue> BuildAddressDictionary(
std::unique_ptr<base::DictionaryValue> address(new base::DictionaryValue());
address->Set("postal_address", std::move(postal_address));
- SetStringIfNotEmpty(profile, PHONE_HOME_WHOLE_NUMBER, app_locale,
- "phone_number", address.get());
+
+ if (include_non_location_data) {
+ SetStringIfNotEmpty(profile, PHONE_HOME_WHOLE_NUMBER, app_locale,
+ PaymentsClient::kPhoneNumber, address.get());
+ }
return address;
}
@@ -209,8 +220,9 @@ class UnmaskCardRequest : public PaymentsRequest {
class GetUploadDetailsRequest : public PaymentsRequest {
public:
- GetUploadDetailsRequest(const std::string& app_locale)
- : app_locale_(app_locale) {}
+ GetUploadDetailsRequest(const std::vector<AutofillProfile>& addresses,
+ const std::string& app_locale)
+ : addresses_(addresses), app_locale_(app_locale) {}
~GetUploadDetailsRequest() override {}
std::string GetRequestUrlPath() override {
@@ -225,6 +237,18 @@ class GetUploadDetailsRequest : public PaymentsRequest {
context->SetString("language_code", app_locale_);
request_dict.Set("context", std::move(context));
+ std::unique_ptr<base::ListValue> addresses(new base::ListValue());
+ for (const AutofillProfile& profile : addresses_) {
+ // These addresses are used by Payments to (1) accurately determine the
+ // user's country in order to show the correct legal documents and (2) to
+ // verify that the addresses are valid for their purposes so that we don't
+ // offer save in a case where it would definitely fail (e.g. P.O. boxes).
+ // The final parameter directs BuildAddressDictionary to omit names and
+ // phone numbers, which aren't useful for these purposes.
+ addresses->Append(BuildAddressDictionary(profile, app_locale_, false));
+ }
+ request_dict.Set("address", std::move(addresses));
+
std::string request_content;
base::JSONWriter::Write(request_dict, &request_content);
VLOG(3) << "getdetailsforsavecard request body: " << request_content;
@@ -249,6 +273,7 @@ class GetUploadDetailsRequest : public PaymentsRequest {
}
private:
+ std::vector<AutofillProfile> addresses_;
std::string app_locale_;
base::string16 context_token_;
std::unique_ptr<base::DictionaryValue> legal_message_;
@@ -283,7 +308,7 @@ class UploadCardRequest : public PaymentsRequest {
std::unique_ptr<base::ListValue> addresses(new base::ListValue());
for (const AutofillProfile& profile : request_details_.profiles) {
- addresses->Append(BuildAddressDictionary(profile, app_locale));
+ addresses->Append(BuildAddressDictionary(profile, app_locale, true));
}
request_dict.Set("address", std::move(addresses));
@@ -330,6 +355,9 @@ class UploadCardRequest : public PaymentsRequest {
} // namespace
+const char PaymentsClient::kRecipientName[] = "recipient_name";
+const char PaymentsClient::kPhoneNumber[] = "phone_number";
+
PaymentsClient::UnmaskRequestDetails::UnmaskRequestDetails() {}
PaymentsClient::UnmaskRequestDetails::~UnmaskRequestDetails() {}
@@ -360,8 +388,11 @@ void PaymentsClient::UnmaskCard(
IssueRequest(base::MakeUnique<UnmaskCardRequest>(request_details), true);
}
-void PaymentsClient::GetUploadDetails(const std::string& app_locale) {
- IssueRequest(base::MakeUnique<GetUploadDetailsRequest>(app_locale), false);
+void PaymentsClient::GetUploadDetails(
+ const std::vector<AutofillProfile>& addresses,
+ const std::string& app_locale) {
+ IssueRequest(base::MakeUnique<GetUploadDetailsRequest>(addresses, app_locale),
+ false);
}
void PaymentsClient::UploadCard(
« no previous file with comments | « components/autofill/core/browser/payments/payments_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698