[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | |
[email protected] | e4b2fa3 | 2013-03-09 22:56:56 | [diff] [blame] | 5 | #ifndef COMPONENTS_AUTOFILL_BROWSER_WALLET_WALLET_ADDRESS_H_ |
| 6 | #define COMPONENTS_AUTOFILL_BROWSER_WALLET_WALLET_ADDRESS_H_ |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/basictypes.h" |
| 11 | #include "base/memory/scoped_ptr.h" |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 12 | #include "base/string16.h" |
[email protected] | e4b2fa3 | 2013-03-09 22:56:56 | [diff] [blame] | 13 | #include "components/autofill/browser/field_types.h" |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 14 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 15 | namespace base { |
| 16 | class DictionaryValue; |
| 17 | } |
| 18 | |
[email protected] | 34517564 | 2013-02-20 19:25:52 | [diff] [blame] | 19 | namespace autofill { |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 20 | |
| 21 | class AutofillProfile; |
| 22 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 23 | namespace wallet { |
| 24 | |
[email protected] | e4b2fa3 | 2013-03-09 22:56:56 | [diff] [blame] | 25 | // TODO(ahutter): This address is a lot like |
| 26 | // components/autofill/browser/address.h. There should be a super |
| 27 | // class that both extend from to clean up duplicated code. See |
| 28 | // http://crbug.com/164463. |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 29 | |
| 30 | // Address contains various address fields that have been populated from the |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 31 | // user's Online Wallet. It is loosely modeled as a subet of the OASIS |
| 32 | // "extensible Address Language" (xAL); see |
| 33 | // http://www.oasis-open.org/committees/ciq/download.shtml. |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 34 | class Address { |
| 35 | public: |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 36 | // TODO(ahutter): Use additional fields (descriptive_name, is_post_box, |
| 37 | // is_minimal_address, is_valid, is_default) when SaveToWallet is implemented. |
| 38 | // See http://crbug.com/164284. |
[email protected] | 5a9ff50 | 2013-03-12 06:06:16 | [diff] [blame] | 39 | |
| 40 | Address(); |
| 41 | |
| 42 | // Using the raw info in |profile|, create a wallet::Address. |
| 43 | explicit Address(const AutofillProfile& profile); |
| 44 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 45 | Address(const std::string& country_name_code, |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 46 | const base::string16& recipient_name, |
| 47 | const base::string16& address_line_1, |
| 48 | const base::string16& address_line_2, |
| 49 | const base::string16& locality_name, |
| 50 | const base::string16& administrative_area_name, |
| 51 | const base::string16& postal_code_number, |
| 52 | const base::string16& phone_number, |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 53 | const std::string& object_id); |
[email protected] | 5a9ff50 | 2013-03-12 06:06:16 | [diff] [blame] | 54 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 55 | ~Address(); |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 56 | |
| 57 | // Returns an empty scoped_ptr if input is invalid or a valid address that is |
| 58 | // selectable for Google Wallet use. Does not require "id" in |dictionary|. |
| 59 | // IDs are not required for billing addresses. |
| 60 | static scoped_ptr<Address> CreateAddress( |
| 61 | const base::DictionaryValue& dictionary); |
| 62 | |
| 63 | // Builds an Address from |dictionary|, which must have an "id" field. This |
| 64 | // function is designed for use with shipping addresses. The function may fail |
| 65 | // and return an empty pointer if its input is invalid. |
| 66 | static scoped_ptr<Address> CreateAddressWithID( |
| 67 | const base::DictionaryValue& dictionary); |
| 68 | |
| 69 | // Returns an empty scoped_ptr if input in invalid or a valid address that |
| 70 | // can only be used for displaying to the user. |
| 71 | static scoped_ptr<Address> CreateDisplayAddress( |
| 72 | const base::DictionaryValue& dictionary); |
| 73 | |
| 74 | // If an address is being upgraded, it will be sent to the server in a |
| 75 | // different format and with a few additional fields set, most importantly |
| 76 | // |object_id_|. |
| 77 | scoped_ptr<base::DictionaryValue> ToDictionaryWithID() const; |
| 78 | |
| 79 | // Newly created addresses will not have an associated |object_id_| and are |
| 80 | // sent to the server in a slightly different format. |
| 81 | scoped_ptr<base::DictionaryValue> ToDictionaryWithoutID() const; |
| 82 | |
| 83 | // Returns a string that summarizes this address, suitable for display to |
| 84 | // the user. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 85 | base::string16 DisplayName() const; |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 86 | |
[email protected] | 009c276 | 2013-03-15 10:55:48 | [diff] [blame] | 87 | // Returns a string that could be used as a sub-label, suitable for display |
| 88 | // to the user together with DisplayName(). |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 89 | base::string16 DisplayNameDetail() const; |
[email protected] | 009c276 | 2013-03-15 10:55:48 | [diff] [blame] | 90 | |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 91 | // Returns data appropriate for |type|. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 92 | base::string16 GetInfo(AutofillFieldType type, |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 93 | const std::string& app_locale) const; |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 94 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 95 | const std::string& country_name_code() const { return country_name_code_; } |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 96 | const base::string16& recipient_name() const { return recipient_name_; } |
| 97 | const base::string16& address_line_1() const { return address_line_1_; } |
| 98 | const base::string16& address_line_2() const { return address_line_2_; } |
| 99 | const base::string16& locality_name() const { return locality_name_; } |
| 100 | const base::string16& administrative_area_name() const { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 101 | return administrative_area_name_; |
| 102 | } |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 103 | const base::string16& postal_code_number() const { |
| 104 | return postal_code_number_; |
| 105 | } |
| 106 | const base::string16& phone_number() const { return phone_number_; } |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 107 | const std::string& object_id() const { return object_id_; } |
| 108 | |
| 109 | void set_country_name_code(const std::string& country_name_code) { |
| 110 | country_name_code_ = country_name_code; |
| 111 | } |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 112 | void set_recipient_name(const base::string16& recipient_name) { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 113 | recipient_name_ = recipient_name; |
| 114 | } |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 115 | void set_address_line_1(const base::string16& address_line_1) { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 116 | address_line_1_ = address_line_1; |
| 117 | } |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 118 | void set_address_line_2(const base::string16& address_line_2) { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 119 | address_line_2_ = address_line_2; |
| 120 | } |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 121 | void set_locality_name(const base::string16& locality_name) { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 122 | locality_name_ = locality_name; |
| 123 | } |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 124 | void set_administrative_area_name( |
| 125 | const base::string16& administrative_area_name) { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 126 | administrative_area_name_ = administrative_area_name; |
| 127 | } |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 128 | void set_postal_code_number(const base::string16& postal_code_number) { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 129 | postal_code_number_ = postal_code_number; |
| 130 | } |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 131 | void set_phone_number(const base::string16& phone_number) { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 132 | phone_number_ = phone_number; |
| 133 | } |
| 134 | void set_object_id(const std::string& object_id) { |
| 135 | object_id_ = object_id; |
| 136 | } |
| 137 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 138 | bool operator==(const Address& other) const; |
| 139 | bool operator!=(const Address& other) const; |
| 140 | |
| 141 | private: |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 142 | // |country_name_code_| should be an ISO 3166-1-alpha-2 (two letter codes, as |
| 143 | // used in DNS). For example, "GB". |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 144 | std::string country_name_code_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 145 | |
| 146 | // The recipient's name. For example "John Doe". |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 147 | base::string16 recipient_name_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 148 | |
| 149 | // |address_line_1| and |address_line_2| correspond to the "AddressLine" |
| 150 | // elements in xAL, which are used to hold unstructured text. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 151 | base::string16 address_line_1_; |
| 152 | base::string16 address_line_2_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 153 | |
| 154 | // Locality. This is something of a fuzzy term, but it generally refers to |
| 155 | // the city/town portion of an address. In regions of the world where |
| 156 | // localities are not well defined or do not fit into this structure well |
| 157 | // (for example, Japan and China), leave locality_name empty and use |
| 158 | // |address_line_2|. |
| 159 | // Examples: US city, IT comune, UK post town. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 160 | base::string16 locality_name_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 161 | |
| 162 | // Top-level administrative subdivision of this country. |
| 163 | // Examples: US state, IT region, UK constituent nation, JP prefecture. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 164 | base::string16 administrative_area_name_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 165 | |
| 166 | // Despite the name, |postal_code_number_| values are frequently alphanumeric. |
| 167 | // Examples: "94043", "SW1W", "SW1W 9TQ". |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 168 | base::string16 postal_code_number_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 169 | |
| 170 | // A valid international phone number. If |phone_number_| is a user provided |
| 171 | // value, it should have been validated using libphonenumber by clients of |
| 172 | // this class before being set; see http://code.google.com/p/libphonenumber/. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 173 | base::string16 phone_number_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 174 | |
| 175 | // Externalized Online Wallet id for this address. |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 176 | std::string object_id_; |
[email protected] | f8a0236 | 2013-02-15 20:28:55 | [diff] [blame] | 177 | |
[email protected] | 5a9ff50 | 2013-03-12 06:06:16 | [diff] [blame] | 178 | // This class is intentionally copyable. |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 179 | DISALLOW_ASSIGN(Address); |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | } // namespace wallet |
[email protected] | 34517564 | 2013-02-20 19:25:52 | [diff] [blame] | 183 | } // namespace autofill |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 184 | |
[email protected] | e4b2fa3 | 2013-03-09 22:56:56 | [diff] [blame] | 185 | #endif // COMPONENTS_AUTOFILL_BROWSER_WALLET_WALLET_ADDRESS_H_ |