Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: components/autofill/browser/autofill_country.h

Issue 17392006: In components/autofill, move browser/ to core/browser/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to fix conflicts Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_BROWSER_AUTOFILL_COUNTRY_H_
6 #define COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_COUNTRY_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/strings/string16.h"
13
14 namespace autofill {
15
16 // The minimal required fields for an address to be complete for a given
17 // country.
18 enum AddressRequiredFields {
19 ADDRESS_REQUIRES_CITY = 1 << 0,
20 ADDRESS_REQUIRES_STATE = 1 << 1,
21 ADDRESS_REQUIRES_ZIP = 1 << 2,
22
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,
32
33 // Policy for countries that don't have city, state or zip requirements.
34 ADDRESS_REQUIRES_ADDRESS_LINE_1_ONLY = 0,
35
36 // Policy for countries for which we do not have information about valid
37 // address format.
38 ADDRESS_REQUIREMENTS_UNKNOWN = ADDRESS_REQUIRES_CITY_STATE_ZIP,
39 };
40
41 // Stores data associated with a country. Strings are localized to the app
42 // locale.
43 class AutofillCountry {
44 public:
45 // Returns country data corresponding to the two-letter ISO code
46 // |country_code|.
47 AutofillCountry(const std::string& country_code, const std::string& locale);
48 ~AutofillCountry();
49
50 // Fills |country_codes| with a list of the available countries' codes.
51 static void GetAvailableCountries(
52 std::vector<std::string>* country_codes);
53
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);
57
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);
63
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_; }
68
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;
72 }
73
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;
77 }
78
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;
82 }
83
84 private:
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);
89
90 // The two-letter ISO-3166 country code.
91 std::string country_code_;
92
93 // The country's name, localized to the app locale.
94 base::string16 name_;
95
96 // The localized label for the postal code (or zip code) field.
97 base::string16 postal_code_label_;
98
99 // The localized label for the state (or province, district, etc.) field.
100 base::string16 state_label_;
101
102 // Address requirement field codes for the country.
103 AddressRequiredFields address_required_fields_;
104
105 DISALLOW_COPY_AND_ASSIGN(AutofillCountry);
106 };
107
108 } // namespace autofill
109
110 #endif // COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_COUNTRY_H_
OLDNEW
« no previous file with comments | « components/autofill/browser/autofill_common_test.cc ('k') | components/autofill/browser/autofill_country.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698