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

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

Issue 2893193002: [Payment Request] Region data loader (Closed)
Patch Set: Addressed comment Created 3 years, 7 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/payments/region_data_loader.h"
6
7 #include "base/strings/sys_string_conversions.h"
8 #include "components/autofill/core/browser/region_data_loader.h"
9 #include "ui/base/models/combobox_model.h"
10
11 #if !defined(__has_feature) || !__has_feature(objc_arc)
12 #error "This file requires ARC support."
13 #endif
14
15 namespace {
16 const int64_t kTimeoutInMilliseconds = 5000;
17 } // namespace
18
19 RegionDataLoader::RegionDataLoader(id<RegionDataLoaderConsumer> consumer)
20 : consumer_(consumer) {
21 region_model_.AddObserver(this);
22 }
23
24 RegionDataLoader::~RegionDataLoader() {
25 region_model_.RemoveObserver(this);
26 }
27
28 void RegionDataLoader::LoadRegionData(
29 const std::string& country_code,
30 autofill::RegionDataLoader* autofill_region_data_loader) {
31 region_model_.LoadRegionData(country_code, autofill_region_data_loader,
32 kTimeoutInMilliseconds);
33 }
34
35 void RegionDataLoader::OnComboboxModelChanged(ui::ComboboxModel* model) {
36 autofill::RegionComboboxModel* region_model =
37 static_cast<autofill::RegionComboboxModel*>(model);
38 if (region_model->IsPendingRegionDataLoad())
39 return;
40
41 NSMutableArray<NSString*>* regions = [[NSMutableArray alloc] init];
42 if (!region_model->failed_to_load_data()) {
43 for (int i = 0; i < region_model->GetItemCount(); ++i) {
44 if (!region_model->IsItemSeparatorAt(i))
45 [regions
46 addObject:base::SysUTF16ToNSString(region_model->GetItemAt(i))];
47 }
48 }
49 [consumer_ regionDataLoaderDidSucceedWithRegions:regions];
50 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/payments/region_data_loader.h ('k') | ios/chrome/browser/ui/payments/region_data_loader_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698