#include "components/plus_addresses/plus_address_preallocator.h"
#include <algorithm>
#include <optional>
#include <string>
#include <utility>
#include "base/check_deref.h"
#include "base/feature_list.h"
#include "base/json/values_util.h"
#include "base/notreached.h"
#include "base/task/sequenced_task_runner.h"
#include "base/values.h"
#include "components/affiliations/core/browser/affiliation_utils.h"
#include "components/plus_addresses/features.h"
#include "components/plus_addresses/plus_address_allocator.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_prefs.h"
#include "components/plus_addresses/plus_address_types.h"
#include "components/plus_addresses/settings/plus_address_setting_service.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "net/base/backoff_entry.h"
#include "net/http/http_status_code.h"
namespace plus_addresses {
namespace {
constexpr auto kPreallocateBackoffPolicy = …;
bool IsOutdatedOrInvalid(const base::Value& preallocated_address) { … }
base::Value SeralizeAndSetEndOfLife(PreallocatedPlusAddress address) { … }
const std::string& GetPlusAddress(const base::Value& preallocated_address) { … }
bool ShouldRetryOnError(const PlusAddressRequestError& error) { … }
}
PlusAddressPreallocator::PlusAddressPreallocator(
PrefService* pref_service,
PlusAddressSettingService* setting_service,
PlusAddressHttpClient* http_client,
IsEnabledCheck is_enabled_check)
: … { … }
PlusAddressPreallocator::~PlusAddressPreallocator() = default;
void PlusAddressPreallocator::AllocatePlusAddress(
const url::Origin& origin,
AllocationMode mode,
PlusAddressRequestCallback callback) { … }
bool PlusAddressPreallocator::IsNextAllocationSynchronous() { … }
bool PlusAddressPreallocator::IsRefreshingSupported(
const url::Origin& origin) const { … }
void PlusAddressPreallocator::RemoveAllocatedPlusAddress(
const PlusAddress& plus_address) { … }
void PlusAddressPreallocator::FixIndexOfNextPreallocatedAddress() { … }
void PlusAddressPreallocator::PrunePreallocatedPlusAddresses() { … }
void PlusAddressPreallocator::MaybeRequestNewPreallocatedPlusAddresses(
bool is_user_triggered) { … }
bool PlusAddressPreallocator::IsEnabled() const { … }
void PlusAddressPreallocator::SendRequestWithDelay(base::TimeDelta delay) { … }
void PlusAddressPreallocator::SendRequest() { … }
void PlusAddressPreallocator::OnReceivePreallocatedPlusAddresses(
PlusAddressHttpClient::PreallocatePlusAddressesResult result) { … }
void PlusAddressPreallocator::ProcessAllocationRequests(
bool is_user_triggered) { … }
void PlusAddressPreallocator::ReplyToRequestsWithError(
const PlusAddressRequestError& error) { … }
std::optional<PlusAddress>
PlusAddressPreallocator::GetNextPreallocatedPlusAddress() { … }
const base::Value::List& PlusAddressPreallocator::GetPreallocatedAddresses()
const { … }
int PlusAddressPreallocator::GetIndexOfNextPreallocatedAddress() const { … }
PlusAddressPreallocator::Request::Request(PlusAddressRequestCallback callback,
affiliations::FacetURI facet)
: … { … }
PlusAddressPreallocator::Request::Request(Request&&) = default;
PlusAddressPreallocator::Request& PlusAddressPreallocator::Request::operator=(
Request&&) = default;
PlusAddressPreallocator::Request::~Request() = default;
}