| 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 const std::string& country_name_code() const { return country_name_code_; } | |
| 47 const string16& recipient_name() const { return recipient_name_; } | |
| 48 const string16& address_line_1() const { return address_line_1_; } | |
| 49 const string16& address_line_2() const { return address_line_2_; } | |
| 50 const string16& locality_name() const { return locality_name_; } | |
| 51 const string16& administrative_area_name() const { | |
| 52 return administrative_area_name_; | |
| 53 } | |
| 54 const string16& postal_code_number() const { return postal_code_number_; } | |
| 55 const string16& phone_number() const { return phone_number_; } | |
| 56 const std::string& object_id() const { return object_id_; } | |
| 57 | |
| 58 void set_country_name_code(const std::string& country_name_code) { | |
| 59 country_name_code_ = country_name_code; | |
| 60 } | |
| 61 void set_recipient_name(const string16& recipient_name) { | |
| 62 recipient_name_ = recipient_name; | |
| 63 } | |
| 64 void set_address_line_1(const string16& address_line_1) { | |
| 65 address_line_1_ = address_line_1; | |
| 66 } | |
| 67 void set_address_line_2(const string16& address_line_2) { | |
| 68 address_line_2_ = address_line_2; | |
| 69 } | |
| 70 void set_locality_name(const string16& locality_name) { | |
| 71 locality_name_ = locality_name; | |
| 72 } | |
| 73 void set_administrative_area_name(const string16& administrative_area_name) { | |
| 74 administrative_area_name_ = administrative_area_name; | |
| 75 } | |
| 76 void set_postal_code_number(const string16& postal_code_number) { | |
| 77 postal_code_number_ = postal_code_number; | |
| 78 } | |
| 79 void set_phone_number(const string16& phone_number) { | |
| 80 phone_number_ = phone_number; | |
| 81 } | |
| 82 void set_object_id(const std::string& object_id) { | |
| 83 object_id_ = object_id; | |
| 84 } | |
| 85 | |
| 86 // If an address is being upgraded, it will be sent to the server in a | |
| 87 // different format and with a few additional fields set, most importantly | |
| 88 // |object_id_|. | |
| 89 scoped_ptr<base::DictionaryValue> ToDictionaryWithID() const; | |
| 90 | |
| 91 // Newly created addresses will not have an associated |object_id_| and are | |
| 92 // sent to the server in a slightly different format. | |
| 93 scoped_ptr<base::DictionaryValue> ToDictionaryWithoutID() const; | |
| 94 | |
| 95 // Returns a string that summarizes this address, suitable for display to | |
| 96 // the user. | |
| 97 string16 DisplayName() const; | |
| 98 | |
| 99 // Returns data appropriate for |type|. | |
| 100 string16 GetInfo(AutofillFieldType type) const; | |
| 101 | |
| 102 // Returns an empty scoped_ptr if input is invalid or a valid address that is | |
| 103 // selectable for Google Wallet use. Does not require "id" in |dictionary|. | |
| 104 // IDs are not required for billing addresses. | |
| 105 static scoped_ptr<Address> CreateAddress( | |
| 106 const base::DictionaryValue& dictionary); | |
| 107 | |
| 108 // Returns an empty scoped_ptr if input is invalid or a valid address that is | |
| 109 // selectable for Google Wallet use. Requires "id" in |dictionary|. IDs are | |
| 110 // required for shipping addresses. | |
| 111 static scoped_ptr<Address> CreateAddressWithID( | |
| 112 const base::DictionaryValue& dictionary); | |
| 113 | |
| 114 // Returns an empty scoped_ptr if input in invalid or a valid address that | |
| 115 // can only be used for displaying to the user. | |
| 116 static scoped_ptr<Address> CreateDisplayAddress( | |
| 117 const base::DictionaryValue& dictionary); | |
| 118 | |
| 119 bool operator==(const Address& other) const; | |
| 120 bool operator!=(const Address& other) const; | |
| 121 | |
| 122 private: | |
| 123 // |country_name_code_| should be an ISO 3166-1-alpha-2 (two letter codes, as | |
| 124 // used in DNS). For example, "GB". | |
| 125 std::string country_name_code_; | |
| 126 | |
| 127 // The recipient's name. For example "John Doe". | |
| 128 string16 recipient_name_; | |
| 129 | |
| 130 // |address_line_1| and |address_line_2| correspond to the "AddressLine" | |
| 131 // elements in xAL, which are used to hold unstructured text. | |
| 132 string16 address_line_1_; | |
| 133 string16 address_line_2_; | |
| 134 | |
| 135 // Locality. This is something of a fuzzy term, but it generally refers to | |
| 136 // the city/town portion of an address. In regions of the world where | |
| 137 // localities are not well defined or do not fit into this structure well | |
| 138 // (for example, Japan and China), leave locality_name empty and use | |
| 139 // |address_line_2|. | |
| 140 // Examples: US city, IT comune, UK post town. | |
| 141 string16 locality_name_; | |
| 142 | |
| 143 // Top-level administrative subdivision of this country. | |
| 144 // Examples: US state, IT region, UK constituent nation, JP prefecture. | |
| 145 string16 administrative_area_name_; | |
| 146 | |
| 147 // Despite the name, |postal_code_number_| values are frequently alphanumeric. | |
| 148 // Examples: "94043", "SW1W", "SW1W 9TQ". | |
| 149 string16 postal_code_number_; | |
| 150 | |
| 151 // A valid international phone number. If |phone_number_| is a user provided | |
| 152 // value, it should have been validated using libphonenumber by clients of | |
| 153 // this class before being set; see http://code.google.com/p/libphonenumber/. | |
| 154 string16 phone_number_; | |
| 155 | |
| 156 // Externalized Online Wallet id for this address. | |
| 157 std::string object_id_; | |
| 158 | |
| 159 DISALLOW_COPY_AND_ASSIGN(Address); | |
| 160 }; | |
| 161 | |
| 162 } // namespace wallet | |
| 163 } // namespace autofill | |
| 164 | |
| 165 #endif // CHROME_BROWSER_AUTOFILL_WALLET_WALLET_ADDRESS_H_ | |
| OLD | NEW |