#include "content/browser/interest_group/bidding_and_auction_serializer.h"
#include <algorithm>
#include <array>
#include <optional>
#include <set>
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/containers/flat_map.h"
#include "base/feature_list.h"
#include "base/json/json_string_value_serializer.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/checked_math.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/time/time.h"
#include "components/cbor/diagnostic_writer.h"
#include "components/cbor/values.h"
#include "components/cbor/writer.h"
#include "content/browser/interest_group/interest_group_auction.h"
#include "content/browser/interest_group/interest_group_caching_storage.h"
#include "content/browser/interest_group/storage_interest_group.h"
#include "content/public/common/content_switches.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.mojom.h"
#include "third_party/abseil-cpp/absl/numeric/bits.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/interest_group/interest_group.h"
#include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h"
#include "third_party/zlib/google/compression_utils.h"
namespace content {
namespace {
const size_t kFramingHeaderSize = …;
const size_t kOhttpEncIdSize = …;
const size_t kOhttpSharedSecretSize = …;
const size_t kOhttpHeaderSize = …;
const uint8_t kRequestVersion = …;
const uint8_t kRequestVersionBitOffset = …;
const uint8_t kGzipCompression = …;
const uint8_t kCompressionBitOffset = …;
const std::array<uint32_t, 7> kBinSizes = …;
struct ValueAndSize { … };
struct CompressedInterestGroups { … };
struct SerializedBiddersMap { … };
constexpr std::size_t constexpr_strlen(const char* s) { … }
constexpr size_t LengthOfLength(uint64_t length) { … }
size_t MaxLengthOfTaggedData(uint64_t length) { … }
constexpr base::CheckedNumeric<size_t> TaggedStringLength(size_t length) { … }
constexpr base::CheckedNumeric<size_t> TaggedUIntLength(uint64_t value) { … }
constexpr base::CheckedNumeric<size_t> TaggedSIntLength(int64_t value) { … }
base::CheckedNumeric<size_t> TaggedArrayLength(
const cbor::Value::ArrayValue& array,
base::CheckedNumeric<size_t> elements_size) { … }
base::CheckedNumeric<size_t> TaggedMapLength(
const cbor::Value::MapValue& map,
base::CheckedNumeric<size_t> elements_size) { … }
ValueAndSize SerializeAds(const std::vector<blink::InterestGroup::Ad>& ads,
bool include_full_ads) { … }
ValueAndSize SerializeInterestGroup(base::Time start_time,
const SingleStorageInterestGroup& group) { … }
CompressedInterestGroups CompressInterestGroups(
const url::Origin& owner,
const std::vector<SingleStorageInterestGroup>& groups,
base::Time start_time,
std::optional<uint32_t> target_uncompressed_size) { … }
SerializedBiddersMap SerializeBidderGroupsWithConfig(
const std::vector<
std::pair<url::Origin, std::vector<SingleStorageInterestGroup>>>&
bidders_and_groups,
const blink::mojom::AuctionDataConfig& config,
size_t total_size_before_groups,
base::Time start_time) { … }
}
BiddingAndAuctionData::BiddingAndAuctionData() = default;
BiddingAndAuctionData::BiddingAndAuctionData(BiddingAndAuctionData&& other) =
default;
BiddingAndAuctionData::~BiddingAndAuctionData() = default;
BiddingAndAuctionData& BiddingAndAuctionData::operator=(
BiddingAndAuctionData&& other) = default;
BiddingAndAuctionSerializer::TargetSizeEstimator::TargetSizeEstimator(
size_t total_size_before_groups,
const blink::mojom::AuctionDataConfig* config)
: … { … }
BiddingAndAuctionSerializer::TargetSizeEstimator::~TargetSizeEstimator() =
default;
void BiddingAndAuctionSerializer::TargetSizeEstimator::UpdatePerBuyerMaxSize(
const url::Origin& bidder,
size_t max_size) { … }
std::optional<uint64_t>
BiddingAndAuctionSerializer::TargetSizeEstimator::EstimateTargetSize(
const url::Origin& bidder,
base::CheckedNumeric<size_t> bidders_elements_size) { … }
void BiddingAndAuctionSerializer::TargetSizeEstimator::UpdateSizedGroupSizes(
size_t remaining_size) { … }
void BiddingAndAuctionSerializer::TargetSizeEstimator::UpdateUnsizedGroupSizes(
size_t remaining_size) { … }
BiddingAndAuctionSerializer::BiddingAndAuctionSerializer() = default;
BiddingAndAuctionSerializer::BiddingAndAuctionSerializer(
BiddingAndAuctionSerializer&& other) = default;
BiddingAndAuctionSerializer::~BiddingAndAuctionSerializer() = default;
void BiddingAndAuctionSerializer::AddGroups(
const url::Origin& owner,
scoped_refptr<StorageInterestGroups> groups) { … }
BiddingAndAuctionData BiddingAndAuctionSerializer::Build() { … }
}