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

Side by Side Diff: components/autofill/core/browser/region_combobox_model.h

Issue 2803443003: [Payments] Added region load failure tolerance and tests to PR editor. (Closed)
Patch Set: Removed unneeded include. Created 3 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
« no previous file with comments | « chrome/test/BUILD.gn ('k') | components/autofill/core/browser/region_combobox_model.cc » ('j') | 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 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_REGION_COMBOBOX_MODEL_H_ 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_REGION_COMBOBOX_MODEL_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_REGION_COMBOBOX_MODEL_H_ 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_REGION_COMBOBOX_MODEL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 18 matching lines...) Expand all
29 // ::i18n::addressinput::PreloadSupplier, |app_locale| is needed for 29 // ::i18n::addressinput::PreloadSupplier, |app_locale| is needed for
30 // ::i18n::addressinput::RegionDataBuilder and |country_code| identifies which 30 // ::i18n::addressinput::RegionDataBuilder and |country_code| identifies which
31 // country's region to load into the model. 31 // country's region to load into the model.
32 RegionComboboxModel( 32 RegionComboboxModel(
33 std::unique_ptr<const ::i18n::addressinput::Source> source, 33 std::unique_ptr<const ::i18n::addressinput::Source> source,
34 std::unique_ptr<::i18n::addressinput::Storage> storage, 34 std::unique_ptr<::i18n::addressinput::Storage> storage,
35 const std::string& app_locale, 35 const std::string& app_locale,
36 const std::string& country_code); 36 const std::string& country_code);
37 ~RegionComboboxModel() override; 37 ~RegionComboboxModel() override;
38 38
39 bool pending_region_data_load() const { return pending_region_data_load_; }
40 bool failed_to_load_data() const { return failed_to_load_data_; }
41
39 // ui::ComboboxModel implementation: 42 // ui::ComboboxModel implementation:
40 int GetItemCount() const override; 43 int GetItemCount() const override;
41 base::string16 GetItemAt(int index) override; 44 base::string16 GetItemAt(int index) override;
42 bool IsItemSeparatorAt(int index) override; 45 bool IsItemSeparatorAt(int index) override;
43 void AddObserver(ui::ComboboxModelObserver* observer) override; 46 void AddObserver(ui::ComboboxModelObserver* observer) override;
44 void RemoveObserver(ui::ComboboxModelObserver* observer) override; 47 void RemoveObserver(ui::ComboboxModelObserver* observer) override;
45 48
49 // To allow testing failure states.
50 void SetFailureModeForTests(bool failed_to_load_data);
51
52 private:
53 // Start the potentially asynchronous process of loading region data.
54 void LoadRegionData(const std::string& country_code);
55
46 // Callback for ::i18n::addressinput::PreloadSupplier::LoadRules 56 // Callback for ::i18n::addressinput::PreloadSupplier::LoadRules
47 void RegionDataLoaded(bool success, const std::string&, int rule_count); 57 void RegionDataLoaded(bool success, const std::string&, int rule_count);
48 58
49 private:
50 // Whether the region data load failed or not. 59 // Whether the region data load failed or not.
51 bool failed_to_load_data_{false}; 60 bool failed_to_load_data_;
61
62 // Set to true during region data load, and false otherwise. Whether the load
63 // succeeded or not doesn't affect this value.
64 bool pending_region_data_load_;
52 65
53 // The application locale. 66 // The application locale.
54 const std::string app_locale_; 67 const std::string app_locale_;
55 68
56 // The callback to give to |region_data_supplier_| for async operations. 69 // The callback to give to |region_data_supplier_| for async operations.
57 ::i18n::addressinput::scoped_ptr< 70 ::i18n::addressinput::scoped_ptr<
58 ::i18n::addressinput::PreloadSupplier::Callback> 71 ::i18n::addressinput::PreloadSupplier::Callback>
59 region_data_supplier_callback_; 72 region_data_supplier_callback_;
60 73
61 // A supplier of region data. 74 // A supplier of region data.
62 ::i18n::addressinput::PreloadSupplier region_data_supplier_; 75 ::i18n::addressinput::PreloadSupplier region_data_supplier_;
63 76
64 // List of <code, name> pairs for ADDRESS_HOME_STATE combobox values; 77 // List of <code, name> pairs for ADDRESS_HOME_STATE combobox values;
65 std::vector<std::pair<std::string, std::string>> regions_; 78 std::vector<std::pair<std::string, std::string>> regions_;
66 79
67 // To be called when the data for the given country code was loaded. 80 // To be called when the data for the given country code was loaded.
68 base::ObserverList<ui::ComboboxModelObserver> observers_; 81 base::ObserverList<ui::ComboboxModelObserver> observers_;
69 82
70 DISALLOW_COPY_AND_ASSIGN(RegionComboboxModel); 83 DISALLOW_COPY_AND_ASSIGN(RegionComboboxModel);
71 }; 84 };
72 85
73 } // namespace autofill 86 } // namespace autofill
74 87
75 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_REGION_COMBOBOX_MODEL_H_ 88 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_REGION_COMBOBOX_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/test/BUILD.gn ('k') | components/autofill/core/browser/region_combobox_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698