// Copyright 2020 The Chromium Authors // 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_GEO_ALTERNATIVE_STATE_NAME_MAP_H_ #define COMPONENTS_AUTOFILL_CORE_BROWSER_GEO_ALTERNATIVE_STATE_NAME_MAP_H_ #include <optional> #include <string> #include "base/i18n/case_conversion.h" #include "base/no_destructor.h" #include "base/synchronization/lock.h" #include "base/thread_annotations.h" #include "base/types/strong_alias.h" #include "components/autofill/core/browser/proto/states.pb.h" namespace autofill { // AlternativeStateNameMap encapsulates mappings from state names in the // profiles to their localized and the abbreviated names. // // AlternativeStateNameMap is used for the filling of state fields, comparison // of profiles, determining mergeability of the address profiles and required // |ADDRESS_HOME_STATE| votes to be sent to the server. // // AlternativeStateNameMap can provide the following data for the states: // 1. The state string stored in the address profile denoted by // state_string_from_profile in this class. // 2. The canonical state name (StateEntry::canonical_name) which acts as the // unique identifier representing the state (unique within a country). // 3. The abbreviations of the state (StateEntry::abbreviations). // 4. The alternative names of the state (StateEntry::alternative_names). // // StateEntry holds the information about the abbreviations and the // alternative names of the state which is determined after comparison with the // state values saved in the address profiles if they match. // // The main map |localized_state_names_map_| maps the tuple // (country_code, canonical state name) as the key to the corresponding // StateEntry object (with the information about the abbreviations and the // alternative names) as the value. // // The |localized_state_names_reverse_lookup_map_| takes in the // country_code and StateEntry::name, StateEntry::abbreviations or // ::alternative_names as the key and the canonical state name as the value. // // Example: Considering "California" as the state_string_from_profile and // the corresponding StateEntry object: // { // 'canonical_name': 'California', // 'abbreviations': ['CA'], // 'alternate_names': ['The Golden State'] // } // // 1. StateEntry::canonical_name (i.e "California" in this case) acts // as the canonical state name. // 2. ("US", "California") acts as the key and the above StateEntry // object is added as the value in the // |localized_state_names_map_|. // 3. Entries added to |localized_state_names_reverse_lookup_map_| // are: // a. ("US", "California") -> "California" // b. ("US", "CA") -> "California" // c. ("US", "TheGoldenState") -> "California" // // In case, the user has an unknown state in the profile, nothing is added to // the AlternativeStateNameMap; class AlternativeStateNameMap { … }; } // namespace autofill #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_GEO_ALTERNATIVE_STATE_NAME_MAP_H_