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

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

Issue 6673079: Reduce boxing and unboxing of AutofillFieldType (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 9 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
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/phone_number.h" 5 #include "chrome/browser/autofill/phone_number.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/autofill/autofill_profile.h" 9 #include "chrome/browser/autofill/autofill_profile.h"
10 #include "chrome/browser/autofill/autofill_type.h" 10 #include "chrome/browser/autofill/autofill_type.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 if (!country_code().empty()) 85 if (!country_code().empty())
86 available_types->insert(GetCountryCodeType()); 86 available_types->insert(GetCountryCodeType());
87 87
88 if (!CityAndNumber().empty()) 88 if (!CityAndNumber().empty())
89 available_types->insert(GetCityAndNumberType()); 89 available_types->insert(GetCityAndNumberType());
90 90
91 if (!WholeNumber().empty()) 91 if (!WholeNumber().empty())
92 available_types->insert(GetWholeNumberType()); 92 available_types->insert(GetWholeNumberType());
93 } 93 }
94 94
95 string16 PhoneNumber::GetFieldText(const AutofillType& type) const { 95 string16 PhoneNumber::GetFieldText(AutofillFieldType type) const {
96 AutofillFieldType field_type = type.field_type(); 96 if (type == GetNumberType())
97 if (field_type == GetNumberType())
98 return number(); 97 return number();
99 98
100 if (field_type == GetCityCodeType()) 99 if (type == GetCityCodeType())
101 return city_code(); 100 return city_code();
102 101
103 if (field_type == GetCountryCodeType()) 102 if (type == GetCountryCodeType())
104 return country_code(); 103 return country_code();
105 104
106 if (field_type == GetCityAndNumberType()) 105 if (type == GetCityAndNumberType())
107 return CityAndNumber(); 106 return CityAndNumber();
108 107
109 if (field_type == GetWholeNumberType()) 108 if (type == GetWholeNumberType())
110 return WholeNumber(); 109 return WholeNumber();
111 110
112 return string16(); 111 return string16();
113 } 112 }
114 113
115 void PhoneNumber::FindInfoMatches(const AutofillType& type, 114 void PhoneNumber::FindInfoMatches(AutofillFieldType type,
116 const string16& info, 115 const string16& info,
117 std::vector<string16>* matched_text) const { 116 std::vector<string16>* matched_text) const {
118 if (matched_text == NULL) { 117 if (matched_text == NULL) {
119 DLOG(ERROR) << "NULL matched vector passed in"; 118 DLOG(ERROR) << "NULL matched vector passed in";
120 return; 119 return;
121 } 120 }
122 121
123 string16 number(info); 122 string16 number(info);
124 StripPunctuation(&number); 123 StripPunctuation(&number);
125 if (!Validate(number)) 124 if (!Validate(number))
126 return; 125 return;
127 126
128 string16 match; 127 string16 match;
129 if (type.field_type() == UNKNOWN_TYPE) { 128 if (type == UNKNOWN_TYPE) {
130 for (int i = 0; i < kAutoFillPhoneLength; ++i) { 129 for (int i = 0; i < kAutoFillPhoneLength; ++i) {
131 if (FindInfoMatchesHelper(kAutoFillPhoneTypes[i], info, &match)) 130 if (FindInfoMatchesHelper(kAutoFillPhoneTypes[i], info, &match))
132 matched_text->push_back(match); 131 matched_text->push_back(match);
133 } 132 }
134 } else { 133 } else {
135 if (FindInfoMatchesHelper(type.subgroup(), info, &match)) 134 if (FindInfoMatchesHelper(AutofillType(type).subgroup(), info, &match))
136 matched_text->push_back(match); 135 matched_text->push_back(match);
137 } 136 }
138 } 137 }
139 138
140 void PhoneNumber::SetInfo(const AutofillType& type, const string16& value) { 139 void PhoneNumber::SetInfo(AutofillFieldType type, const string16& value) {
141 string16 number(value); 140 string16 number(value);
142 StripPunctuation(&number); 141 StripPunctuation(&number);
143 if (!Validate(number)) 142 if (!Validate(number))
144 return; 143 return;
145 144
146 FieldTypeSubGroup subgroup = type.subgroup(); 145 FieldTypeSubGroup subgroup = AutofillType(type).subgroup();
147 if (subgroup == AutofillType::PHONE_NUMBER) 146 if (subgroup == AutofillType::PHONE_NUMBER)
148 set_number(number); 147 set_number(number);
149 else if (subgroup == AutofillType::PHONE_CITY_CODE) 148 else if (subgroup == AutofillType::PHONE_CITY_CODE)
150 set_city_code(number); 149 set_city_code(number);
151 else if (subgroup == AutofillType::PHONE_COUNTRY_CODE) 150 else if (subgroup == AutofillType::PHONE_COUNTRY_CODE)
152 set_country_code(number); 151 set_country_code(number);
153 else if (subgroup == AutofillType::PHONE_CITY_AND_NUMBER || 152 else if (subgroup == AutofillType::PHONE_CITY_AND_NUMBER ||
154 subgroup == AutofillType::PHONE_WHOLE_NUMBER) 153 subgroup == AutofillType::PHONE_WHOLE_NUMBER)
155 set_whole_number(number); 154 set_whole_number(number);
156 else 155 else
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return false; 297 return false;
299 } 298 }
300 299
301 return true; 300 return true;
302 } 301 }
303 302
304 // Static. 303 // Static.
305 void PhoneNumber::StripPunctuation(string16* number) { 304 void PhoneNumber::StripPunctuation(string16* number) {
306 RemoveChars(*number, kPhoneNumberSeparators, number); 305 RemoveChars(*number, kPhoneNumberSeparators, number);
307 } 306 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/phone_number.h ('k') | chrome/browser/autofill/select_control_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698