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