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

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

Issue 11360055: [Autofill] Rename GetInfo and SetInfo to GetRawInfo and SetRawInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase harder Created 8 years, 1 month 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <math.h> 7 #include <math.h>
8 8
9 #import <AddressBook/AddressBook.h> 9 #import <AddressBook/AddressBook.h>
10 10
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // We only propagate the company name to work profiles. 137 // We only propagate the company name to work profiles.
138 void AuxiliaryProfilesImpl::GetAddressBookNames( 138 void AuxiliaryProfilesImpl::GetAddressBookNames(
139 ABPerson* me, 139 ABPerson* me,
140 NSString* addressLabelRaw, 140 NSString* addressLabelRaw,
141 AutofillProfile* profile) { 141 AutofillProfile* profile) {
142 NSString* firstName = [me valueForProperty:kABFirstNameProperty]; 142 NSString* firstName = [me valueForProperty:kABFirstNameProperty];
143 NSString* middleName = [me valueForProperty:kABMiddleNameProperty]; 143 NSString* middleName = [me valueForProperty:kABMiddleNameProperty];
144 NSString* lastName = [me valueForProperty:kABLastNameProperty]; 144 NSString* lastName = [me valueForProperty:kABLastNameProperty];
145 NSString* companyName = [me valueForProperty:kABOrganizationProperty]; 145 NSString* companyName = [me valueForProperty:kABOrganizationProperty];
146 146
147 profile->SetInfo(NAME_FIRST, base::SysNSStringToUTF16(firstName)); 147 profile->SetRawInfo(NAME_FIRST, base::SysNSStringToUTF16(firstName));
148 profile->SetInfo(NAME_MIDDLE, base::SysNSStringToUTF16(middleName)); 148 profile->SetRawInfo(NAME_MIDDLE, base::SysNSStringToUTF16(middleName));
149 profile->SetInfo(NAME_LAST, base::SysNSStringToUTF16(lastName)); 149 profile->SetRawInfo(NAME_LAST, base::SysNSStringToUTF16(lastName));
150 if ([addressLabelRaw isEqualToString:kABAddressWorkLabel]) 150 if ([addressLabelRaw isEqualToString:kABAddressWorkLabel])
151 profile->SetInfo(COMPANY_NAME, base::SysNSStringToUTF16(companyName)); 151 profile->SetRawInfo(COMPANY_NAME, base::SysNSStringToUTF16(companyName));
152 } 152 }
153 153
154 // Addresss information from the Address Book may span multiple lines. 154 // Addresss information from the Address Book may span multiple lines.
155 // If it does then we represent the address with two lines in the profile. The 155 // If it does then we represent the address with two lines in the profile. The
156 // second line we join with commas. 156 // second line we join with commas.
157 // For example: "c/o John Doe\n1122 Other Avenue\nApt #7" translates to 157 // For example: "c/o John Doe\n1122 Other Avenue\nApt #7" translates to
158 // line 1: "c/o John Doe", line 2: "1122 Other Avenue, Apt #7". 158 // line 1: "c/o John Doe", line 2: "1122 Other Avenue, Apt #7".
159 void AuxiliaryProfilesImpl::GetAddressBookAddresses(NSDictionary* address, 159 void AuxiliaryProfilesImpl::GetAddressBookAddresses(NSDictionary* address,
160 AutofillProfile* profile) { 160 AutofillProfile* profile) {
161 if (NSString* addressField = [address objectForKey:kABAddressStreetKey]) { 161 if (NSString* addressField = [address objectForKey:kABAddressStreetKey]) {
162 // If there are newlines in the address, split into two lines. 162 // If there are newlines in the address, split into two lines.
163 if ([addressField rangeOfCharacterFromSet: 163 if ([addressField rangeOfCharacterFromSet:
164 [NSCharacterSet newlineCharacterSet]].location != NSNotFound) { 164 [NSCharacterSet newlineCharacterSet]].location != NSNotFound) {
165 NSArray* chunks = [addressField componentsSeparatedByCharactersInSet: 165 NSArray* chunks = [addressField componentsSeparatedByCharactersInSet:
166 [NSCharacterSet newlineCharacterSet]]; 166 [NSCharacterSet newlineCharacterSet]];
167 DCHECK([chunks count] > 1); 167 DCHECK([chunks count] > 1);
168 168
169 NSString* separator = l10n_util::GetNSString( 169 NSString* separator = l10n_util::GetNSString(
170 IDS_AUTOFILL_MAC_ADDRESS_LINE_SEPARATOR); 170 IDS_AUTOFILL_MAC_ADDRESS_LINE_SEPARATOR);
171 171
172 NSString* addressField1 = [chunks objectAtIndex:0]; 172 NSString* addressField1 = [chunks objectAtIndex:0];
173 NSString* addressField2 = 173 NSString* addressField2 =
174 [[chunks subarrayWithRange:NSMakeRange(1, [chunks count] - 1)] 174 [[chunks subarrayWithRange:NSMakeRange(1, [chunks count] - 1)]
175 componentsJoinedByString:separator]; 175 componentsJoinedByString:separator];
176 profile->SetInfo(ADDRESS_HOME_LINE1, 176 profile->SetRawInfo(ADDRESS_HOME_LINE1,
177 base::SysNSStringToUTF16(addressField1)); 177 base::SysNSStringToUTF16(addressField1));
178 profile->SetInfo(ADDRESS_HOME_LINE2, 178 profile->SetRawInfo(ADDRESS_HOME_LINE2,
179 base::SysNSStringToUTF16(addressField2)); 179 base::SysNSStringToUTF16(addressField2));
180 } else { 180 } else {
181 profile->SetInfo(ADDRESS_HOME_LINE1, 181 profile->SetRawInfo(ADDRESS_HOME_LINE1,
182 base::SysNSStringToUTF16(addressField)); 182 base::SysNSStringToUTF16(addressField));
183 } 183 }
184 } 184 }
185 185
186 if (NSString* city = [address objectForKey:kABAddressCityKey]) 186 if (NSString* city = [address objectForKey:kABAddressCityKey])
187 profile->SetInfo(ADDRESS_HOME_CITY, base::SysNSStringToUTF16(city)); 187 profile->SetRawInfo(ADDRESS_HOME_CITY, base::SysNSStringToUTF16(city));
188
188 if (NSString* state = [address objectForKey:kABAddressStateKey]) 189 if (NSString* state = [address objectForKey:kABAddressStateKey])
189 profile->SetInfo(ADDRESS_HOME_STATE, base::SysNSStringToUTF16(state)); 190 profile->SetRawInfo(ADDRESS_HOME_STATE, base::SysNSStringToUTF16(state));
191
190 if (NSString* zip = [address objectForKey:kABAddressZIPKey]) 192 if (NSString* zip = [address objectForKey:kABAddressZIPKey])
191 profile->SetInfo(ADDRESS_HOME_ZIP, base::SysNSStringToUTF16(zip)); 193 profile->SetRawInfo(ADDRESS_HOME_ZIP, base::SysNSStringToUTF16(zip));
192 if (NSString* country = [address objectForKey:kABAddressCountryKey]) 194
193 profile->SetInfo(ADDRESS_HOME_COUNTRY, base::SysNSStringToUTF16(country)); 195 if (NSString* country = [address objectForKey:kABAddressCountryKey]) {
196 profile->SetRawInfo(ADDRESS_HOME_COUNTRY,
197 base::SysNSStringToUTF16(country));
198 }
194 } 199 }
195 200
196 // Fills in email address matching current address label. Note that there may 201 // Fills in email address matching current address label. Note that there may
197 // be multiple matching email addresses for a given label. We take the 202 // be multiple matching email addresses for a given label. We take the
198 // first we find (topmost) as preferred. 203 // first we find (topmost) as preferred.
199 void AuxiliaryProfilesImpl::GetAddressBookEmail( 204 void AuxiliaryProfilesImpl::GetAddressBookEmail(
200 ABPerson* me, 205 ABPerson* me,
201 NSString* addressLabelRaw, 206 NSString* addressLabelRaw,
202 AutofillProfile* profile) { 207 AutofillProfile* profile) {
203 ABMultiValue* emailAddresses = [me valueForProperty:kABEmailProperty]; 208 ABMultiValue* emailAddresses = [me valueForProperty:kABEmailProperty];
204 NSString* emailAddress = nil; 209 NSString* emailAddress = nil;
205 for (NSUInteger j = 0, emailCount = [emailAddresses count]; 210 for (NSUInteger j = 0, emailCount = [emailAddresses count];
206 j < emailCount; j++) { 211 j < emailCount; j++) {
207 NSString* emailAddressLabelRaw = [emailAddresses labelAtIndex:j]; 212 NSString* emailAddressLabelRaw = [emailAddresses labelAtIndex:j];
208 if ([emailAddressLabelRaw isEqualToString:addressLabelRaw]) { 213 if ([emailAddressLabelRaw isEqualToString:addressLabelRaw]) {
209 emailAddress = [emailAddresses valueAtIndex:j]; 214 emailAddress = [emailAddresses valueAtIndex:j];
210 break; 215 break;
211 } 216 }
212 } 217 }
213 profile->SetInfo(EMAIL_ADDRESS, base::SysNSStringToUTF16(emailAddress)); 218 profile->SetRawInfo(EMAIL_ADDRESS, base::SysNSStringToUTF16(emailAddress));
214 } 219 }
215 220
216 // Fills in telephone numbers. Each of these are special cases. 221 // Fills in telephone numbers. Each of these are special cases.
217 // We match two cases: home/tel, work/tel. 222 // We match two cases: home/tel, work/tel.
218 // Note, we traverse in reverse order so that top values in address book 223 // Note, we traverse in reverse order so that top values in address book
219 // take priority. 224 // take priority.
220 void AuxiliaryProfilesImpl::GetAddressBookPhoneNumbers( 225 void AuxiliaryProfilesImpl::GetAddressBookPhoneNumbers(
221 ABPerson* me, 226 ABPerson* me,
222 NSString* addressLabelRaw, 227 NSString* addressLabelRaw,
223 AutofillProfile* profile) { 228 AutofillProfile* profile) {
224 ABMultiValue* phoneNumbers = [me valueForProperty:kABPhoneProperty]; 229 ABMultiValue* phoneNumbers = [me valueForProperty:kABPhoneProperty];
225 for (NSUInteger k = 0, phoneCount = [phoneNumbers count]; 230 for (NSUInteger k = 0, phoneCount = [phoneNumbers count];
226 k < phoneCount; k++) { 231 k < phoneCount; k++) {
227 NSUInteger reverseK = phoneCount - k - 1; 232 NSUInteger reverseK = phoneCount - k - 1;
228 NSString* phoneLabelRaw = [phoneNumbers labelAtIndex:reverseK]; 233 NSString* phoneLabelRaw = [phoneNumbers labelAtIndex:reverseK];
229 if ([addressLabelRaw isEqualToString:kABAddressHomeLabel] && 234 if ([addressLabelRaw isEqualToString:kABAddressHomeLabel] &&
230 [phoneLabelRaw isEqualToString:kABPhoneHomeLabel]) { 235 [phoneLabelRaw isEqualToString:kABPhoneHomeLabel]) {
231 string16 homePhone = base::SysNSStringToUTF16( 236 string16 homePhone = base::SysNSStringToUTF16(
232 [phoneNumbers valueAtIndex:reverseK]); 237 [phoneNumbers valueAtIndex:reverseK]);
233 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, homePhone); 238 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, homePhone);
234 } else if ([addressLabelRaw isEqualToString:kABAddressWorkLabel] && 239 } else if ([addressLabelRaw isEqualToString:kABAddressWorkLabel] &&
235 [phoneLabelRaw isEqualToString:kABPhoneWorkLabel]) { 240 [phoneLabelRaw isEqualToString:kABPhoneWorkLabel]) {
236 string16 workPhone = base::SysNSStringToUTF16( 241 string16 workPhone = base::SysNSStringToUTF16(
237 [phoneNumbers valueAtIndex:reverseK]); 242 [phoneNumbers valueAtIndex:reverseK]);
238 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, workPhone); 243 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, workPhone);
239 } else if ([phoneLabelRaw isEqualToString:kABPhoneMobileLabel] || 244 } else if ([phoneLabelRaw isEqualToString:kABPhoneMobileLabel] ||
240 [phoneLabelRaw isEqualToString:kABPhoneMainLabel]) { 245 [phoneLabelRaw isEqualToString:kABPhoneMainLabel]) {
241 string16 phone = base::SysNSStringToUTF16( 246 string16 phone = base::SysNSStringToUTF16(
242 [phoneNumbers valueAtIndex:reverseK]); 247 [phoneNumbers valueAtIndex:reverseK]);
243 profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, phone); 248 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, phone);
244 } 249 }
245 } 250 }
246 } 251 }
247 252
248 } // namespace 253 } // namespace
249 254
250 // Populate |auxiliary_profiles_| with the Address Book data. 255 // Populate |auxiliary_profiles_| with the Address Book data.
251 void PersonalDataManager::LoadAuxiliaryProfiles() const { 256 void PersonalDataManager::LoadAuxiliaryProfiles() const {
252 AuxiliaryProfilesImpl impl(&auxiliary_profiles_); 257 AuxiliaryProfilesImpl impl(&auxiliary_profiles_);
253 impl.GetAddressBookMeCard(); 258 impl.GetAddressBookMeCard();
254 } 259 }
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