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.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_COUNTRY_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_COUNTRY_H_
11 #include "base/basictypes.h"
12 #include "base/strings/string16.h"
16 // The minimal required fields for an address to be complete for a given
18 enum AddressRequiredFields
{
19 ADDRESS_REQUIRES_CITY
= 1 << 0,
20 ADDRESS_REQUIRES_STATE
= 1 << 1,
21 ADDRESS_REQUIRES_ZIP
= 1 << 2,
23 // Composite versions (for data).
24 ADDRESS_REQUIRES_CITY_STATE
=
25 ADDRESS_REQUIRES_CITY
| ADDRESS_REQUIRES_STATE
,
26 ADDRESS_REQUIRES_STATE_ZIP
=
27 ADDRESS_REQUIRES_STATE
| ADDRESS_REQUIRES_ZIP
,
28 ADDRESS_REQUIRES_CITY_ZIP
=
29 ADDRESS_REQUIRES_CITY
|ADDRESS_REQUIRES_ZIP
,
30 ADDRESS_REQUIRES_CITY_STATE_ZIP
=
31 ADDRESS_REQUIRES_CITY
| ADDRESS_REQUIRES_STATE
| ADDRESS_REQUIRES_ZIP
,
33 // Policy for countries that don't have city, state or zip requirements.
34 ADDRESS_REQUIRES_ADDRESS_LINE_1_ONLY
= 0,
36 // Policy for countries for which we do not have information about valid
38 ADDRESS_REQUIREMENTS_UNKNOWN
= ADDRESS_REQUIRES_CITY_STATE_ZIP
,
41 // Stores data associated with a country. Strings are localized to the app
43 class AutofillCountry
{
45 // Returns country data corresponding to the two-letter ISO code
47 AutofillCountry(const std::string
& country_code
, const std::string
& locale
);
50 // Fills |country_codes| with a list of the available countries' codes.
51 static void GetAvailableCountries(
52 std::vector
<std::string
>* country_codes
);
54 // Returns the likely country code for |locale|, or "US" as a fallback if no
55 // mapping from the locale is available.
56 static const std::string
CountryCodeForLocale(const std::string
& locale
);
58 // Returns the country code corresponding to |country|, which should be a
59 // country code or country name localized to |locale|. This function can
60 // be expensive so use judiciously.
61 static const std::string
GetCountryCode(const base::string16
& country
,
62 const std::string
& locale
);
64 const std::string
& country_code() const { return country_code_
; }
65 const base::string16
& name() const { return name_
; }
66 const base::string16
& postal_code_label() const { return postal_code_label_
; }
67 const base::string16
& state_label() const { return state_label_
; }
69 // City is expected in a complete address for this country.
70 bool requires_city() const {
71 return (address_required_fields_
& ADDRESS_REQUIRES_CITY
) != 0;
74 // State is expected in a complete address for this country.
75 bool requires_state() const {
76 return (address_required_fields_
& ADDRESS_REQUIRES_STATE
) != 0;
79 // Zip is expected in a complete address for this country.
80 bool requires_zip() const {
81 return (address_required_fields_
& ADDRESS_REQUIRES_ZIP
) != 0;
85 AutofillCountry(const std::string
& country_code
,
86 const base::string16
& name
,
87 const base::string16
& postal_code_label
,
88 const base::string16
& state_label
);
90 // The two-letter ISO-3166 country code.
91 std::string country_code_
;
93 // The country's name, localized to the app locale.
96 // The localized label for the postal code (or zip code) field.
97 base::string16 postal_code_label_
;
99 // The localized label for the state (or province, district, etc.) field.
100 base::string16 state_label_
;
102 // Address requirement field codes for the country.
103 AddressRequiredFields address_required_fields_
;
105 DISALLOW_COPY_AND_ASSIGN(AutofillCountry
);
108 } // namespace autofill
110 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_COUNTRY_H_