Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 is a valid country code or a valid |
|
macourteau
2017/07/04 13:53:45
s/has //
Moe
2017/07/04 15:47:06
Done.
| |
| 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(1 == [[countries allKeysForObject:country] count]); | |
|
macourteau
2017/07/04 13:53:45
DCHECK -> DCHECK_EQ
Moe
2017/07/04 15:47:06
Done.
| |
| 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 Loading... | |
| 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 |
| OLD | NEW |