#include "net/reporting/reporting_cache_impl.h"
#include <algorithm>
#include <optional>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include "base/containers/contains.h"
#include "base/memory/raw_ptr.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/stl_util.h"
#include "base/time/clock.h"
#include "base/time/tick_clock.h"
#include "net/base/features.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/url_util.h"
#include "net/log/net_log.h"
#include "net/reporting/reporting_target_type.h"
namespace net {
ReportingCacheImpl::ReportingCacheImpl(
ReportingContext* context,
const base::flat_map<std::string, GURL>& enterprise_reporting_endpoints)
: … { … }
ReportingCacheImpl::~ReportingCacheImpl() = default;
void ReportingCacheImpl::AddReport(
const std::optional<base::UnguessableToken>& reporting_source,
const NetworkAnonymizationKey& network_anonymization_key,
const GURL& url,
const std::string& user_agent,
const std::string& group_name,
const std::string& type,
base::Value::Dict body,
int depth,
base::TimeTicks queued,
int attempts,
ReportingTargetType target_type) { … }
void ReportingCacheImpl::GetReports(
std::vector<raw_ptr<const ReportingReport, VectorExperimental>>*
reports_out) const { … }
base::Value ReportingCacheImpl::GetReportsAsValue() const { … }
std::vector<raw_ptr<const ReportingReport, VectorExperimental>>
ReportingCacheImpl::GetReportsToDeliver() { … }
std::vector<raw_ptr<const ReportingReport, VectorExperimental>>
ReportingCacheImpl::GetReportsToDeliverForSource(
const base::UnguessableToken& reporting_source) { … }
void ReportingCacheImpl::ClearReportsPending(
const std::vector<raw_ptr<const ReportingReport, VectorExperimental>>&
reports) { … }
void ReportingCacheImpl::IncrementReportsAttempts(
const std::vector<raw_ptr<const ReportingReport, VectorExperimental>>&
reports) { … }
std::vector<ReportingEndpoint> FilterEndpointsByOrigin(
const std::map<base::UnguessableToken, std::vector<ReportingEndpoint>>&
document_endpoints,
const url::Origin& origin) { … }
base::flat_map<url::Origin, std::vector<ReportingEndpoint>>
ReportingCacheImpl::GetV1ReportingEndpointsByOrigin() const { … }
ReportingEndpoint::Statistics* ReportingCacheImpl::GetEndpointStats(
const ReportingEndpointGroupKey& group_key,
const GURL& url) { … }
void ReportingCacheImpl::IncrementEndpointDeliveries(
const ReportingEndpointGroupKey& group_key,
const GURL& url,
int reports_delivered,
bool successful) { … }
void ReportingCacheImpl::SetExpiredSource(
const base::UnguessableToken& reporting_source) { … }
const base::flat_set<base::UnguessableToken>&
ReportingCacheImpl::GetExpiredSources() const { … }
void ReportingCacheImpl::RemoveReports(
const std::vector<raw_ptr<const ReportingReport, VectorExperimental>>&
reports) { … }
void ReportingCacheImpl::RemoveReports(
const std::vector<raw_ptr<const ReportingReport, VectorExperimental>>&
reports,
bool delivery_success) { … }
void ReportingCacheImpl::RemoveAllReports() { … }
size_t ReportingCacheImpl::GetFullReportCountForTesting() const { … }
size_t ReportingCacheImpl::GetReportCountWithStatusForTesting(
ReportingReport::Status status) const { … }
bool ReportingCacheImpl::IsReportPendingForTesting(
const ReportingReport* report) const { … }
bool ReportingCacheImpl::IsReportDoomedForTesting(
const ReportingReport* report) const { … }
void ReportingCacheImpl::OnParsedHeader(
const NetworkAnonymizationKey& network_anonymization_key,
const url::Origin& origin,
std::vector<ReportingEndpointGroup> parsed_header) { … }
void ReportingCacheImpl::RemoveSourceAndEndpoints(
const base::UnguessableToken& reporting_source) { … }
void ReportingCacheImpl::OnParsedReportingEndpointsHeader(
const base::UnguessableToken& reporting_source,
const IsolationInfo& isolation_info,
std::vector<ReportingEndpoint> endpoints) { … }
void ReportingCacheImpl::SetEnterpriseReportingEndpoints(
const base::flat_map<std::string, GURL>& endpoints) { … }
std::set<url::Origin> ReportingCacheImpl::GetAllOrigins() const { … }
void ReportingCacheImpl::RemoveClient(
const NetworkAnonymizationKey& network_anonymization_key,
const url::Origin& origin) { … }
void ReportingCacheImpl::RemoveClientsForOrigin(const url::Origin& origin) { … }
void ReportingCacheImpl::RemoveAllClients() { … }
void ReportingCacheImpl::RemoveEndpointGroup(
const ReportingEndpointGroupKey& group_key) { … }
void ReportingCacheImpl::RemoveEndpointsForUrl(const GURL& url) { … }
void ReportingCacheImpl::AddClientsLoadedFromStore(
std::vector<ReportingEndpoint> loaded_endpoints,
std::vector<CachedReportingEndpointGroup> loaded_endpoint_groups) { … }
std::vector<ReportingEndpoint>
ReportingCacheImpl::GetCandidateEndpointsForDelivery(
const ReportingEndpointGroupKey& group_key) { … }
base::Value ReportingCacheImpl::GetClientsAsValue() const { … }
size_t ReportingCacheImpl::GetEndpointCount() const { … }
void ReportingCacheImpl::Flush() { … }
ReportingEndpoint ReportingCacheImpl::GetV1EndpointForTesting(
const base::UnguessableToken& reporting_source,
const std::string& endpoint_name) const { … }
ReportingEndpoint ReportingCacheImpl::GetEndpointForTesting(
const ReportingEndpointGroupKey& group_key,
const GURL& url) const { … }
std::vector<ReportingEndpoint>
ReportingCacheImpl::GetEnterpriseEndpointsForTesting() const { … }
bool ReportingCacheImpl::EndpointGroupExistsForTesting(
const ReportingEndpointGroupKey& group_key,
OriginSubdomains include_subdomains,
base::Time expires) const { … }
bool ReportingCacheImpl::ClientExistsForTesting(
const NetworkAnonymizationKey& network_anonymization_key,
const url::Origin& origin) const { … }
size_t ReportingCacheImpl::GetEndpointGroupCountForTesting() const { … }
size_t ReportingCacheImpl::GetClientCountForTesting() const { … }
size_t ReportingCacheImpl::GetReportingSourceCountForTesting() const { … }
void ReportingCacheImpl::SetV1EndpointForTesting(
const ReportingEndpointGroupKey& group_key,
const base::UnguessableToken& reporting_source,
const IsolationInfo& isolation_info,
const GURL& url) { … }
void ReportingCacheImpl::SetEnterpriseEndpointForTesting(
const ReportingEndpointGroupKey& group_key,
const GURL& url) { … }
void ReportingCacheImpl::SetEndpointForTesting(
const ReportingEndpointGroupKey& group_key,
const GURL& url,
OriginSubdomains include_subdomains,
base::Time expires,
int priority,
int weight) { … }
IsolationInfo ReportingCacheImpl::GetIsolationInfoForEndpoint(
const ReportingEndpoint& endpoint) const { … }
ReportingCacheImpl::Client::Client(
const NetworkAnonymizationKey& network_anonymization_key,
const url::Origin& origin)
: … { … }
ReportingCacheImpl::Client::Client(const Client& other) = default;
ReportingCacheImpl::Client::Client(Client&& other) = default;
ReportingCacheImpl::Client& ReportingCacheImpl::Client::operator=(
const Client& other) = default;
ReportingCacheImpl::Client& ReportingCacheImpl::Client::operator=(
Client&& other) = default;
ReportingCacheImpl::Client::~Client() = default;
ReportingCacheImpl::ReportSet::const_iterator
ReportingCacheImpl::FindReportToEvict() const { … }
void ReportingCacheImpl::ConsistencyCheckClients() const { … }
size_t ReportingCacheImpl::ConsistencyCheckClient(const std::string& domain,
const Client& client) const { … }
size_t ReportingCacheImpl::ConsistencyCheckEndpointGroup(
const ReportingEndpointGroupKey& key,
const CachedReportingEndpointGroup& group) const { … }
void ReportingCacheImpl::ConsistencyCheckEndpoint(
const ReportingEndpointGroupKey& key,
const ReportingEndpoint& endpoint,
EndpointMap::const_iterator endpoint_it) const { … }
ReportingCacheImpl::ClientMap::iterator ReportingCacheImpl::FindClientIt(
const NetworkAnonymizationKey& network_anonymization_key,
const url::Origin& origin) { … }
ReportingCacheImpl::ClientMap::iterator ReportingCacheImpl::FindClientIt(
const ReportingEndpointGroupKey& group_key) { … }
ReportingCacheImpl::EndpointGroupMap::iterator
ReportingCacheImpl::FindEndpointGroupIt(
const ReportingEndpointGroupKey& group_key) { … }
ReportingCacheImpl::EndpointMap::iterator ReportingCacheImpl::FindEndpointIt(
const ReportingEndpointGroupKey& group_key,
const GURL& url) { … }
ReportingCacheImpl::ClientMap::iterator ReportingCacheImpl::AddOrUpdateClient(
Client new_client) { … }
void ReportingCacheImpl::AddOrUpdateEndpointGroup(
CachedReportingEndpointGroup new_group) { … }
void ReportingCacheImpl::AddOrUpdateEndpoint(ReportingEndpoint new_endpoint) { … }
void ReportingCacheImpl::RemoveEndpointsInGroupOtherThan(
const ReportingEndpointGroupKey& group_key,
const std::set<GURL>& endpoints_to_keep_urls) { … }
void ReportingCacheImpl::RemoveEndpointGroupsForClientOtherThan(
const NetworkAnonymizationKey& network_anonymization_key,
const url::Origin& origin,
const std::set<std::string>& groups_to_keep_names) { … }
std::vector<ReportingEndpoint> ReportingCacheImpl::GetEndpointsInGroup(
const ReportingEndpointGroupKey& group_key) const { … }
size_t ReportingCacheImpl::GetEndpointCountInGroup(
const ReportingEndpointGroupKey& group_key) const { … }
void ReportingCacheImpl::MarkEndpointGroupAndClientUsed(
ClientMap::iterator client_it,
EndpointGroupMap::iterator group_it,
base::Time now) { … }
std::optional<ReportingCacheImpl::EndpointMap::iterator>
ReportingCacheImpl::RemoveEndpointInternal(ClientMap::iterator client_it,
EndpointGroupMap::iterator group_it,
EndpointMap::iterator endpoint_it) { … }
std::optional<ReportingCacheImpl::EndpointGroupMap::iterator>
ReportingCacheImpl::RemoveEndpointGroupInternal(
ClientMap::iterator client_it,
EndpointGroupMap::iterator group_it,
size_t* num_endpoints_removed) { … }
ReportingCacheImpl::ClientMap::iterator
ReportingCacheImpl::RemoveClientInternal(ClientMap::iterator client_it) { … }
void ReportingCacheImpl::EnforcePerClientAndGlobalEndpointLimits(
ClientMap::iterator client_it) { … }
void ReportingCacheImpl::EvictEndpointsFromClient(ClientMap::iterator client_it,
size_t endpoints_to_evict) { … }
void ReportingCacheImpl::EvictEndpointFromGroup(
ClientMap::iterator client_it,
EndpointGroupMap::iterator group_it) { … }
bool ReportingCacheImpl::RemoveExpiredOrStaleGroups(
ClientMap::iterator client_it,
size_t* num_endpoints_removed) { … }
void ReportingCacheImpl::AddEndpointItToIndex(
EndpointMap::iterator endpoint_it) { … }
void ReportingCacheImpl::RemoveEndpointItFromIndex(
EndpointMap::iterator endpoint_it) { … }
base::Value ReportingCacheImpl::GetClientAsValue(const Client& client) const { … }
base::Value ReportingCacheImpl::GetEndpointGroupAsValue(
const CachedReportingEndpointGroup& group) const { … }
base::Value ReportingCacheImpl::GetEndpointAsValue(
const ReportingEndpoint& endpoint) const { … }
}