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

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: Rename function post-rebase 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
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:
46 // Callback for ::i18n::addressinput::PreloadSupplier::LoadRules 53 // Callback for ::i18n::addressinput::PreloadSupplier::LoadRules
47 void RegionDataLoaded(bool success, const std::string&, int rule_count); 54 void RegionDataLoaded(bool success, const std::string&, int rule_count);
48 55
49 private:
50 // Whether the region data load failed or not. 56 // Whether the region data load failed or not.
51 bool failed_to_load_data_{false}; 57 bool failed_to_load_data_{false};
52 58
59 // Set to true during region data load, and false otherwise. Whether the load
60 // succeeded or not doesn't affect this value.
61 bool pending_region_data_load_{false};
please use gerrit instead 2017/04/11 21:05:35 Please initialize in the constructor, unless this
MAD 2017/04/12 02:46:08 Here's the thread: https://groups.google.com/a/chr
62
53 // The application locale. 63 // The application locale.
54 const std::string app_locale_; 64 const std::string app_locale_;
55 65
56 // The callback to give to |region_data_supplier_| for async operations. 66 // The callback to give to |region_data_supplier_| for async operations.
57 ::i18n::addressinput::scoped_ptr< 67 ::i18n::addressinput::scoped_ptr<
58 ::i18n::addressinput::PreloadSupplier::Callback> 68 ::i18n::addressinput::PreloadSupplier::Callback>
59 region_data_supplier_callback_; 69 region_data_supplier_callback_;
60 70
61 // A supplier of region data. 71 // A supplier of region data.
62 ::i18n::addressinput::PreloadSupplier region_data_supplier_; 72 ::i18n::addressinput::PreloadSupplier region_data_supplier_;
63 73
64 // List of <code, name> pairs for ADDRESS_HOME_STATE combobox values; 74 // List of <code, name> pairs for ADDRESS_HOME_STATE combobox values;
65 std::vector<std::pair<std::string, std::string>> regions_; 75 std::vector<std::pair<std::string, std::string>> regions_;
66 76
67 // To be called when the data for the given country code was loaded. 77 // To be called when the data for the given country code was loaded.
68 base::ObserverList<ui::ComboboxModelObserver> observers_; 78 base::ObserverList<ui::ComboboxModelObserver> observers_;
69 79
70 DISALLOW_COPY_AND_ASSIGN(RegionComboboxModel); 80 DISALLOW_COPY_AND_ASSIGN(RegionComboboxModel);
71 }; 81 };
72 82
73 } // namespace autofill 83 } // namespace autofill
74 84
75 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_REGION_COMBOBOX_MODEL_H_ 85 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_REGION_COMBOBOX_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698