chromium/components/autofill/core/browser/address_data_manager.h

// Copyright 2024 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_ADDRESS_DATA_MANAGER_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_DATA_MANAGER_H_

#include <deque>
#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "base/scoped_observation.h"
#include "components/autofill/core/browser/country_type.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/strike_databases/address_suggestion_strike_database.h"
#include "components/autofill/core/browser/strike_databases/autofill_profile_migration_strike_database.h"
#include "components/autofill/core/browser/strike_databases/autofill_profile_save_strike_database.h"
#include "components/autofill/core/browser/strike_databases/autofill_profile_update_strike_database.h"
#include "components/autofill/core/browser/strike_databases/strike_database_base.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service_observer.h"
#include "components/history/core/browser/history_types.h"
#include "components/prefs/pref_member.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/sync/service/sync_service.h"
#include "components/webdata/common/web_data_service_consumer.h"

namespace signin {
class IdentityManager;
}

class PrefService;

namespace autofill {

class AddressDataCleaner;
class AlternativeStateNameMapUpdater;
class ContactInfoPreconditionChecker;

// Contains all address-related logic of the `PersonalDataManager`. See comment
// above the `PersonalDataManager` first. In the `AddressDataManager` (ADM),
// `Refresh()` is called `LoadProfiles()`.
// Owned by the PDM.
//
// Technical details on how modifications are implemented:
// The ADM queues pending changes in `ongoing_profile_changes_`. For each
// profile, they are executed in order and the next change is only posted to the
// DB sequence once the previous change has finished. After each change that
// finishes, the `AutofillWebDataService` notifies the ADM via
// `OnAutofillProfileChanged(change)` - and the ADM updates its state
// accordingly. No `LoadProfiles()` is performed.
// Queuing the pending modifications is necessary, so the ADM can do consistency
// checks against the latest state. For example, a remove should only be
// performed if the profile exists. Without the queuing, if a remove operation
// was posted before the add operation has finished, the remove would
// incorrectly get rejected by the ADM.
class AddressDataManager : public AutofillWebDataServiceObserverOnUISequence,
                           public WebDataServiceConsumer {};

}  // namespace autofill

#endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_DATA_MANAGER_H_