| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/payments/core/payment_address.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" |
| 10 |
| 11 namespace payments { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // These are defined as part of the spec at: |
| 16 // https://w3c.github.io/browser-payment-api/#paymentaddress-interface |
| 17 static const char kAddressAddressLine[] = "addressLine"; |
| 18 static const char kAddressCity[] = "city"; |
| 19 static const char kAddressCountry[] = "country"; |
| 20 static const char kAddressDependentLocality[] = "dependentLocality"; |
| 21 static const char kAddressLanguageCode[] = "languageCode"; |
| 22 static const char kAddressOrganization[] = "organization"; |
| 23 static const char kAddressPhone[] = "phone"; |
| 24 static const char kAddressPostalCode[] = "postalCode"; |
| 25 static const char kAddressRecipient[] = "recipient"; |
| 26 static const char kAddressRegion[] = "region"; |
| 27 static const char kAddressSortingCode[] = "sortingCode"; |
| 28 |
| 29 } // namespace |
| 30 |
| 31 PaymentAddress::PaymentAddress() {} |
| 32 PaymentAddress::PaymentAddress(const PaymentAddress& other) = default; |
| 33 PaymentAddress::~PaymentAddress() = default; |
| 34 |
| 35 bool PaymentAddress::operator==(const PaymentAddress& other) const { |
| 36 return this->country == other.country && |
| 37 this->address_line == other.address_line && |
| 38 this->region == other.region && this->city == other.city && |
| 39 this->dependent_locality == other.dependent_locality && |
| 40 this->postal_code == other.postal_code && |
| 41 this->sorting_code == other.sorting_code && |
| 42 this->language_code == other.language_code && |
| 43 this->organization == other.organization && |
| 44 this->recipient == other.recipient && this->phone == other.phone; |
| 45 } |
| 46 |
| 47 bool PaymentAddress::operator!=(const PaymentAddress& other) const { |
| 48 return !(*this == other); |
| 49 } |
| 50 |
| 51 std::unique_ptr<base::DictionaryValue> PaymentAddress::ToDictionaryValue() |
| 52 const { |
| 53 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 54 |
| 55 if (!this->country.empty()) |
| 56 result->SetString(kAddressCountry, this->country); |
| 57 |
| 58 if (!this->address_line.empty()) { |
| 59 std::unique_ptr<base::ListValue> address_line = |
| 60 base::MakeUnique<base::ListValue>(); |
| 61 for (const base::string16& address_line_string : this->address_line) { |
| 62 if (!address_line_string.empty()) |
| 63 address_line->AppendString(address_line_string); |
| 64 } |
| 65 result->Set(kAddressAddressLine, std::move(address_line)); |
| 66 } |
| 67 |
| 68 if (!this->region.empty()) |
| 69 result->SetString(kAddressRegion, this->region); |
| 70 if (!this->city.empty()) |
| 71 result->SetString(kAddressCity, this->city); |
| 72 if (!this->dependent_locality.empty()) |
| 73 result->SetString(kAddressDependentLocality, this->dependent_locality); |
| 74 if (!this->postal_code.empty()) |
| 75 result->SetString(kAddressPostalCode, this->postal_code); |
| 76 if (!this->sorting_code.empty()) |
| 77 result->SetString(kAddressSortingCode, this->sorting_code); |
| 78 if (!this->language_code.empty()) |
| 79 result->SetString(kAddressLanguageCode, this->language_code); |
| 80 if (!this->organization.empty()) |
| 81 result->SetString(kAddressOrganization, this->organization); |
| 82 if (!this->recipient.empty()) |
| 83 result->SetString(kAddressRecipient, this->recipient); |
| 84 if (!this->phone.empty()) |
| 85 result->SetString(kAddressPhone, this->phone); |
| 86 |
| 87 return result; |
| 88 } |
| 89 |
| 90 } // namespace payments |
| OLD | NEW |