chromium/components/plus_addresses/plus_address_service.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/plus_addresses/plus_address_service.h"

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/check_deref.h"
#include "base/check_op.h"
#include "base/containers/flat_set.h"
#include "base/functional/bind.h"
#include "base/notimplemented.h"
#include "base/notreached.h"
#include "base/scoped_observation.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "components/affiliations/core/browser/affiliation_utils.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/data_model/borrowed_transliterator.h"
#include "components/autofill/core/browser/ui/suggestion.h"
#include "components/autofill/core/browser/ui/suggestion_type.h"
#include "components/autofill/core/common/aliases.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/plus_addresses/features.h"
#include "components/plus_addresses/metrics/plus_address_metrics.h"
#include "components/plus_addresses/plus_address_allocator.h"
#include "components/plus_addresses/plus_address_blocklist_data.h"
#include "components/plus_addresses/plus_address_http_client.h"
#include "components/plus_addresses/plus_address_http_client_impl.h"
#include "components/plus_addresses/plus_address_jit_allocator.h"
#include "components/plus_addresses/plus_address_preallocator.h"
#include "components/plus_addresses/plus_address_types.h"
#include "components/plus_addresses/settings/plus_address_setting_service.h"
#include "components/plus_addresses/webdata/plus_address_sync_util.h"
#include "components/plus_addresses/webdata/plus_address_webdata_service.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/base/consent_level.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/strings/grit/components_strings.h"
#include "components/webdata/common/web_data_results.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "ui/base/l10n/l10n_util.h"

namespace plus_addresses {

namespace {

FormFieldData;
Suggestion;
SuggestionType;
PasswordFormClassification;

// Get the ETLD+1 of `origin`, which means any subdomain is treated
// equivalently. See `GetDomainAndRegistry` for concrete examples.
std::string GetEtldPlusOne(const url::Origin origin) {}

// Get and parse the excluded sites.
base::flat_set<std::string> GetAndParseExcludedSites() {}

affiliations::FacetURI OriginToFacet(const url::Origin& origin) {}

// Returns `true` when we wish to offer plus address creation on a form with
// password manager classification `form_classification` and a focused field
// with id `focused_field_id`.
// If password manager did not recognize a username field or the username field
// is different from the focused field, this is always `true`. Otherwise,
// whether we offer plus address creation depends on the form type.
bool ShouldOfferPlusAddressCreationOnForm(
    const PasswordFormClassification& form_classification,
    autofill::FieldGlobalId focused_field_id) {}

std::unique_ptr<PlusAddressAllocator> CreateAllocator(
    PrefService* pref_service,
    PlusAddressSettingService* setting_service,
    PlusAddressHttpClient* http_client,
    PlusAddressPreallocator::IsEnabledCheck is_enabled_check) {}

// Returns `true` if the origin is part of the set of blocklisted domains and
// `false` otherwise. If `kPlusAddressBlocklistEnabled` is enabled, this means
// that the domain's origin matches the `exclusion_pattern` regex and does not
// match the `exception_pattern` regex.
bool IsSiteExcluded(const base::flat_set<std::string>& excluded_sites,
                    const url::Origin& origin) {}

// Returns an Autofill `Suggestion` for creating a new plus address.
// TODO(crbug.com/362445807): Add tests for the inline suggestion once we set
// more suggestion properties.
Suggestion CreateNewPlusAddressSuggestion(bool has_accepted_notice) {}

}  // namespace

PlusAddressService::PlusAddressService(
    PrefService* pref_service,
    signin::IdentityManager* identity_manager,
    PlusAddressSettingService* setting_service,
    std::unique_ptr<PlusAddressHttpClient> plus_address_http_client,
    scoped_refptr<PlusAddressWebDataService> webdata_service,
    affiliations::AffiliationService* affiliation_service,
    FeatureEnabledForProfileCheck feature_enabled_for_profile_check)
    :{}

PlusAddressService::~PlusAddressService() {}

bool PlusAddressService::IsPlusAddressFillingEnabled(
    const url::Origin& origin) const {}

bool PlusAddressService::IsPlusAddressCreationEnabled(
    const url::Origin& origin,
    bool is_off_the_record) const {}

bool PlusAddressService::ShouldShowManualFallback(
    const url::Origin& origin,
    bool is_off_the_record) const {}

std::optional<PlusAddress> PlusAddressService::GetPlusAddress(
    const affiliations::FacetURI& facet) const {}

void PlusAddressService::GetAffiliatedPlusProfiles(
    const url::Origin& origin,
    GetPlusProfilesCallback callback) {}

base::span<const PlusProfile> PlusAddressService::GetPlusProfiles() const {}

std::optional<PlusProfile> PlusAddressService::GetPlusProfile(
    const affiliations::FacetURI& facet) const {}

void PlusAddressService::SavePlusProfile(const PlusProfile& profile) {}

bool PlusAddressService::IsPlusAddress(
    const std::string& potential_plus_address) const {}

void PlusAddressService::GetSuggestions(
    const url::Origin& last_committed_primary_main_frame_origin,
    bool is_off_the_record,
    const PasswordFormClassification& focused_form_classification,
    const FormFieldData& focused_field,
    autofill::AutofillSuggestionTriggerSource trigger_source,
    GetSuggestionsCallback callback) {}

Suggestion PlusAddressService::GetManagePlusAddressSuggestion() const {}

bool PlusAddressService::ShouldMixWithSingleFieldFormFillSuggestions() const {}

void PlusAddressService::OnGetAffiliatedPlusProfiles(
    const PasswordFormClassification& focused_form_classification,
    const FormFieldData& focused_field,
    autofill::AutofillSuggestionTriggerSource trigger_source,
    bool is_off_the_record,
    GetSuggestionsCallback callback,
    std::vector<PlusProfile> affiliated_profiles) {}

void PlusAddressService::ReservePlusAddress(
    const url::Origin& origin,
    PlusAddressRequestCallback on_completed) {}

void PlusAddressService::RefreshPlusAddress(
    const url::Origin& origin,
    PlusAddressRequestCallback on_completed) {}

bool PlusAddressService::IsRefreshingSupported(const url::Origin& origin) {}

void PlusAddressService::ConfirmPlusAddress(
    const url::Origin& origin,
    const PlusAddress& plus_address,
    PlusAddressRequestCallback on_completed) {}

void PlusAddressService::HandleCreateOrConfirmResponse(
    const url::Origin& origin,
    PlusAddressRequestCallback callback,
    const PlusProfileOrError& maybe_profile) {}

std::optional<std::string> PlusAddressService::GetPrimaryEmail() {}

bool PlusAddressService::IsEnabled() const {}

void PlusAddressService::OnWebDataChangedBySync(
    const std::vector<PlusAddressDataChange>& changes) {}

void PlusAddressService::OnWebDataServiceRequestDone(
    WebDataServiceBase::Handle handle,
    std::unique_ptr<WDTypedResult> result) {}

void PlusAddressService::HandlePlusAddressRequestError(
    const PlusAddressRequestError& error) {}
void PlusAddressService::OnPrimaryAccountChanged(
    const signin::PrimaryAccountChangeEvent& event) {}

void PlusAddressService::OnErrorStateOfRefreshTokenUpdatedForAccount(
    const CoreAccountInfo& account_info,
    const GoogleServiceAuthError& error,
    signin_metrics::SourceForRefreshTokenOperation token_operation_source) {}

void PlusAddressService::HandleSignout() {}


bool PlusAddressService::IsSupportedOrigin(const url::Origin& origin) const {}

void PlusAddressService::RecordAutofillSuggestionEvent(
    SuggestionEvent suggestion_event) {}

void PlusAddressService::OnPlusAddressSuggestionShown(
    autofill::AutofillManager& manager,
    autofill::FormGlobalId form,
    autofill::FieldGlobalId field,
    SuggestionContext suggestion_context,
    autofill::AutofillClient::PasswordFormClassification::Type form_type,
    autofill::SuggestionType suggestion_type) {}

void PlusAddressService::OnClickedRefreshInlineSuggestion(
    base::span<const autofill::Suggestion> current_suggestions,
    size_t current_suggestion_index,
    base::OnceCallback<void(std::vector<autofill::Suggestion>,
                            autofill::AutofillSuggestionTriggerSource)>
        update_suggestions_callback) {}

}  // namespace plus_addresses