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

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

Issue 2849523003: Add billing address as a mandatory field of Payments credit cards. (Closed)
Patch Set: Components Unittests fix 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 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_COMBOBOX_MODEL_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_COMBOBOX_MODEL_H_
7
8 #include <memory>
9 #include <string>
10 #include <utility>
11 #include <vector>
12
13 #include "base/macros.h"
14 #include "base/observer_list.h"
15 #include "base/strings/string16.h"
16 #include "ui/base/models/combobox_model.h"
17
18 namespace autofill {
19
20 class AutofillProfile;
21 class PersonalDataManager;
22
23 // A combobox model for listing addresses by a generated user visible string and
24 // have a unique id to identify the one selected by the user.
25 class AddressComboboxModel : public ui::ComboboxModel {
26 public:
27 // Enumerate the profiles from |personal_data_manager| to expose them in a
28 // combobox using |app_locale| for proper format.
29 AddressComboboxModel(const PersonalDataManager& personal_data_manager,
30 const std::string& app_locale);
31 ~AddressComboboxModel() override;
32
33 // ui::ComboboxModel implementation:
34 int GetItemCount() const override;
35 base::string16 GetItemAt(int index) override;
36 bool IsItemSeparatorAt(int index) override;
37 void AddObserver(ui::ComboboxModelObserver* observer) override;
38 void RemoveObserver(ui::ComboboxModelObserver* observer) override;
39
40 // Adds |profile| to model and return its combobox index.
41 int AddNewProfile(const AutofillProfile& profile);
42
43 // Returns the unique identifier of the profile at |index|, unless |index|
44 // refers to a special entry, in which case an empty string is returned.
45 std::string GetItemIdentifierAt(int index);
46
47 // Returns the combobox index of the item with the given id or -1 if it's not
48 // found.
49 int GetIndexOfIdentifier(const std::string& identifier);
50
51 private:
52 // Update |addresses_| based on |profiles_cache_| and notify observers.
53 void UpdateAddresses();
54
55 // List of <id, user visible string> pairs for the addresses extracted from
56 // the |personal_data_manager| passed in the constructor.
57 std::vector<std::pair<std::string, base::string16>> addresses_;
58
59 // A cached copy of all profiles to allow rebuilding the differentiating
60 // labels when new profiles are added.
61 std::vector<std::unique_ptr<AutofillProfile>> profiles_cache_;
62
63 // Application locale, also needed when a new profile is added.
64 std::string app_locale_;
65
66 // To be called when the data for the given country code was loaded.
67 base::ObserverList<ui::ComboboxModelObserver> observers_;
68
69 DISALLOW_COPY_AND_ASSIGN(AddressComboboxModel);
70 };
71
72 } // namespace autofill
73
74 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_COMBOBOX_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698