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

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

Powered by Google App Engine
This is Rietveld 408576698