OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_ADDRESS_H_ | |
6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_ADDRESS_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include <memory> | |
11 #include <string> | |
12 | |
13 #include "base/macros.h" | |
14 #include "base/strings/string16.h" | |
15 #include "components/autofill/core/browser/phone_number_i18n.h" | |
16 | |
17 namespace base { | |
18 class DictionaryValue; | |
19 } | |
20 | |
21 namespace autofill { | |
22 | |
23 class AutofillProfile; | |
24 class AutofillType; | |
25 | |
26 namespace wallet { | |
27 | |
28 // TODO(ahutter): This address is a lot like | |
29 // components/autofill/core/browser/address.h. There should be a super | |
30 // class that both extend from to clean up duplicated code. See | |
31 // http://crbug.com/164463. | |
32 | |
33 // Address contains various address fields that have been populated from the | |
34 // user's Online Wallet. It is loosely modeled as a subet of the OASIS | |
35 // "extensible Address Language" (xAL); see | |
36 // http://www.oasis-open.org/committees/ciq/download.shtml. | |
37 class Address { | |
38 public: | |
39 // TODO(ahutter): Use additional fields (descriptive_name, is_post_box, | |
40 // is_valid, is_default) when SaveToWallet is implemented. | |
41 // See http://crbug.com/164284. | |
42 | |
43 Address(); | |
44 | |
45 // Using the raw info in |profile|, create a wallet::Address. | |
46 explicit Address(const AutofillProfile& profile); | |
47 | |
48 Address(const std::string& country_name_code, | |
49 const base::string16& recipient_name, | |
50 const std::vector<base::string16>& street_address, | |
51 const base::string16& locality_name, | |
52 const base::string16& dependent_locality_name, | |
53 const base::string16& administrative_area_name, | |
54 const base::string16& postal_code_number, | |
55 const base::string16& sorting_code, | |
56 const base::string16& phone_number, | |
57 const std::string& object_id, | |
58 const std::string& language_code); | |
59 | |
60 ~Address(); | |
61 | |
62 // Returns an empty scoped_ptr if input is invalid or a valid address that is | |
63 // selectable for Google Wallet use. Does not require "id" in |dictionary|. | |
64 // IDs are not required for billing addresses. | |
65 static std::unique_ptr<Address> CreateAddress( | |
66 const base::DictionaryValue& dictionary); | |
67 | |
68 // TODO(ahutter): Make obvious in the function name that this public method | |
69 // only works for shipping address and assumes existance of "postal_address". | |
70 // Builds an Address from |dictionary|, which must have an "id" field. This | |
71 // function is designed for use with shipping addresses. The function may fail | |
72 // and return an empty pointer if its input is invalid. | |
73 static std::unique_ptr<Address> CreateAddressWithID( | |
74 const base::DictionaryValue& dictionary); | |
75 | |
76 // Returns an empty scoped_ptr if input in invalid or a valid address that | |
77 // can only be used for displaying to the user. | |
78 static std::unique_ptr<Address> CreateDisplayAddress( | |
79 const base::DictionaryValue& dictionary); | |
80 | |
81 // If an address is being upgraded, it will be sent to the server in a | |
82 // different format and with a few additional fields set, most importantly | |
83 // |object_id_|. | |
84 std::unique_ptr<base::DictionaryValue> ToDictionaryWithID() const; | |
85 | |
86 // Newly created addresses will not have an associated |object_id_| and are | |
87 // sent to the server in a slightly different format. | |
88 std::unique_ptr<base::DictionaryValue> ToDictionaryWithoutID() const; | |
89 | |
90 // Returns a string that summarizes this address, suitable for display to | |
91 // the user. | |
92 base::string16 DisplayName() const; | |
93 | |
94 // Returns a string that could be used as a sub-label, suitable for display | |
95 // to the user together with DisplayName(). | |
96 base::string16 DisplayNameDetail() const; | |
97 | |
98 // Returns the phone number as a string that is suitable for display to the | |
99 // user. | |
100 base::string16 DisplayPhoneNumber() const; | |
101 | |
102 // Returns data appropriate for |type|. | |
103 base::string16 GetInfo(const AutofillType& type, | |
104 const std::string& app_locale) const; | |
105 | |
106 const std::string& country_name_code() const { return country_name_code_; } | |
107 const base::string16& recipient_name() const { return recipient_name_; } | |
108 const std::vector<base::string16>& street_address() const { | |
109 return street_address_; | |
110 } | |
111 const base::string16& locality_name() const { return locality_name_; } | |
112 const base::string16& administrative_area_name() const { | |
113 return administrative_area_name_; | |
114 } | |
115 const base::string16& postal_code_number() const { | |
116 return postal_code_number_; | |
117 } | |
118 const base::string16& phone_number() const { return phone_number_; } | |
119 const std::string& object_id() const { return object_id_; } | |
120 bool is_complete_address() const { | |
121 return is_complete_address_; | |
122 } | |
123 const std::string& language_code() const { return language_code_; } | |
124 | |
125 void set_country_name_code(const std::string& country_name_code) { | |
126 country_name_code_ = country_name_code; | |
127 } | |
128 void set_recipient_name(const base::string16& recipient_name) { | |
129 recipient_name_ = recipient_name; | |
130 } | |
131 void set_street_address(const std::vector<base::string16>& street_address) { | |
132 street_address_ = street_address; | |
133 } | |
134 void set_locality_name(const base::string16& locality_name) { | |
135 locality_name_ = locality_name; | |
136 } | |
137 void set_dependent_locality_name( | |
138 const base::string16& dependent_locality_name) { | |
139 dependent_locality_name_ = dependent_locality_name; | |
140 } | |
141 void set_administrative_area_name( | |
142 const base::string16& administrative_area_name) { | |
143 administrative_area_name_ = administrative_area_name; | |
144 } | |
145 void set_postal_code_number(const base::string16& postal_code_number) { | |
146 postal_code_number_ = postal_code_number; | |
147 } | |
148 void set_sorting_code(const base::string16& sorting_code) { | |
149 sorting_code_ = sorting_code; | |
150 } | |
151 void SetPhoneNumber(const base::string16& phone_number); | |
152 void set_object_id(const std::string& object_id) { | |
153 object_id_ = object_id; | |
154 } | |
155 void set_is_complete_address(bool is_complete_address) { | |
156 is_complete_address_ = is_complete_address; | |
157 } | |
158 void set_language_code(const std::string& language_code) { | |
159 language_code_ = language_code; | |
160 } | |
161 | |
162 // Tests if this address exact matches |other|. This method can be used to | |
163 // cull duplicates. It wouldn't make sense to have multiple identical street | |
164 // addresses with different identifiers or language codes (used for | |
165 // formatting). Therefore, |object_id| and |language_code| are ignored. | |
166 bool EqualsIgnoreID(const Address& other) const; | |
167 | |
168 // Tests if this address exact matches |other| including |object_id| and | |
169 // |language_code|. | |
170 bool operator==(const Address& other) const; | |
171 bool operator!=(const Address& other) const; | |
172 | |
173 private: | |
174 // Gets the street address on the given line (0-indexed). | |
175 base::string16 GetStreetAddressLine(size_t line) const; | |
176 | |
177 // |country_name_code_| should be an ISO 3166-1-alpha-2 (two letter codes, as | |
178 // used in DNS). For example, "GB". | |
179 std::string country_name_code_; | |
180 | |
181 // The recipient's name. For example "John Doe". | |
182 base::string16 recipient_name_; | |
183 | |
184 // Address lines (arbitrarily many). | |
185 std::vector<base::string16> street_address_; | |
186 | |
187 // Locality. This is something of a fuzzy term, but it generally refers to | |
188 // the city/town portion of an address. | |
189 // Examples: US city, IT comune, UK post town. | |
190 base::string16 locality_name_; | |
191 | |
192 // Dependent locality is used in Korea and China. | |
193 // Example: a Chinese county under the authority of a prefecture-level city. | |
194 base::string16 dependent_locality_name_; | |
195 | |
196 // Top-level administrative subdivision of this country. | |
197 // Examples: US state, IT region, UK constituent nation, JP prefecture. | |
198 // Note: this must be in short form, e.g. TX rather than Texas. | |
199 base::string16 administrative_area_name_; | |
200 | |
201 // Despite the name, |postal_code_number_| values are frequently alphanumeric. | |
202 // Examples: "94043", "SW1W", "SW1W 9TQ". | |
203 base::string16 postal_code_number_; | |
204 | |
205 // Sorting code, e.g. CEDEX in France. | |
206 base::string16 sorting_code_; | |
207 | |
208 // A valid international phone number. If |phone_number_| is a user provided | |
209 // value, it should have been validated using libphonenumber by clients of | |
210 // this class before being set; see http://code.google.com/p/libphonenumber/. | |
211 base::string16 phone_number_; | |
212 | |
213 // The parsed phone number. | |
214 i18n::PhoneObject phone_object_; | |
215 | |
216 // Externalized Online Wallet id for this address. | |
217 std::string object_id_; | |
218 | |
219 // Server's understanding of this address as complete address or not. | |
220 bool is_complete_address_; | |
221 | |
222 // The BCP 47 language code that can be used for formatting this address for | |
223 // display. | |
224 std::string language_code_; | |
225 | |
226 // This class is intentionally copyable. | |
227 DISALLOW_ASSIGN(Address); | |
228 }; | |
229 | |
230 } // namespace wallet | |
231 } // namespace autofill | |
232 | |
233 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_ADDRESS_H_ | |
OLD | NEW |