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

Side by Side Diff: chrome/browser/autofill/address.cc

Issue 8169009: Remove FieldTypeSubGroups from the AutofillType class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests compile Created 9 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autofill/address.h" 5 #include "chrome/browser/autofill/address.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "chrome/browser/autofill/autofill_country.h" 12 #include "chrome/browser/autofill/autofill_country.h"
13 #include "chrome/browser/autofill/autofill_type.h" 13 #include "chrome/browser/autofill/autofill_type.h"
14 #include "chrome/browser/autofill/field_types.h" 14 #include "chrome/browser/autofill/field_types.h"
15 15
16 namespace { 16 namespace {
17 17
18 const char16 kAddressSplitChars[] = {'-', ',', '#', '.', ' ', 0}; 18 const char16 kAddressSplitChars[] = {'-', ',', '#', '.', ' ', 0};
19 19
20 const AutofillType::FieldTypeSubGroup kAutofillAddressTypes[] = {
21 AutofillType::ADDRESS_LINE1,
22 AutofillType::ADDRESS_LINE2,
23 AutofillType::ADDRESS_CITY,
24 AutofillType::ADDRESS_STATE,
25 AutofillType::ADDRESS_ZIP,
26 AutofillType::ADDRESS_COUNTRY,
27 };
28
29 const int kAutofillAddressLength = arraysize(kAutofillAddressTypes);
30
31 // Returns the country code corresponding to |country|, which should be a 20 // Returns the country code corresponding to |country|, which should be a
32 // localized country name. 21 // localized country name.
33 std::string ToCountryCode(const string16& country) { 22 std::string ToCountryCode(const string16& country) {
34 std::string app_locale = AutofillCountry::ApplicationLocale(); 23 std::string app_locale = AutofillCountry::ApplicationLocale();
35 return AutofillCountry::GetCountryCode(country, app_locale); 24 return AutofillCountry::GetCountryCode(country, app_locale);
36 } 25 }
37 26
38 } // namespace 27 } // namespace
39 28
40 Address::Address() {} 29 Address::Address() {}
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 if (type == ADDRESS_HOME_ZIP) 72 if (type == ADDRESS_HOME_ZIP)
84 return zip_code_; 73 return zip_code_;
85 74
86 if (type == ADDRESS_HOME_COUNTRY) 75 if (type == ADDRESS_HOME_COUNTRY)
87 return Country(); 76 return Country();
88 77
89 return string16(); 78 return string16();
90 } 79 }
91 80
92 void Address::SetInfo(AutofillFieldType type, const string16& value) { 81 void Address::SetInfo(AutofillFieldType type, const string16& value) {
93 FieldTypeSubGroup subgroup = AutofillType(type).subgroup(); 82 type = AutofillType::GetEquivalentFieldType(type);
94 if (subgroup == AutofillType::ADDRESS_LINE1) 83 if (type == ADDRESS_HOME_LINE1)
95 line1_ = value; 84 line1_ = value;
96 else if (subgroup == AutofillType::ADDRESS_LINE2) 85 else if (type == ADDRESS_HOME_LINE2)
97 line2_ = value; 86 line2_ = value;
98 else if (subgroup == AutofillType::ADDRESS_CITY) 87 else if (type == ADDRESS_HOME_CITY)
99 city_ = value; 88 city_ = value;
100 else if (subgroup == AutofillType::ADDRESS_STATE) 89 else if (type == ADDRESS_HOME_STATE)
101 state_ = value; 90 state_ = value;
102 else if (subgroup == AutofillType::ADDRESS_COUNTRY) 91 else if (type == ADDRESS_HOME_COUNTRY)
103 country_code_ = ToCountryCode(value); 92 country_code_ = ToCountryCode(value);
104 else if (subgroup == AutofillType::ADDRESS_ZIP) 93 else if (type == ADDRESS_HOME_ZIP)
105 zip_code_ = value; 94 zip_code_ = value;
106 else 95 else
107 NOTREACHED(); 96 NOTREACHED();
108 } 97 }
109 98
110 void Address::GetMatchingTypes(const string16& text, 99 void Address::GetMatchingTypes(const string16& text,
111 FieldTypeSet* matching_types) const { 100 FieldTypeSet* matching_types) const {
112 FormGroup::GetMatchingTypes(text, matching_types); 101 FormGroup::GetMatchingTypes(text, matching_types);
113 102
114 // Check to see if the |text| canonicalized as a country name is a match. 103 // Check to see if the |text| canonicalized as a country name is a match.
115 std::string country_code = ToCountryCode(text); 104 std::string country_code = ToCountryCode(text);
116 if (!country_code.empty() && country_code_ == country_code) 105 if (!country_code.empty() && country_code_ == country_code)
117 matching_types->insert(ADDRESS_HOME_COUNTRY); 106 matching_types->insert(ADDRESS_HOME_COUNTRY);
118 } 107 }
119 108
120 string16 Address::Country() const { 109 string16 Address::Country() const {
121 if (country_code().empty()) 110 if (country_code().empty())
122 return string16(); 111 return string16();
123 112
124 std::string app_locale = AutofillCountry::ApplicationLocale(); 113 std::string app_locale = AutofillCountry::ApplicationLocale();
125 return AutofillCountry(country_code(), app_locale).name(); 114 return AutofillCountry(country_code(), app_locale).name();
126 } 115 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698