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

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

Issue 13488009: Remove application locale cache in autofill code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 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) 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 "components/autofill/browser/personal_data_manager.h" 5 #include "components/autofill/browser/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 24 matching lines...) Expand all
35 public: 35 public:
36 // Constructor takes a reference to the |profiles| that will be filled in 36 // Constructor takes a reference to the |profiles| that will be filled in
37 // by the subsequent call to |GetAddressBookMeCard()|. |profiles| may not 37 // by the subsequent call to |GetAddressBookMeCard()|. |profiles| may not
38 // be NULL. 38 // be NULL.
39 explicit AuxiliaryProfilesImpl(ScopedVector<AutofillProfile>* profiles) 39 explicit AuxiliaryProfilesImpl(ScopedVector<AutofillProfile>* profiles)
40 : profiles_(*profiles) { 40 : profiles_(*profiles) {
41 } 41 }
42 virtual ~AuxiliaryProfilesImpl() {} 42 virtual ~AuxiliaryProfilesImpl() {}
43 43
44 // Import the "me" card from the Mac Address Book and fill in |profiles_|. 44 // Import the "me" card from the Mac Address Book and fill in |profiles_|.
45 void GetAddressBookMeCard(); 45 void GetAddressBookMeCard(const std::string& app_locale);
46 46
47 private: 47 private:
48 void GetAddressBookNames(ABPerson* me, 48 void GetAddressBookNames(ABPerson* me,
49 NSString* addressLabelRaw, 49 NSString* addressLabelRaw,
50 AutofillProfile* profile); 50 AutofillProfile* profile);
51 void GetAddressBookAddress(NSDictionary* address, AutofillProfile* profile); 51 void GetAddressBookAddress(NSDictionary* address, AutofillProfile* profile);
52 void GetAddressBookEmail(ABPerson* me, 52 void GetAddressBookEmail(ABPerson* me,
53 NSString* addressLabelRaw, 53 NSString* addressLabelRaw,
54 AutofillProfile* profile); 54 AutofillProfile* profile);
55 void GetAddressBookPhoneNumbers(ABPerson* me, 55 void GetAddressBookPhoneNumbers(ABPerson* me,
56 NSString* addressLabelRaw, 56 NSString* addressLabelRaw,
57 AutofillProfile* profile); 57 AutofillProfile* profile);
58 58
59 private: 59 private:
60 // A reference to the profiles this class populates. 60 // A reference to the profiles this class populates.
61 ScopedVector<AutofillProfile>& profiles_; 61 ScopedVector<AutofillProfile>& profiles_;
62 62
63 DISALLOW_COPY_AND_ASSIGN(AuxiliaryProfilesImpl); 63 DISALLOW_COPY_AND_ASSIGN(AuxiliaryProfilesImpl);
64 }; 64 };
65 65
66 // This method uses the |ABAddressBook| system service to fetch the "me" card 66 // This method uses the |ABAddressBook| system service to fetch the "me" card
67 // from the active user's address book. It looks for the user address 67 // from the active user's address book. It looks for the user address
68 // information and translates it to the internal list of |AutofillProfile| data 68 // information and translates it to the internal list of |AutofillProfile| data
69 // structures. 69 // structures.
70 void AuxiliaryProfilesImpl::GetAddressBookMeCard() { 70 void AuxiliaryProfilesImpl::GetAddressBookMeCard(
71 const std::string& app_locale) {
71 profiles_.clear(); 72 profiles_.clear();
72 73
73 // +[ABAddressBook sharedAddressBook] throws an exception internally in 74 // +[ABAddressBook sharedAddressBook] throws an exception internally in
74 // circumstances that aren't clear. The exceptions are only observed in crash 75 // circumstances that aren't clear. The exceptions are only observed in crash
75 // reports, so it is unknown whether they would be caught by AppKit and nil 76 // reports, so it is unknown whether they would be caught by AppKit and nil
76 // returned, or if they would take down the app. In either case, avoid 77 // returned, or if they would take down the app. In either case, avoid
77 // crashing. http://crbug.com/129022 78 // crashing. http://crbug.com/129022
78 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions(^{ 79 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions(^{
79 return [ABAddressBook sharedAddressBook]; 80 return [ABAddressBook sharedAddressBook];
80 }); 81 });
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 guid += base::StringPrintf(kAddressGUIDFormat.c_str(), i); 116 guid += base::StringPrintf(kAddressGUIDFormat.c_str(), i);
116 DCHECK_EQ(kGUIDLength, guid.size()); 117 DCHECK_EQ(kGUIDLength, guid.size());
117 118
118 scoped_ptr<AutofillProfile> profile(new AutofillProfile(guid)); 119 scoped_ptr<AutofillProfile> profile(new AutofillProfile(guid));
119 DCHECK(base::IsValidGUID(profile->guid())); 120 DCHECK(base::IsValidGUID(profile->guid()));
120 121
121 // Fill in name and company information. 122 // Fill in name and company information.
122 GetAddressBookNames(me, addressLabelRaw, profile.get()); 123 GetAddressBookNames(me, addressLabelRaw, profile.get());
123 124
124 // Fill in address information. 125 // Fill in address information.
125 GetAddressBookAddress(address, profile.get()); 126 GetAddressBookAddress(app_locale, address, profile.get());
126 127
127 // Fill in email information. 128 // Fill in email information.
128 GetAddressBookEmail(me, addressLabelRaw, profile.get()); 129 GetAddressBookEmail(me, addressLabelRaw, profile.get());
129 130
130 // Fill in phone number information. 131 // Fill in phone number information.
131 GetAddressBookPhoneNumbers(me, addressLabelRaw, profile.get()); 132 GetAddressBookPhoneNumbers(me, addressLabelRaw, profile.get());
132 133
133 profiles_.push_back(profile.release()); 134 profiles_.push_back(profile.release());
134 } 135 }
135 } 136 }
(...skipping 15 matching lines...) Expand all
151 profile->SetRawInfo(NAME_LAST, base::SysNSStringToUTF16(lastName)); 152 profile->SetRawInfo(NAME_LAST, base::SysNSStringToUTF16(lastName));
152 if ([addressLabelRaw isEqualToString:kABAddressWorkLabel]) 153 if ([addressLabelRaw isEqualToString:kABAddressWorkLabel])
153 profile->SetRawInfo(COMPANY_NAME, base::SysNSStringToUTF16(companyName)); 154 profile->SetRawInfo(COMPANY_NAME, base::SysNSStringToUTF16(companyName));
154 } 155 }
155 156
156 // Addresss information from the Address Book may span multiple lines. 157 // Addresss information from the Address Book may span multiple lines.
157 // If it does then we represent the address with two lines in the profile. The 158 // If it does then we represent the address with two lines in the profile. The
158 // second line we join with commas. 159 // second line we join with commas.
159 // For example: "c/o John Doe\n1122 Other Avenue\nApt #7" translates to 160 // For example: "c/o John Doe\n1122 Other Avenue\nApt #7" translates to
160 // line 1: "c/o John Doe", line 2: "1122 Other Avenue, Apt #7". 161 // line 1: "c/o John Doe", line 2: "1122 Other Avenue, Apt #7".
161 void AuxiliaryProfilesImpl::GetAddressBookAddress(NSDictionary* address, 162 void AuxiliaryProfilesImpl::GetAddressBookAddress(const std::string& app_locale,
163 NSDictionary* address,
162 AutofillProfile* profile) { 164 AutofillProfile* profile) {
163 if (NSString* addressField = [address objectForKey:kABAddressStreetKey]) { 165 if (NSString* addressField = [address objectForKey:kABAddressStreetKey]) {
164 // If there are newlines in the address, split into two lines. 166 // If there are newlines in the address, split into two lines.
165 if ([addressField rangeOfCharacterFromSet: 167 if ([addressField rangeOfCharacterFromSet:
166 [NSCharacterSet newlineCharacterSet]].location != NSNotFound) { 168 [NSCharacterSet newlineCharacterSet]].location != NSNotFound) {
167 NSArray* chunks = [addressField componentsSeparatedByCharactersInSet: 169 NSArray* chunks = [addressField componentsSeparatedByCharactersInSet:
168 [NSCharacterSet newlineCharacterSet]]; 170 [NSCharacterSet newlineCharacterSet]];
169 DCHECK([chunks count] > 1); 171 DCHECK([chunks count] > 1);
170 172
171 NSString* separator = l10n_util::GetNSString( 173 NSString* separator = l10n_util::GetNSString(
(...skipping 18 matching lines...) Expand all
190 192
191 if (NSString* state = [address objectForKey:kABAddressStateKey]) 193 if (NSString* state = [address objectForKey:kABAddressStateKey])
192 profile->SetRawInfo(ADDRESS_HOME_STATE, base::SysNSStringToUTF16(state)); 194 profile->SetRawInfo(ADDRESS_HOME_STATE, base::SysNSStringToUTF16(state));
193 195
194 if (NSString* zip = [address objectForKey:kABAddressZIPKey]) 196 if (NSString* zip = [address objectForKey:kABAddressZIPKey])
195 profile->SetRawInfo(ADDRESS_HOME_ZIP, base::SysNSStringToUTF16(zip)); 197 profile->SetRawInfo(ADDRESS_HOME_ZIP, base::SysNSStringToUTF16(zip));
196 198
197 if (NSString* country = [address objectForKey:kABAddressCountryKey]) { 199 if (NSString* country = [address objectForKey:kABAddressCountryKey]) {
198 profile->SetInfo(ADDRESS_HOME_COUNTRY, 200 profile->SetInfo(ADDRESS_HOME_COUNTRY,
199 base::SysNSStringToUTF16(country), 201 base::SysNSStringToUTF16(country),
200 AutofillCountry::ApplicationLocale()); 202 app_locale);
201 } 203 }
202 } 204 }
203 205
204 // Fills in email address matching current address label. Note that there may 206 // Fills in email address matching current address label. Note that there may
205 // be multiple matching email addresses for a given label. We take the 207 // be multiple matching email addresses for a given label. We take the
206 // first we find (topmost) as preferred. 208 // first we find (topmost) as preferred.
207 void AuxiliaryProfilesImpl::GetAddressBookEmail( 209 void AuxiliaryProfilesImpl::GetAddressBookEmail(
208 ABPerson* me, 210 ABPerson* me,
209 NSString* addressLabelRaw, 211 NSString* addressLabelRaw,
210 AutofillProfile* profile) { 212 AutofillProfile* profile) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, phone); 253 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, phone);
252 } 254 }
253 } 255 }
254 } 256 }
255 257
256 } // namespace 258 } // namespace
257 259
258 // Populate |auxiliary_profiles_| with the Address Book data. 260 // Populate |auxiliary_profiles_| with the Address Book data.
259 void PersonalDataManager::LoadAuxiliaryProfiles() { 261 void PersonalDataManager::LoadAuxiliaryProfiles() {
260 AuxiliaryProfilesImpl impl(&auxiliary_profiles_); 262 AuxiliaryProfilesImpl impl(&auxiliary_profiles_);
261 impl.GetAddressBookMeCard(); 263 impl.GetAddressBookMeCard(app_locale_);
262 } 264 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698