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

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: sync 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(const std::string& app_locale,
52 NSDictionary* address,
53 AutofillProfile* profile);
52 void GetAddressBookEmail(ABPerson* me, 54 void GetAddressBookEmail(ABPerson* me,
53 NSString* addressLabelRaw, 55 NSString* addressLabelRaw,
54 AutofillProfile* profile); 56 AutofillProfile* profile);
55 void GetAddressBookPhoneNumbers(ABPerson* me, 57 void GetAddressBookPhoneNumbers(ABPerson* me,
56 NSString* addressLabelRaw, 58 NSString* addressLabelRaw,
57 AutofillProfile* profile); 59 AutofillProfile* profile);
58 60
59 private: 61 private:
60 // A reference to the profiles this class populates. 62 // A reference to the profiles this class populates.
61 ScopedVector<AutofillProfile>& profiles_; 63 ScopedVector<AutofillProfile>& profiles_;
62 64
63 DISALLOW_COPY_AND_ASSIGN(AuxiliaryProfilesImpl); 65 DISALLOW_COPY_AND_ASSIGN(AuxiliaryProfilesImpl);
64 }; 66 };
65 67
66 // This method uses the |ABAddressBook| system service to fetch the "me" card 68 // 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 69 // 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 70 // information and translates it to the internal list of |AutofillProfile| data
69 // structures. 71 // structures.
70 void AuxiliaryProfilesImpl::GetAddressBookMeCard() { 72 void AuxiliaryProfilesImpl::GetAddressBookMeCard(
73 const std::string& app_locale) {
71 profiles_.clear(); 74 profiles_.clear();
72 75
73 // +[ABAddressBook sharedAddressBook] throws an exception internally in 76 // +[ABAddressBook sharedAddressBook] throws an exception internally in
74 // circumstances that aren't clear. The exceptions are only observed in crash 77 // 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 78 // 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 79 // returned, or if they would take down the app. In either case, avoid
77 // crashing. http://crbug.com/129022 80 // crashing. http://crbug.com/129022
78 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions(^{ 81 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions(^{
79 return [ABAddressBook sharedAddressBook]; 82 return [ABAddressBook sharedAddressBook];
80 }); 83 });
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 guid += base::StringPrintf(kAddressGUIDFormat.c_str(), i); 118 guid += base::StringPrintf(kAddressGUIDFormat.c_str(), i);
116 DCHECK_EQ(kGUIDLength, guid.size()); 119 DCHECK_EQ(kGUIDLength, guid.size());
117 120
118 scoped_ptr<AutofillProfile> profile(new AutofillProfile(guid)); 121 scoped_ptr<AutofillProfile> profile(new AutofillProfile(guid));
119 DCHECK(base::IsValidGUID(profile->guid())); 122 DCHECK(base::IsValidGUID(profile->guid()));
120 123
121 // Fill in name and company information. 124 // Fill in name and company information.
122 GetAddressBookNames(me, addressLabelRaw, profile.get()); 125 GetAddressBookNames(me, addressLabelRaw, profile.get());
123 126
124 // Fill in address information. 127 // Fill in address information.
125 GetAddressBookAddress(address, profile.get()); 128 GetAddressBookAddress(app_locale, address, profile.get());
126 129
127 // Fill in email information. 130 // Fill in email information.
128 GetAddressBookEmail(me, addressLabelRaw, profile.get()); 131 GetAddressBookEmail(me, addressLabelRaw, profile.get());
129 132
130 // Fill in phone number information. 133 // Fill in phone number information.
131 GetAddressBookPhoneNumbers(me, addressLabelRaw, profile.get()); 134 GetAddressBookPhoneNumbers(me, addressLabelRaw, profile.get());
132 135
133 profiles_.push_back(profile.release()); 136 profiles_.push_back(profile.release());
134 } 137 }
135 } 138 }
(...skipping 15 matching lines...) Expand all
151 profile->SetRawInfo(NAME_LAST, base::SysNSStringToUTF16(lastName)); 154 profile->SetRawInfo(NAME_LAST, base::SysNSStringToUTF16(lastName));
152 if ([addressLabelRaw isEqualToString:kABAddressWorkLabel]) 155 if ([addressLabelRaw isEqualToString:kABAddressWorkLabel])
153 profile->SetRawInfo(COMPANY_NAME, base::SysNSStringToUTF16(companyName)); 156 profile->SetRawInfo(COMPANY_NAME, base::SysNSStringToUTF16(companyName));
154 } 157 }
155 158
156 // Addresss information from the Address Book may span multiple lines. 159 // 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 160 // If it does then we represent the address with two lines in the profile. The
158 // second line we join with commas. 161 // second line we join with commas.
159 // For example: "c/o John Doe\n1122 Other Avenue\nApt #7" translates to 162 // 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". 163 // line 1: "c/o John Doe", line 2: "1122 Other Avenue, Apt #7".
161 void AuxiliaryProfilesImpl::GetAddressBookAddress(NSDictionary* address, 164 void AuxiliaryProfilesImpl::GetAddressBookAddress(const std::string& app_locale,
165 NSDictionary* address,
162 AutofillProfile* profile) { 166 AutofillProfile* profile) {
163 if (NSString* addressField = [address objectForKey:kABAddressStreetKey]) { 167 if (NSString* addressField = [address objectForKey:kABAddressStreetKey]) {
164 // If there are newlines in the address, split into two lines. 168 // If there are newlines in the address, split into two lines.
165 if ([addressField rangeOfCharacterFromSet: 169 if ([addressField rangeOfCharacterFromSet:
166 [NSCharacterSet newlineCharacterSet]].location != NSNotFound) { 170 [NSCharacterSet newlineCharacterSet]].location != NSNotFound) {
167 NSArray* chunks = [addressField componentsSeparatedByCharactersInSet: 171 NSArray* chunks = [addressField componentsSeparatedByCharactersInSet:
168 [NSCharacterSet newlineCharacterSet]]; 172 [NSCharacterSet newlineCharacterSet]];
169 DCHECK([chunks count] > 1); 173 DCHECK([chunks count] > 1);
170 174
171 NSString* separator = l10n_util::GetNSString( 175 NSString* separator = l10n_util::GetNSString(
(...skipping 18 matching lines...) Expand all
190 194
191 if (NSString* state = [address objectForKey:kABAddressStateKey]) 195 if (NSString* state = [address objectForKey:kABAddressStateKey])
192 profile->SetRawInfo(ADDRESS_HOME_STATE, base::SysNSStringToUTF16(state)); 196 profile->SetRawInfo(ADDRESS_HOME_STATE, base::SysNSStringToUTF16(state));
193 197
194 if (NSString* zip = [address objectForKey:kABAddressZIPKey]) 198 if (NSString* zip = [address objectForKey:kABAddressZIPKey])
195 profile->SetRawInfo(ADDRESS_HOME_ZIP, base::SysNSStringToUTF16(zip)); 199 profile->SetRawInfo(ADDRESS_HOME_ZIP, base::SysNSStringToUTF16(zip));
196 200
197 if (NSString* country = [address objectForKey:kABAddressCountryKey]) { 201 if (NSString* country = [address objectForKey:kABAddressCountryKey]) {
198 profile->SetInfo(ADDRESS_HOME_COUNTRY, 202 profile->SetInfo(ADDRESS_HOME_COUNTRY,
199 base::SysNSStringToUTF16(country), 203 base::SysNSStringToUTF16(country),
200 AutofillCountry::ApplicationLocale()); 204 app_locale);
201 } 205 }
202 } 206 }
203 207
204 // Fills in email address matching current address label. Note that there may 208 // 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 209 // be multiple matching email addresses for a given label. We take the
206 // first we find (topmost) as preferred. 210 // first we find (topmost) as preferred.
207 void AuxiliaryProfilesImpl::GetAddressBookEmail( 211 void AuxiliaryProfilesImpl::GetAddressBookEmail(
208 ABPerson* me, 212 ABPerson* me,
209 NSString* addressLabelRaw, 213 NSString* addressLabelRaw,
210 AutofillProfile* profile) { 214 AutofillProfile* profile) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, phone); 255 profile->SetRawInfo(PHONE_HOME_WHOLE_NUMBER, phone);
252 } 256 }
253 } 257 }
254 } 258 }
255 259
256 } // namespace 260 } // namespace
257 261
258 // Populate |auxiliary_profiles_| with the Address Book data. 262 // Populate |auxiliary_profiles_| with the Address Book data.
259 void PersonalDataManager::LoadAuxiliaryProfiles() { 263 void PersonalDataManager::LoadAuxiliaryProfiles() {
260 AuxiliaryProfilesImpl impl(&auxiliary_profiles_); 264 AuxiliaryProfilesImpl impl(&auxiliary_profiles_);
261 impl.GetAddressBookMeCard(); 265 impl.GetAddressBookMeCard(app_locale_);
262 } 266 }
OLDNEW
« no previous file with comments | « components/autofill/browser/personal_data_manager.cc ('k') | components/autofill/browser/personal_data_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698