chromium/components/autofill/core/browser/webdata/addresses/address_autofill_table.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/autofill/core/browser/webdata/addresses/address_autofill_table.h"

#include <stdint.h>

#include <memory>
#include <optional>
#include <ranges>
#include <string_view>
#include <vector>

#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/field_type_utils.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/webdata/autofill_table_utils.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/webdata/common/web_database.h"
#include "sql/statement.h"
#include "sql/transaction.h"

namespace autofill {

namespace {

constexpr std::string_view kAddressesTable =;
constexpr std::string_view kGuid =;
constexpr std::string_view kRecordType =;
constexpr std::string_view kUseCount =;
constexpr std::string_view kUseDate =;
constexpr std::string_view kUseDate2 =;
constexpr std::string_view kUseDate3 =;
constexpr std::string_view kDateModified =;
constexpr std::string_view kLanguageCode =;
constexpr std::string_view kLabel =;
constexpr std::string_view kInitialCreatorId =;
constexpr std::string_view kLastModifierId =;

constexpr std::string_view kAddressTypeTokensTable =;
// kGuid = "guid"
constexpr std::string_view kType =;
constexpr std::string_view kValue =;
constexpr std::string_view kVerificationStatus =;
constexpr std::string_view kObservations =;

// Before the `kAddressesTable` and `kAddressTypeTokensTable` tables, local and
// account addresses were stored separately.
constexpr std::string_view kContactInfoTable =;
constexpr std::string_view kLocalAddressesTable =;
constexpr std::string_view kContactInfoTypeTokensTable =;
constexpr std::string_view kLocalAddressesTypeTokensTable =;

// Historically, a different schema was used and addresses were stored in a set
// of tables named autofill_profiles*. These tables are no longer used in
// production and only referenced in the migration logic. Do not add to them.
// Use the contact_info* and local_addresses* tables instead.
constexpr std::string_view kAutofillProfilesTable =;
// kGuid = "guid"
// kLabel = "label"
constexpr std::string_view kCompanyName =;
constexpr std::string_view kStreetAddress =;
constexpr std::string_view kDependentLocality =;
constexpr std::string_view kCity =;
constexpr std::string_view kState =;
constexpr std::string_view kZipcode =;
constexpr std::string_view kSortingCode =;
constexpr std::string_view kCountryCode =;
// kUseCount = "use_count"
// kUseDate = "use_date"
// kDateModified = "date_modified"
// kLanguageCode = "language_code"
constexpr std::string_view kDisallowSettingsVisibleUpdates =;

constexpr std::string_view kAutofillProfileAddressesTable =;
// kGuid = "guid"
// kStreetAddress = "street_address"
constexpr std::string_view kStreetName =;
constexpr std::string_view kDependentStreetName =;
constexpr std::string_view kHouseNumber =;
constexpr std::string_view kSubpremise =;
// kDependentLocality = "dependent_locality"
// kCity = "city"
// kState = "state"
constexpr std::string_view kZipCode =;
// kCountryCode = "country_code"
// kSortingCode = "sorting_code"
constexpr std::string_view kApartmentNumber =;
constexpr std::string_view kFloor =;
constexpr std::string_view kStreetAddressStatus =;
constexpr std::string_view kStreetNameStatus =;
constexpr std::string_view kDependentStreetNameStatus =;
constexpr std::string_view kHouseNumberStatus =;
constexpr std::string_view kSubpremiseStatus =;
constexpr std::string_view kDependentLocalityStatus =;
constexpr std::string_view kCityStatus =;
constexpr std::string_view kStateStatus =;
constexpr std::string_view kZipCodeStatus =;
constexpr std::string_view kCountryCodeStatus =;
constexpr std::string_view kSortingCodeStatus =;
constexpr std::string_view kApartmentNumberStatus =;
constexpr std::string_view kFloorStatus =;

constexpr std::string_view kAutofillProfileNamesTable =;
// kGuid = "guid"
constexpr std::string_view kFirstName =;
constexpr std::string_view kMiddleName =;
constexpr std::string_view kLastName =;
constexpr std::string_view kFirstLastName =;
constexpr std::string_view kConjunctionLastName =;
constexpr std::string_view kSecondLastName =;
constexpr std::string_view kFullName =;
constexpr std::string_view kFirstNameStatus =;
constexpr std::string_view kMiddleNameStatus =;
constexpr std::string_view kLastNameStatus =;
constexpr std::string_view kFirstLastNameStatus =;
constexpr std::string_view kConjunctionLastNameStatus =;
constexpr std::string_view kSecondLastNameStatus =;
constexpr std::string_view kFullNameStatus =;

constexpr std::string_view kAutofillProfileEmailsTable =;
// kGuid = "guid"
constexpr std::string_view kEmail =;

constexpr std::string_view kAutofillProfilePhonesTable =;
// kGuid = "guid"
constexpr std::string_view kNumber =;

constexpr std::string_view kAutofillProfileBirthdatesTable =;
// kGuid = "guid"
constexpr std::string_view kDay =;
constexpr std::string_view kMonth =;
constexpr std::string_view kYear =;

void AddLegacyAutofillProfileDetailsFromStatement(sql::Statement& s,
                                                  AutofillProfile* profile) {}

bool AddLegacyAutofillProfileNamesToProfile(sql::Database* db,
                                            AutofillProfile* profile) {}

bool AddLegacyAutofillProfileAddressesToProfile(sql::Database* db,
                                                AutofillProfile* profile) {}

bool AddLegacyAutofillProfileEmailsToProfile(sql::Database* db,
                                             AutofillProfile* profile) {}

bool AddLegacyAutofillProfilePhonesToProfile(sql::Database* db,
                                             AutofillProfile* profile) {}

WebDatabaseTable::TypeKey GetKey() {}

time_t GetEndTime(base::Time end) {}

// In an older version of the schema, local and account addresses were stored in
// different tables with the same layout. This function was used to get the
// correct table based on the record type. It shouldn't be used anymore, except
// in migration logic.
std::string_view GetLegacyProfileMetadataTable(
    AutofillProfile::RecordType record_type) {}
std::string_view GetLegacyProfileTypeTokensTable(
    AutofillProfile::RecordType record_type) {}

// Insert the `profile`'s metadata into `kAddressesTable`, returning true if the
// write succeeded.
bool AddProfileMetadataToTable(sql::Database* db,
                               const AutofillProfile& profile) {}

// Insert the `profile`'s values into `kAddressTypeTokensTable`, returning true
// if the write succeeded.
bool AddProfileTypeTokensToTable(sql::Database* db,
                                 const AutofillProfile& profile) {}

// `MigrateToVersion113MigrateLocalAddressProfilesToNewTable()` migrates
// profiles from one table layout to another. This function inserts the given
// `profile` into the `GetProfileMetadataTable()` of schema version 113.
// `AddAutofillProfileToTable()` can't be reused, since the schema can change in
// future database versions in ways incompatible with version 113 (e.g. adding
// a column).
// The code was copied from `AddAutofillProfileToTable()` in version 113. Like
// the migration logic, it shouldn't be changed.
bool AddAutofillProfileToTableVersion113(sql::Database* db,
                                         const AutofillProfile& profile) {}

// Constructs a profile based on the data in `kAddressTypeTokensTable` for the
// given `guid`. Since the data model of the profile depends on the country, the
// implementation first collects all `FieldTypeData` and only then constructs
// the profile based on the country code found. The returned profile's metadata
// isn't populated, since it is stored in a different table (see
// `ReadProfileMetadata()` below). If reading from the table fails, nullopt is
// returned.
std::optional<AutofillProfile> GetProfileFromTypeTokensTable(
    sql::Database* db,
    const std::string& guid,
    AutofillProfile::RecordType record_type) {}

// Reads all metadata (usage information, etc) of the profile from
// `kAddressesTable` and writes it to the `profile`.
// If reading from the table fails, false is returned and the profile is left
// untouched.
bool ReadProfileMetadata(sql::Database* db, AutofillProfile& profile) {}

}  // namespace

AddressAutofillTable::AddressAutofillTable() = default;

AddressAutofillTable::~AddressAutofillTable() = default;

// static
AddressAutofillTable* AddressAutofillTable::FromWebDatabase(WebDatabase* db) {}

WebDatabaseTable::TypeKey AddressAutofillTable::GetTypeKey() const {}

bool AddressAutofillTable::CreateTablesIfNecessary() {}

bool AddressAutofillTable::MigrateToVersion(int version,
                                            bool* update_compatible_version) {}

bool AddressAutofillTable::AddAutofillProfile(const AutofillProfile& profile) {}

bool AddressAutofillTable::UpdateAutofillProfile(
    const AutofillProfile& profile) {}

bool AddressAutofillTable::RemoveAutofillProfile(
    const std::string& guid,
    AutofillProfile::RecordType record_type) {}

bool AddressAutofillTable::RemoveAllAutofillProfiles(
    AutofillProfile::RecordType record_type) {}

std::optional<AutofillProfile> AddressAutofillTable::GetAutofillProfile(
    const std::string& guid,
    AutofillProfile::RecordType record_type) const {}

bool AddressAutofillTable::GetAutofillProfiles(
    AutofillProfile::RecordType record_type,
    std::vector<AutofillProfile>& profiles) const {}

std::optional<AutofillProfile>
AddressAutofillTable::GetAutofillProfileFromLegacyTable(
    const std::string& guid) const {}

// TODO(crbug.com/40267335): This function's implementation is very similar to
// `GetAutofillProfiles()`. Simplify somehow.
bool AddressAutofillTable::GetAutofillProfilesFromLegacyTable(
    std::vector<AutofillProfile>& profiles) const {}

bool AddressAutofillTable::RemoveAutofillDataModifiedBetween(
    base::Time delete_begin,
    base::Time delete_end,
    std::vector<AutofillProfile>& profiles) {}

bool AddressAutofillTable::MigrateToVersion88AddNewNameColumns() {}

bool AddressAutofillTable::MigrateToVersion92AddNewPrefixedNameColumn() {}

bool AddressAutofillTable::MigrateToVersion90AddNewStructuredAddressColumns() {}

bool AddressAutofillTable::MigrateToVersion91AddMoreStructuredAddressColumns() {}

bool AddressAutofillTable::MigrateToVersion93AddAutofillProfileLabelColumn() {}

bool AddressAutofillTable::
    MigrateToVersion96AddAutofillProfileDisallowConfirmableMergesColumn() {}

bool AddressAutofillTable::
    MigrateToVersion99RemoveAutofillProfilesTrashTable() {}

bool AddressAutofillTable::
    MigrateToVersion100RemoveProfileValidityBitfieldColumn() {}

bool AddressAutofillTable::MigrateToVersion102AddAutofillBirthdatesTable() {}

bool AddressAutofillTable::MigrateToVersion107AddContactInfoTables() {}

bool AddressAutofillTable::
    MigrateToVersion110AddInitialCreatorIdAndLastModifierId() {}

bool AddressAutofillTable::
    MigrateToVersion113MigrateLocalAddressProfilesToNewTable() {}

bool AddressAutofillTable::MigrateToVersion114DropLegacyAddressTables() {}

bool AddressAutofillTable::MigrateToVersion117AddProfileObservationColumn() {}

bool AddressAutofillTable::MigrateToVersion121DropServerAddressTables() {}

bool AddressAutofillTable::
    MigrateToVersion132AddAdditionalLastUseDateColumns() {}

bool AddressAutofillTable::
    MigrateToVersion134UnifyLocalAndAccountAddressStorage() {}

bool AddressAutofillTable::InitLegacyProfileAddressesTable() {}

bool AddressAutofillTable::InitAddressesTable() {}

bool AddressAutofillTable::InitAddressTypeTokensTable() {}

}  // namespace autofill