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

Side by Side Diff: chrome/browser/autofill/personal_data_manager_mac.mm

Issue 6673079: Reduce boxing and unboxing of AutofillFieldType (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compile on Windows. 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/personal_data_manager.h" 5 #include "chrome/browser/autofill/personal_data_manager.h"
6 6
7 #import <AddressBook/AddressBook.h> 7 #import <AddressBook/AddressBook.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // We only propagate the company name to work profiles. 104 // We only propagate the company name to work profiles.
105 void AuxiliaryProfilesImpl::GetAddressBookNames( 105 void AuxiliaryProfilesImpl::GetAddressBookNames(
106 ABPerson* me, 106 ABPerson* me,
107 NSString* addressLabelRaw, 107 NSString* addressLabelRaw,
108 AutofillProfile* profile) { 108 AutofillProfile* profile) {
109 NSString* firstName = [me valueForProperty:kABFirstNameProperty]; 109 NSString* firstName = [me valueForProperty:kABFirstNameProperty];
110 NSString* middleName = [me valueForProperty:kABMiddleNameProperty]; 110 NSString* middleName = [me valueForProperty:kABMiddleNameProperty];
111 NSString* lastName = [me valueForProperty:kABLastNameProperty]; 111 NSString* lastName = [me valueForProperty:kABLastNameProperty];
112 NSString* companyName = [me valueForProperty:kABOrganizationProperty]; 112 NSString* companyName = [me valueForProperty:kABOrganizationProperty];
113 113
114 profile->SetInfo(AutofillType(NAME_FIRST), 114 profile->SetInfo(NAME_FIRST,
dhollowa 2011/03/16 17:07:11 nit: A number of these should fit on single line n
Ilya Sherman 2011/03/17 03:42:29 Done.
115 base::SysNSStringToUTF16(firstName)); 115 base::SysNSStringToUTF16(firstName));
116 profile->SetInfo(AutofillType(NAME_MIDDLE), 116 profile->SetInfo(NAME_MIDDLE,
117 base::SysNSStringToUTF16(middleName)); 117 base::SysNSStringToUTF16(middleName));
118 profile->SetInfo(AutofillType(NAME_LAST), 118 profile->SetInfo(NAME_LAST,
119 base::SysNSStringToUTF16(lastName)); 119 base::SysNSStringToUTF16(lastName));
120 if ([addressLabelRaw isEqualToString:kABAddressWorkLabel]) { 120 if ([addressLabelRaw isEqualToString:kABAddressWorkLabel]) {
121 profile->SetInfo(AutofillType(COMPANY_NAME), 121 profile->SetInfo(COMPANY_NAME,
122 base::SysNSStringToUTF16(companyName)); 122 base::SysNSStringToUTF16(companyName));
123 } 123 }
124 } 124 }
125 125
126 // Addresss information from the Address Book may span multiple lines. 126 // Addresss information from the Address Book may span multiple lines.
127 // If it does then we represent the address with two lines in the profile. The 127 // If it does then we represent the address with two lines in the profile. The
128 // second line we join with commas. 128 // second line we join with commas.
129 // For example: "c/o John Doe\n1122 Other Avenue\nApt #7" translates to 129 // For example: "c/o John Doe\n1122 Other Avenue\nApt #7" translates to
130 // line 1: "c/o John Doe", line 2: "1122 Other Avenue, Apt #7". 130 // line 1: "c/o John Doe", line 2: "1122 Other Avenue, Apt #7".
131 void AuxiliaryProfilesImpl::GetAddressBookAddresses( 131 void AuxiliaryProfilesImpl::GetAddressBookAddresses(
132 NSDictionary* address, 132 NSDictionary* address,
133 AutofillProfile* profile) { 133 AutofillProfile* profile) {
134 if (NSString* addressField = [address objectForKey:kABAddressStreetKey]) { 134 if (NSString* addressField = [address objectForKey:kABAddressStreetKey]) {
135 // If there are newlines in the address, split into two lines. 135 // If there are newlines in the address, split into two lines.
136 if ([addressField rangeOfCharacterFromSet: 136 if ([addressField rangeOfCharacterFromSet:
137 [NSCharacterSet newlineCharacterSet]].location != NSNotFound) { 137 [NSCharacterSet newlineCharacterSet]].location != NSNotFound) {
138 NSArray* chunks = [addressField componentsSeparatedByCharactersInSet: 138 NSArray* chunks = [addressField componentsSeparatedByCharactersInSet:
139 [NSCharacterSet newlineCharacterSet]]; 139 [NSCharacterSet newlineCharacterSet]];
140 DCHECK([chunks count] > 1); 140 DCHECK([chunks count] > 1);
141 141
142 NSString* separator = l10n_util::GetNSString( 142 NSString* separator = l10n_util::GetNSString(
143 IDS_AUTOFILL_MAC_ADDRESS_LINE_SEPARATOR); 143 IDS_AUTOFILL_MAC_ADDRESS_LINE_SEPARATOR);
144 144
145 NSString* addressField1 = [chunks objectAtIndex:0]; 145 NSString* addressField1 = [chunks objectAtIndex:0];
146 NSString* addressField2 = 146 NSString* addressField2 =
147 [[chunks subarrayWithRange:NSMakeRange(1, [chunks count] - 1)] 147 [[chunks subarrayWithRange:NSMakeRange(1, [chunks count] - 1)]
148 componentsJoinedByString:separator]; 148 componentsJoinedByString:separator];
149 profile->SetInfo(AutofillType(ADDRESS_HOME_LINE1), 149 profile->SetInfo(ADDRESS_HOME_LINE1,
150 base::SysNSStringToUTF16(addressField1)); 150 base::SysNSStringToUTF16(addressField1));
151 profile->SetInfo(AutofillType(ADDRESS_HOME_LINE2), 151 profile->SetInfo(ADDRESS_HOME_LINE2,
152 base::SysNSStringToUTF16(addressField2)); 152 base::SysNSStringToUTF16(addressField2));
153 } else { 153 } else {
154 profile->SetInfo(AutofillType(ADDRESS_HOME_LINE1), 154 profile->SetInfo(ADDRESS_HOME_LINE1,
155 base::SysNSStringToUTF16(addressField)); 155 base::SysNSStringToUTF16(addressField));
156 } 156 }
157 } 157 }
158 158
159 if (NSString* city = [address objectForKey:kABAddressCityKey]) { 159 if (NSString* city = [address objectForKey:kABAddressCityKey]) {
160 profile->SetInfo(AutofillType(ADDRESS_HOME_CITY), 160 profile->SetInfo(ADDRESS_HOME_CITY,
161 base::SysNSStringToUTF16(city)); 161 base::SysNSStringToUTF16(city));
162 } 162 }
163 if (NSString* state = [address objectForKey:kABAddressStateKey]) { 163 if (NSString* state = [address objectForKey:kABAddressStateKey]) {
164 profile->SetInfo(AutofillType(ADDRESS_HOME_STATE), 164 profile->SetInfo(ADDRESS_HOME_STATE,
165 base::SysNSStringToUTF16(state)); 165 base::SysNSStringToUTF16(state));
166 } 166 }
167 if (NSString* zip = [address objectForKey:kABAddressZIPKey]) { 167 if (NSString* zip = [address objectForKey:kABAddressZIPKey]) {
168 profile->SetInfo(AutofillType(ADDRESS_HOME_ZIP), 168 profile->SetInfo(ADDRESS_HOME_ZIP,
169 base::SysNSStringToUTF16(zip)); 169 base::SysNSStringToUTF16(zip));
170 } 170 }
171 if (NSString* country = [address objectForKey:kABAddressCountryKey]) { 171 if (NSString* country = [address objectForKey:kABAddressCountryKey]) {
172 profile->SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), 172 profile->SetInfo(ADDRESS_HOME_COUNTRY,
173 base::SysNSStringToUTF16(country)); 173 base::SysNSStringToUTF16(country));
174 } 174 }
175 } 175 }
176 176
177 // Fills in email address matching current address label. Note that there may 177 // Fills in email address matching current address label. Note that there may
178 // be multiple matching email addresses for a given label. We take the 178 // be multiple matching email addresses for a given label. We take the
179 // first we find (topmost) as preferred. 179 // first we find (topmost) as preferred.
180 void AuxiliaryProfilesImpl::GetAddressBookEmail( 180 void AuxiliaryProfilesImpl::GetAddressBookEmail(
181 ABPerson* me, 181 ABPerson* me,
182 NSString* addressLabelRaw, 182 NSString* addressLabelRaw,
183 AutofillProfile* profile) { 183 AutofillProfile* profile) {
184 ABMultiValue* emailAddresses = [me valueForProperty:kABEmailProperty]; 184 ABMultiValue* emailAddresses = [me valueForProperty:kABEmailProperty];
185 NSString* emailAddress = nil; 185 NSString* emailAddress = nil;
186 for (NSUInteger j = 0, emailCount = [emailAddresses count]; 186 for (NSUInteger j = 0, emailCount = [emailAddresses count];
187 j < emailCount; j++) { 187 j < emailCount; j++) {
188 NSString* emailAddressLabelRaw = [emailAddresses labelAtIndex:j]; 188 NSString* emailAddressLabelRaw = [emailAddresses labelAtIndex:j];
189 if ([emailAddressLabelRaw isEqualToString:addressLabelRaw]) { 189 if ([emailAddressLabelRaw isEqualToString:addressLabelRaw]) {
190 emailAddress = [emailAddresses valueAtIndex:j]; 190 emailAddress = [emailAddresses valueAtIndex:j];
191 break; 191 break;
192 } 192 }
193 } 193 }
194 profile->SetInfo(AutofillType(EMAIL_ADDRESS), 194 profile->SetInfo(EMAIL_ADDRESS,
195 base::SysNSStringToUTF16(emailAddress)); 195 base::SysNSStringToUTF16(emailAddress));
196 } 196 }
197 197
198 // Fills in telephone numbers. Each of these are special cases. 198 // Fills in telephone numbers. Each of these are special cases.
199 // We match four cases: home/tel, home/fax, work/tel, work/fax. 199 // We match four cases: home/tel, home/fax, work/tel, work/fax.
200 // Note, we traverse in reverse order so that top values in address book 200 // Note, we traverse in reverse order so that top values in address book
201 // take priority. 201 // take priority.
202 void AuxiliaryProfilesImpl::GetAddressBookPhoneNumbers( 202 void AuxiliaryProfilesImpl::GetAddressBookPhoneNumbers(
203 ABPerson* me, 203 ABPerson* me,
204 NSString* addressLabelRaw, 204 NSString* addressLabelRaw,
205 AutofillProfile* profile) { 205 AutofillProfile* profile) {
206 string16 number; 206 string16 number;
207 string16 city_code; 207 string16 city_code;
208 string16 country_code; 208 string16 country_code;
209 209
210 ABMultiValue* phoneNumbers = [me valueForProperty:kABPhoneProperty]; 210 ABMultiValue* phoneNumbers = [me valueForProperty:kABPhoneProperty];
211 for (NSUInteger k = 0, phoneCount = [phoneNumbers count]; 211 for (NSUInteger k = 0, phoneCount = [phoneNumbers count];
212 k < phoneCount; k++) { 212 k < phoneCount; k++) {
213 NSUInteger reverseK = phoneCount - k - 1; 213 NSUInteger reverseK = phoneCount - k - 1;
214 NSString* phoneLabelRaw = [phoneNumbers labelAtIndex:reverseK]; 214 NSString* phoneLabelRaw = [phoneNumbers labelAtIndex:reverseK];
215 if ([addressLabelRaw isEqualToString:kABAddressHomeLabel] && 215 if ([addressLabelRaw isEqualToString:kABAddressHomeLabel] &&
216 [phoneLabelRaw isEqualToString:kABPhoneHomeLabel]) { 216 [phoneLabelRaw isEqualToString:kABPhoneHomeLabel]) {
217 string16 homePhone = base::SysNSStringToUTF16( 217 string16 homePhone = base::SysNSStringToUTF16(
218 [phoneNumbers valueAtIndex:reverseK]); 218 [phoneNumbers valueAtIndex:reverseK]);
219 PhoneNumber::ParsePhoneNumber( 219 PhoneNumber::ParsePhoneNumber(
220 homePhone, &number, &city_code, &country_code); 220 homePhone, &number, &city_code, &country_code);
221 profile->SetInfo(AutofillType(PHONE_HOME_NUMBER), number); 221 profile->SetInfo(PHONE_HOME_NUMBER, number);
222 profile->SetInfo(AutofillType(PHONE_HOME_CITY_CODE), city_code); 222 profile->SetInfo(PHONE_HOME_CITY_CODE, city_code);
223 profile->SetInfo(AutofillType(PHONE_HOME_COUNTRY_CODE), country_code); 223 profile->SetInfo(PHONE_HOME_COUNTRY_CODE, country_code);
224 } else if ([addressLabelRaw isEqualToString:kABAddressHomeLabel] && 224 } else if ([addressLabelRaw isEqualToString:kABAddressHomeLabel] &&
225 [phoneLabelRaw isEqualToString:kABPhoneHomeFAXLabel]) { 225 [phoneLabelRaw isEqualToString:kABPhoneHomeFAXLabel]) {
226 string16 homeFax = base::SysNSStringToUTF16( 226 string16 homeFax = base::SysNSStringToUTF16(
227 [phoneNumbers valueAtIndex:reverseK]); 227 [phoneNumbers valueAtIndex:reverseK]);
228 PhoneNumber::ParsePhoneNumber(homeFax, 228 PhoneNumber::ParsePhoneNumber(homeFax,
229 &number, &city_code, &country_code); 229 &number, &city_code, &country_code);
230 profile->SetInfo(AutofillType(PHONE_FAX_NUMBER), number); 230 profile->SetInfo(PHONE_FAX_NUMBER, number);
231 profile->SetInfo(AutofillType(PHONE_FAX_CITY_CODE), city_code); 231 profile->SetInfo(PHONE_FAX_CITY_CODE, city_code);
232 profile->SetInfo(AutofillType(PHONE_FAX_COUNTRY_CODE), country_code); 232 profile->SetInfo(PHONE_FAX_COUNTRY_CODE, country_code);
233 } else if ([addressLabelRaw isEqualToString:kABAddressWorkLabel] && 233 } else if ([addressLabelRaw isEqualToString:kABAddressWorkLabel] &&
234 [phoneLabelRaw isEqualToString:kABPhoneWorkLabel]) { 234 [phoneLabelRaw isEqualToString:kABPhoneWorkLabel]) {
235 string16 workPhone = base::SysNSStringToUTF16( 235 string16 workPhone = base::SysNSStringToUTF16(
236 [phoneNumbers valueAtIndex:reverseK]); 236 [phoneNumbers valueAtIndex:reverseK]);
237 PhoneNumber::ParsePhoneNumber(workPhone, 237 PhoneNumber::ParsePhoneNumber(workPhone,
238 &number, &city_code, &country_code); 238 &number, &city_code, &country_code);
239 profile->SetInfo(AutofillType(PHONE_HOME_NUMBER), number); 239 profile->SetInfo(PHONE_HOME_NUMBER, number);
240 profile->SetInfo(AutofillType(PHONE_HOME_CITY_CODE), city_code); 240 profile->SetInfo(PHONE_HOME_CITY_CODE, city_code);
241 profile->SetInfo(AutofillType(PHONE_HOME_COUNTRY_CODE), country_code); 241 profile->SetInfo(PHONE_HOME_COUNTRY_CODE, country_code);
242 } else if ([addressLabelRaw isEqualToString:kABAddressWorkLabel] && 242 } else if ([addressLabelRaw isEqualToString:kABAddressWorkLabel] &&
243 [phoneLabelRaw isEqualToString:kABPhoneWorkFAXLabel]) { 243 [phoneLabelRaw isEqualToString:kABPhoneWorkFAXLabel]) {
244 string16 workFax = base::SysNSStringToUTF16( 244 string16 workFax = base::SysNSStringToUTF16(
245 [phoneNumbers valueAtIndex:reverseK]); 245 [phoneNumbers valueAtIndex:reverseK]);
246 PhoneNumber::ParsePhoneNumber(workFax, 246 PhoneNumber::ParsePhoneNumber(workFax,
247 &number, &city_code, &country_code); 247 &number, &city_code, &country_code);
248 profile->SetInfo(AutofillType(PHONE_FAX_NUMBER), number); 248 profile->SetInfo(PHONE_FAX_NUMBER, number);
249 profile->SetInfo(AutofillType(PHONE_FAX_CITY_CODE), city_code); 249 profile->SetInfo(PHONE_FAX_CITY_CODE, city_code);
250 profile->SetInfo(AutofillType(PHONE_FAX_COUNTRY_CODE), country_code); 250 profile->SetInfo(PHONE_FAX_COUNTRY_CODE, country_code);
251 } 251 }
252 } 252 }
253 } 253 }
254 254
255 } // namespace 255 } // namespace
256 256
257 // Populate |auxiliary_profiles_| with the Address Book data. 257 // Populate |auxiliary_profiles_| with the Address Book data.
258 void PersonalDataManager::LoadAuxiliaryProfiles() { 258 void PersonalDataManager::LoadAuxiliaryProfiles() {
259 AuxiliaryProfilesImpl impl(&auxiliary_profiles_); 259 AuxiliaryProfilesImpl impl(&auxiliary_profiles_);
260 impl.GetAddressBookMeCard(); 260 impl.GetAddressBookMeCard();
261 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698