#include "services/network/ip_protection/ip_protection_token_cache_manager_impl.h"
#include <memory>
#include <string>
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "components/ip_protection/common/ip_protection_data_types.h"
#include "components/ip_protection/common/ip_protection_telemetry.h"
#include "net/base/features.h"
#include "services/network/ip_protection/ip_protection_config_cache.h"
#include "services/network/ip_protection/ip_protection_geo_utils.h"
namespace network {
namespace {
constexpr base::TimeDelta kMinimumFuzzInterval = …;
constexpr base::TimeDelta kTokenRateMeasurementInterval = …;
constexpr base::TimeDelta kImmediateTokenRefillDelay = …;
constexpr base::TimeDelta kTokenLimitExceededDelay = …;
constexpr char kDefaultGeo[] = …;
}
BlindSignedAuthToken;
IpProtectionTokenCacheManagerImpl::IpProtectionTokenCacheManagerImpl(
IpProtectionConfigCache* config_cache,
IpProtectionConfigGetter* config_getter,
ip_protection::ProxyLayer proxy_layer,
bool disable_cache_management_for_testing)
: … { … }
IpProtectionTokenCacheManagerImpl::~IpProtectionTokenCacheManagerImpl() =
default;
bool IpProtectionTokenCacheManagerImpl::IsAuthTokenAvailable() { … }
bool IpProtectionTokenCacheManagerImpl::IsAuthTokenAvailable(
const std::string& geo_id) { … }
void IpProtectionTokenCacheManagerImpl::MaybeRefillCache() { … }
void IpProtectionTokenCacheManagerImpl::InvalidateTryAgainAfterTime() { … }
std::string IpProtectionTokenCacheManagerImpl::CurrentGeo() const { … }
void IpProtectionTokenCacheManagerImpl::SetCurrentGeo(
const std::string& geo_id) { … }
void IpProtectionTokenCacheManagerImpl::ScheduleMaybeRefillCache() { … }
bool IpProtectionTokenCacheManagerImpl::NeedsRefill(
const std::string& geo_id) const { … }
bool IpProtectionTokenCacheManagerImpl::IsTokenLimitExceeded(
const std::string& geo_id) const { … }
void IpProtectionTokenCacheManagerImpl::OnGotAuthTokens(
const base::TimeTicks attempt_start_time_for_metrics,
std::optional<std::vector<BlindSignedAuthToken>> tokens,
std::optional<base::Time> try_again_after) { … }
std::optional<BlindSignedAuthToken>
IpProtectionTokenCacheManagerImpl::GetAuthToken() { … }
std::optional<BlindSignedAuthToken>
IpProtectionTokenCacheManagerImpl::GetAuthToken(const std::string& geo_id) { … }
void IpProtectionTokenCacheManagerImpl::RemoveExpiredTokens() { … }
void IpProtectionTokenCacheManagerImpl::MeasureTokenRates() { … }
void IpProtectionTokenCacheManagerImpl::DisableCacheManagementForTesting(
base::OnceClosure on_cache_management_disabled) { … }
void IpProtectionTokenCacheManagerImpl::EnableTokenExpirationFuzzingForTesting(
bool enable) { … }
void IpProtectionTokenCacheManagerImpl::CallTryGetAuthTokensForTesting() { … }
}