blob: 937553eefe29557c1dab914843f4ea33cc61daa0 [file] [log] [blame]
[email protected]ce63d6b2012-12-20 02:46:281// 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]e4b2fa32013-03-09 22:56:565#ifndef COMPONENTS_AUTOFILL_BROWSER_WALLET_WALLET_ADDRESS_H_
6#define COMPONENTS_AUTOFILL_BROWSER_WALLET_WALLET_ADDRESS_H_
[email protected]ce63d6b2012-12-20 02:46:287
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/memory/scoped_ptr.h"
[email protected]b5093a72013-02-14 00:16:5812#include "base/string16.h"
[email protected]e4b2fa32013-03-09 22:56:5613#include "components/autofill/browser/field_types.h"
[email protected]ce63d6b2012-12-20 02:46:2814
[email protected]ce63d6b2012-12-20 02:46:2815namespace base {
16class DictionaryValue;
17}
18
[email protected]345175642013-02-20 19:25:5219namespace autofill {
[email protected]e217c5632013-04-12 19:11:4820
21class AutofillProfile;
22
[email protected]ce63d6b2012-12-20 02:46:2823namespace wallet {
24
[email protected]e4b2fa32013-03-09 22:56:5625// 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]ce63d6b2012-12-20 02:46:2829
30// Address contains various address fields that have been populated from the
[email protected]f8a02362013-02-15 20:28:5531// 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]ce63d6b2012-12-20 02:46:2834class Address {
35 public:
[email protected]ce63d6b2012-12-20 02:46:2836 // 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]5a9ff502013-03-12 06:06:1639
40 Address();
41
42 // Using the raw info in |profile|, create a wallet::Address.
43 explicit Address(const AutofillProfile& profile);
44
[email protected]ce63d6b2012-12-20 02:46:2845 Address(const std::string& country_name_code,
[email protected]d5ca8fb2013-04-11 17:54:3146 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]ce63d6b2012-12-20 02:46:2853 const std::string& object_id);
[email protected]5a9ff502013-03-12 06:06:1654
[email protected]ce63d6b2012-12-20 02:46:2855 ~Address();
[email protected]ca2fcbb2013-03-09 02:39:3356
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]d5ca8fb2013-04-11 17:54:3185 base::string16 DisplayName() const;
[email protected]ca2fcbb2013-03-09 02:39:3386
[email protected]009c2762013-03-15 10:55:4887 // Returns a string that could be used as a sub-label, suitable for display
88 // to the user together with DisplayName().
[email protected]d5ca8fb2013-04-11 17:54:3189 base::string16 DisplayNameDetail() const;
[email protected]009c2762013-03-15 10:55:4890
[email protected]ca2fcbb2013-03-09 02:39:3391 // Returns data appropriate for |type|.
[email protected]d5ca8fb2013-04-11 17:54:3192 base::string16 GetInfo(AutofillFieldType type,
[email protected]0b2f513b2013-04-05 20:13:2393 const std::string& app_locale) const;
[email protected]ca2fcbb2013-03-09 02:39:3394
[email protected]ce63d6b2012-12-20 02:46:2895 const std::string& country_name_code() const { return country_name_code_; }
[email protected]d5ca8fb2013-04-11 17:54:3196 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]ce63d6b2012-12-20 02:46:28101 return administrative_area_name_;
102 }
[email protected]d5ca8fb2013-04-11 17:54:31103 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]ce63d6b2012-12-20 02:46:28107 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]d5ca8fb2013-04-11 17:54:31112 void set_recipient_name(const base::string16& recipient_name) {
[email protected]ce63d6b2012-12-20 02:46:28113 recipient_name_ = recipient_name;
114 }
[email protected]d5ca8fb2013-04-11 17:54:31115 void set_address_line_1(const base::string16& address_line_1) {
[email protected]ce63d6b2012-12-20 02:46:28116 address_line_1_ = address_line_1;
117 }
[email protected]d5ca8fb2013-04-11 17:54:31118 void set_address_line_2(const base::string16& address_line_2) {
[email protected]ce63d6b2012-12-20 02:46:28119 address_line_2_ = address_line_2;
120 }
[email protected]d5ca8fb2013-04-11 17:54:31121 void set_locality_name(const base::string16& locality_name) {
[email protected]ce63d6b2012-12-20 02:46:28122 locality_name_ = locality_name;
123 }
[email protected]d5ca8fb2013-04-11 17:54:31124 void set_administrative_area_name(
125 const base::string16& administrative_area_name) {
[email protected]ce63d6b2012-12-20 02:46:28126 administrative_area_name_ = administrative_area_name;
127 }
[email protected]d5ca8fb2013-04-11 17:54:31128 void set_postal_code_number(const base::string16& postal_code_number) {
[email protected]ce63d6b2012-12-20 02:46:28129 postal_code_number_ = postal_code_number;
130 }
[email protected]d5ca8fb2013-04-11 17:54:31131 void set_phone_number(const base::string16& phone_number) {
[email protected]ce63d6b2012-12-20 02:46:28132 phone_number_ = phone_number;
133 }
134 void set_object_id(const std::string& object_id) {
135 object_id_ = object_id;
136 }
137
[email protected]ce63d6b2012-12-20 02:46:28138 bool operator==(const Address& other) const;
139 bool operator!=(const Address& other) const;
140
141 private:
[email protected]f8a02362013-02-15 20:28:55142 // |country_name_code_| should be an ISO 3166-1-alpha-2 (two letter codes, as
143 // used in DNS). For example, "GB".
[email protected]ce63d6b2012-12-20 02:46:28144 std::string country_name_code_;
[email protected]f8a02362013-02-15 20:28:55145
146 // The recipient's name. For example "John Doe".
[email protected]d5ca8fb2013-04-11 17:54:31147 base::string16 recipient_name_;
[email protected]f8a02362013-02-15 20:28:55148
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]d5ca8fb2013-04-11 17:54:31151 base::string16 address_line_1_;
152 base::string16 address_line_2_;
[email protected]f8a02362013-02-15 20:28:55153
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]d5ca8fb2013-04-11 17:54:31160 base::string16 locality_name_;
[email protected]f8a02362013-02-15 20:28:55161
162 // Top-level administrative subdivision of this country.
163 // Examples: US state, IT region, UK constituent nation, JP prefecture.
[email protected]d5ca8fb2013-04-11 17:54:31164 base::string16 administrative_area_name_;
[email protected]f8a02362013-02-15 20:28:55165
166 // Despite the name, |postal_code_number_| values are frequently alphanumeric.
167 // Examples: "94043", "SW1W", "SW1W 9TQ".
[email protected]d5ca8fb2013-04-11 17:54:31168 base::string16 postal_code_number_;
[email protected]f8a02362013-02-15 20:28:55169
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]d5ca8fb2013-04-11 17:54:31173 base::string16 phone_number_;
[email protected]f8a02362013-02-15 20:28:55174
175 // Externalized Online Wallet id for this address.
[email protected]ce63d6b2012-12-20 02:46:28176 std::string object_id_;
[email protected]f8a02362013-02-15 20:28:55177
[email protected]5a9ff502013-03-12 06:06:16178 // This class is intentionally copyable.
[email protected]ca2fcbb2013-03-09 02:39:33179 DISALLOW_ASSIGN(Address);
[email protected]ce63d6b2012-12-20 02:46:28180};
181
182} // namespace wallet
[email protected]345175642013-02-20 19:25:52183} // namespace autofill
[email protected]ce63d6b2012-12-20 02:46:28184
[email protected]e4b2fa32013-03-09 22:56:56185#endif // COMPONENTS_AUTOFILL_BROWSER_WALLET_WALLET_ADDRESS_H_