OLD | NEW |
(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/memory/ptr_util.h" |
| 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "components/autofill/core/browser/region_combobox_model.h" |
| 10 #include "components/autofill/core/browser/region_data_loader.h" |
| 11 #include "ui/base/models/combobox_model.h" |
| 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
| 17 namespace { |
| 18 const int64_t kTimeoutInMilliseconds = 5000; |
| 19 } // namespace |
| 20 |
| 21 RegionDataLoader::RegionDataLoader(id<RegionDataLoaderConsumer> consumer) |
| 22 : consumer_(consumer), |
| 23 region_model_(base::MakeUnique<autofill::RegionComboboxModel>()) { |
| 24 region_model_->AddObserver(this); |
| 25 } |
| 26 |
| 27 RegionDataLoader::~RegionDataLoader() { |
| 28 region_model_->RemoveObserver(this); |
| 29 } |
| 30 |
| 31 void RegionDataLoader::LoadRegionData( |
| 32 const std::string& country_code, |
| 33 autofill::RegionDataLoader* autofill_region_data_loader) { |
| 34 region_model_->LoadRegionData(country_code, autofill_region_data_loader, |
| 35 kTimeoutInMilliseconds); |
| 36 } |
| 37 |
| 38 void RegionDataLoader::OnComboboxModelChanged(ui::ComboboxModel* model) { |
| 39 autofill::RegionComboboxModel* region_model = |
| 40 static_cast<autofill::RegionComboboxModel*>(model); |
| 41 if (region_model->IsPendingRegionDataLoad()) |
| 42 return; |
| 43 |
| 44 NSMutableArray<NSString*>* regions = [[NSMutableArray alloc] init]; |
| 45 if (!region_model->failed_to_load_data()) { |
| 46 for (int i = 0; i < region_model->GetItemCount(); ++i) { |
| 47 if (!region_model->IsItemSeparatorAt(i)) |
| 48 [regions |
| 49 addObject:base::SysUTF16ToNSString(region_model->GetItemAt(i))]; |
| 50 } |
| 51 } |
| 52 [consumer_ regionDataLoaderDidSucceedWithRegions:regions]; |
| 53 } |
OLD | NEW |