#include "content/browser/attribution_reporting/rate_limit_table.h"
#include <stdint.h>
#include <set>
#include <string>
#include <vector>
#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/flat_set.h"
#include "base/memory/raw_ref.h"
#include "base/notreached.h"
#include "base/ranges/functional.h"
#include "base/time/time.h"
#include "base/types/expected.h"
#include "components/attribution_reporting/source_registration.h"
#include "components/attribution_reporting/suitable_origin.h"
#include "content/browser/attribution_reporting/attribution_config.h"
#include "content/browser/attribution_reporting/attribution_info.h"
#include "content/browser/attribution_reporting/attribution_resolver_delegate.h"
#include "content/browser/attribution_reporting/common_source_info.h"
#include "content/browser/attribution_reporting/rate_limit_result.h"
#include "content/browser/attribution_reporting/sql_queries.h"
#include "content/browser/attribution_reporting/sql_utils.h"
#include "content/browser/attribution_reporting/storable_source.h"
#include "content/browser/attribution_reporting/stored_source.h"
#include "net/base/schemeful_site.h"
#include "sql/database.h"
#include "sql/statement.h"
#include "sql/transaction.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "url/origin.h"
namespace content {
namespace {
bool IsAttribution(RateLimitTable::Scope scope) { … }
struct DestinationLimitRecord { … };
}
RateLimitTable::RateLimitTable(const AttributionResolverDelegate* delegate)
: … { … }
RateLimitTable::~RateLimitTable() { … }
bool RateLimitTable::CreateTable(sql::Database* db) { … }
bool RateLimitTable::AddRateLimitForSource(sql::Database* db,
const StoredSource& source,
int64_t destination_limit_priority) { … }
bool RateLimitTable::AddRateLimitForAttribution(
sql::Database* db,
const AttributionInfo& attribution_info,
const StoredSource& source,
Scope scope,
AttributionReport::Id report_id) { … }
bool RateLimitTable::AddRateLimit(
sql::Database* db,
const StoredSource& source,
std::optional<base::Time> trigger_time,
const attribution_reporting::SuitableOrigin& context_origin,
Scope scope,
std::optional<AttributionReport::Id> report_id,
std::optional<int64_t> destination_limit_priority) { … }
RateLimitResult RateLimitTable::AttributionAllowedForAttributionLimit(
sql::Database* db,
const AttributionInfo& attribution_info,
const StoredSource& source,
Scope scope) { … }
RateLimitResult RateLimitTable::SourceAllowedForReportingOriginLimit(
sql::Database* db,
const StorableSource& source,
base::Time source_time) { … }
RateLimitResult RateLimitTable::SourceAllowedForReportingOriginPerSiteLimit(
sql::Database* db,
const StorableSource& source,
base::Time source_time) { … }
base::expected<std::vector<StoredSource::Id>, RateLimitTable::Error>
RateLimitTable::GetSourcesToDeactivateForDestinationLimit(
sql::Database* db,
const StorableSource& source,
base::Time source_time) { … }
bool RateLimitTable::DeactivateSourcesForDestinationLimit(
sql::Database* db,
const std::vector<StoredSource::Id>& source_ids) { … }
RateLimitTable::DestinationRateLimitResult
RateLimitTable::SourceAllowedForDestinationRateLimit(
sql::Database* db,
const StorableSource& source,
base::Time source_time) { … }
RateLimitResult RateLimitTable::SourceAllowedForDestinationPerDayRateLimit(
sql::Database* db,
const StorableSource& source,
base::Time source_time) { … }
RateLimitResult RateLimitTable::AttributionAllowedForReportingOriginLimit(
sql::Database* db,
const AttributionInfo& attribution_info,
const StoredSource& source) { … }
RateLimitResult RateLimitTable::AllowedForReportingOriginLimit(
sql::Database* db,
bool is_source,
const CommonSourceInfo& common_info,
base::Time time,
const base::flat_set<net::SchemefulSite>& destination_sites) { … }
bool RateLimitTable::DeleteAttributionRateLimit(
sql::Database* db,
Scope scope,
AttributionReport::Id report_id) { … }
bool RateLimitTable::ClearAllDataInRange(sql::Database* db,
base::Time delete_begin,
base::Time delete_end) { … }
bool RateLimitTable::ClearAllDataAllTime(sql::Database* db) { … }
bool RateLimitTable::ClearDataForOriginsInRange(
sql::Database* db,
base::Time delete_begin,
base::Time delete_end,
StoragePartition::StorageKeyMatcherFunction filter) { … }
bool RateLimitTable::DeleteExpiredRateLimits(sql::Database* db) { … }
bool RateLimitTable::ClearDataForSourceIds(
sql::Database* db,
const std::vector<StoredSource::Id>& source_ids) { … }
void RateLimitTable::AppendRateLimitDataKeys(
sql::Database* db,
std::set<AttributionDataModel::DataKey>& keys) { … }
void RateLimitTable::SetDelegate(const AttributionResolverDelegate& delegate) { … }
}