#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;
std::string GetEtldPlusOne(const url::Origin origin) { … }
base::flat_set<std::string> GetAndParseExcludedSites() { … }
affiliations::FacetURI OriginToFacet(const url::Origin& origin) { … }
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) { … }
bool IsSiteExcluded(const base::flat_set<std::string>& excluded_sites,
const url::Origin& origin) { … }
Suggestion CreateNewPlusAddressSuggestion(bool has_accepted_notice) { … }
}
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) { … }
}