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

Side by Side Diff: ios/chrome/browser/ui/payments/address_edit_mediator.mm

Issue 2964333002: [Payment Request] Populates country field if country code/name is valid. (Closed)
Patch Set: Addressed comments Created 3 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #import "ios/chrome/browser/ui/payments/address_edit_mediator.h" 5 #import "ios/chrome/browser/ui/payments/address_edit_mediator.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // field value is set to the respective region code. Otherwise, it is set to 146 // field value is set to the respective region code. Otherwise, it is set to
147 // nil. 147 // nil.
148 self.regionField.value = nil; 148 self.regionField.value = nil;
149 if (self.address) { 149 if (self.address) {
150 NSString* region = 150 NSString* region =
151 [self fieldValueFromProfile:self.address 151 [self fieldValueFromProfile:self.address
152 fieldType:autofill::ADDRESS_HOME_STATE]; 152 fieldType:autofill::ADDRESS_HOME_STATE];
153 if ([regions objectForKey:region]) { 153 if ([regions objectForKey:region]) {
154 self.regionField.value = region; 154 self.regionField.value = region;
155 } else if ([[regions allKeysForObject:region] count]) { 155 } else if ([[regions allKeysForObject:region] count]) {
156 DCHECK(1 == [[regions allKeysForObject:region] count]); 156 DCHECK_EQ(1U, [[regions allKeysForObject:region] count]);
157 self.regionField.value = [regions allKeysForObject:region][0]; 157 self.regionField.value = [regions allKeysForObject:region][0];
158 } 158 }
159 } 159 }
160 160
161 // Notify the view controller asynchronously to allow for the view to update. 161 // Notify the view controller asynchronously to allow for the view to update.
162 __weak AddressEditMediator* weakSelf = self; 162 __weak AddressEditMediator* weakSelf = self;
163 dispatch_async(dispatch_get_main_queue(), ^{ 163 dispatch_async(dispatch_get_main_queue(), ^{
164 [weakSelf.consumer setOptions:@[ [regions allKeys] ] 164 [weakSelf.consumer setOptions:@[ [regions allKeys] ]
165 forEditorField:weakSelf.regionField]; 165 forEditorField:weakSelf.regionField];
166 }); 166 });
(...skipping 15 matching lines...) Expand all
182 initWithCapacity:static_cast<NSUInteger>(countriesVector.size())]; 182 initWithCapacity:static_cast<NSUInteger>(countriesVector.size())];
183 for (size_t i = 0; i < countriesVector.size(); ++i) { 183 for (size_t i = 0; i < countriesVector.size(); ++i) {
184 if (countriesVector[i].get()) { 184 if (countriesVector[i].get()) {
185 [countries setObject:base::SysUTF16ToNSString(countriesVector[i]->name()) 185 [countries setObject:base::SysUTF16ToNSString(countriesVector[i]->name())
186 forKey:base::SysUTF8ToNSString( 186 forKey:base::SysUTF8ToNSString(
187 countriesVector[i]->country_code())]; 187 countriesVector[i]->country_code())];
188 } 188 }
189 } 189 }
190 _countries = countries; 190 _countries = countries;
191 191
192 // If an address is being edited and it has a valid country code, the selected 192 // If an address is being edited and it has a valid country code or a valid
193 // country code is set to that value. Otherwise, it is set to the default 193 // country name for the autofill::ADDRESS_HOME_COUNTRY field, the selected
194 // country code. 194 // country code is set to the respective country code. Otherwise, the selected
195 NSString* countryCode = 195 // country code is set to the default country code.
196 NSString* country =
196 [self fieldValueFromProfile:_address 197 [self fieldValueFromProfile:_address
197 fieldType:autofill::ADDRESS_HOME_COUNTRY]; 198 fieldType:autofill::ADDRESS_HOME_COUNTRY];
198 _selectedCountryCode = 199
199 countryCode && [_countries objectForKey:countryCode] 200 if ([countries objectForKey:country]) {
200 ? countryCode 201 _selectedCountryCode = country;
201 : base::SysUTF8ToNSString(countryModel.GetDefaultCountryCode()); 202 } else if ([[countries allKeysForObject:country] count]) {
203 DCHECK_EQ(1U, [[countries allKeysForObject:country] count]);
204 _selectedCountryCode = [countries allKeysForObject:country][0];
205 } else {
206 _selectedCountryCode =
207 base::SysUTF8ToNSString(countryModel.GetDefaultCountryCode());
208 }
202 } 209 }
203 210
204 // Queries the region names based on the selected country code. 211 // Queries the region names based on the selected country code.
205 - (void)loadRegions { 212 - (void)loadRegions {
206 _regionDataLoader = base::MakeUnique<RegionDataLoader>(self); 213 _regionDataLoader = base::MakeUnique<RegionDataLoader>(self);
207 _regionDataLoader->LoadRegionData( 214 _regionDataLoader->LoadRegionData(
208 base::SysNSStringToUTF8(self.selectedCountryCode), 215 base::SysNSStringToUTF8(self.selectedCountryCode),
209 _paymentRequest->GetRegionDataLoader()); 216 _paymentRequest->GetRegionDataLoader());
210 } 217 }
211 218
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // corresponding field value. Returns nil if |profile| is nullptr. 350 // corresponding field value. Returns nil if |profile| is nullptr.
344 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile 351 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile
345 fieldType:(autofill::ServerFieldType)fieldType { 352 fieldType:(autofill::ServerFieldType)fieldType {
346 return profile ? base::SysUTF16ToNSString(profile->GetInfo( 353 return profile ? base::SysUTF16ToNSString(profile->GetInfo(
347 autofill::AutofillType(fieldType), 354 autofill::AutofillType(fieldType),
348 GetApplicationContext()->GetApplicationLocale())) 355 GetApplicationContext()->GetApplicationLocale()))
349 : nil; 356 : nil;
350 } 357 }
351 358
352 @end 359 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698