chromium/chrome/common/privacy_budget/types.h

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_COMMON_PRIVACY_BUDGET_TYPES_H_
#define CHROME_COMMON_PRIVACY_BUDGET_TYPES_H_

#include <type_traits>
#include <vector>

#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "chrome/common/privacy_budget/field_trial_param_conversions.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_surface.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_token.h"

// Common container and map types. In order to verify successful encoding and
// decoding, each of these must be tested in
// field_trial_param_conversions_unittest.cc.
//
// In all cases, the choice of container assumes that:
//   1. Size is relatively low: Use of a contiguous container helps with data
//      locality.
//   2. Mutations are uncommon: A contiguous container is usually expensive to
//      mutate, but fast lookups and locality make up for it.
//
// If other characteristics are desired, then we should consider other container
// types. Please test encoding/decoding when using new container types.

IdentifiableSurfaceSet;

IdentifiableSurfaceTypeSet;

IdentifiableSurfaceList;

IdentifiableSurfaceTypeList;

// Sampling rates are represented as the denominator of a quotient 1/R. I.e.
// A sampling rate of 1 in 100 is represented using the integer 100.
IdentifiableSurfaceSampleRateMap;

// Sampling rates are represented as the denominator of a quotient 1/R. I.e.
// A sampling rate of 1 in 100 is represented using the integer 100.
IdentifiableSurfaceTypeSampleRateMap;

// See SurfaceSetValuation for details on the costing model and the units for
// cost.
PrivacyBudgetCost;

IdentifiableSurfaceCostMap;

IdentifiableSurfaceTypeCostMap;

// See SurfaceSetEquivalence for details on how equivalence classes work.
// SurfaceSetEquivalentClassesList contains a list of equivalence classes. Each
// class is encoded as a list of surfaces.
//
// **The first element in the list is considered to be the representative
// surface for that class.
//
// Obv an equivalence set which contains just zero or one members is
// nonsensical. For the purpose of ecoding/decoding such instances are ignored.
SurfaceSetEquivalentClassesList;

// Similar to the SurfaceSetEquivalentClassesList, but is semantically different
// in that the ordering doesn't matter. There's no assumption that the first
// element of each list is special in any meaningful way.
IdentifiableSurfaceBlocks;

namespace privacy_budget_internal {

template <>
struct SortWhenSerializing<IdentifiableSurfaceSet> : std::true_type {};
template <>
struct SortWhenSerializing<IdentifiableSurfaceTypeSet> : std::true_type {};

}  // namespace privacy_budget_internal
#endif  // CHROME_COMMON_PRIVACY_BUDGET_TYPES_H_