Index: components/autofill/core/browser/address_combobox_model.h |
diff --git a/components/autofill/core/browser/address_combobox_model.h b/components/autofill/core/browser/address_combobox_model.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0ee29849ab75f1b0549e1bd3d19a3afad9c125b1 |
--- /dev/null |
+++ b/components/autofill/core/browser/address_combobox_model.h |
@@ -0,0 +1,74 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_COMBOBOX_MODEL_H_ |
+#define COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_COMBOBOX_MODEL_H_ |
+ |
+#include <memory> |
+#include <string> |
+#include <utility> |
+#include <vector> |
+ |
+#include "base/macros.h" |
+#include "base/observer_list.h" |
+#include "base/strings/string16.h" |
+#include "ui/base/models/combobox_model.h" |
+ |
+namespace autofill { |
+ |
+class AutofillProfile; |
+class PersonalDataManager; |
+ |
+// A combobox model for listing addresses by a generated user visible string and |
+// have a unique id to identify the one selected by the user. |
+class AddressComboboxModel : public ui::ComboboxModel { |
+ public: |
+ // Enumerate the profiles from |personal_data_manager| to expose them in a |
+ // combobox using |app_locale| for proper format. |
+ AddressComboboxModel(const PersonalDataManager& personal_data_manager, |
+ const std::string& app_locale); |
+ ~AddressComboboxModel() override; |
+ |
+ // ui::ComboboxModel implementation: |
+ int GetItemCount() const override; |
+ base::string16 GetItemAt(int index) override; |
+ bool IsItemSeparatorAt(int index) override; |
+ void AddObserver(ui::ComboboxModelObserver* observer) override; |
+ void RemoveObserver(ui::ComboboxModelObserver* observer) override; |
+ |
+ // Adds |profile| to model and return its combobox index. |
+ int AddNewProfile(const AutofillProfile& profile); |
+ |
+ // Returns the unique identifier of the profile at |index|, unless |index| |
+ // refers to a special entry, in which case an empty string is returned. |
+ std::string GetItemIdentifierAt(int index); |
+ |
+ // Returns the combobox index of the item with the given id or -1 if it's not |
+ // found. |
+ int GetIndexOfIdentifier(const std::string& identifier); |
+ |
+ private: |
+ // Update |addresses_| based on |profiles_cache_| and notify observers. |
+ void UpdateAddresses(); |
+ |
+ // List of <id, user visible string> pairs for the addresses extracted from |
+ // the |personal_data_manager| passed in the constructor. |
+ std::vector<std::pair<std::string, base::string16>> addresses_; |
+ |
+ // A cached copy of all profiles to allow rebuilding the differentiating |
+ // labels when new profiles are added. |
+ std::vector<std::unique_ptr<AutofillProfile>> profiles_cache_; |
+ |
+ // Application locale, also needed when a new profile is added. |
+ std::string app_locale_; |
+ |
+ // To be called when the data for the given country code was loaded. |
+ base::ObserverList<ui::ComboboxModelObserver> observers_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AddressComboboxModel); |
+}; |
+ |
+} // namespace autofill |
+ |
+#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_COMBOBOX_MODEL_H_ |