#ifndef NET_REPORTING_REPORTING_ENDPOINT_H_
#define NET_REPORTING_REPORTING_ENDPOINT_H_
#include <string>
#include <vector>
#include "base/time/time.h"
#include "base/unguessable_token.h"
#include "net/base/net_export.h"
#include "net/base/network_anonymization_key.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace net {
struct NET_EXPORT ReportingEndpointGroupKey {
ReportingEndpointGroupKey();
ReportingEndpointGroupKey(
const NetworkAnonymizationKey& network_anonymization_key,
const url::Origin& origin,
const std::string& group_name);
ReportingEndpointGroupKey(
const NetworkAnonymizationKey& network_anonymization_key,
absl::optional<base::UnguessableToken> reporting_source,
const url::Origin& origin,
const std::string& group_name);
ReportingEndpointGroupKey(
const ReportingEndpointGroupKey& other,
const absl::optional<base::UnguessableToken>& reporting_source);
ReportingEndpointGroupKey(const ReportingEndpointGroupKey& other);
ReportingEndpointGroupKey(ReportingEndpointGroupKey&& other);
ReportingEndpointGroupKey& operator=(const ReportingEndpointGroupKey&);
ReportingEndpointGroupKey& operator=(ReportingEndpointGroupKey&&);
~ReportingEndpointGroupKey();
std::string ToString() const;
bool IsDocumentEndpoint() const { return reporting_source.has_value(); }
NetworkAnonymizationKey network_anonymization_key;
absl::optional<base::UnguessableToken> reporting_source;
url::Origin origin;
std::string group_name;
};
NET_EXPORT bool operator==(const ReportingEndpointGroupKey& lhs,
const ReportingEndpointGroupKey& rhs);
NET_EXPORT bool operator!=(const ReportingEndpointGroupKey& lhs,
const ReportingEndpointGroupKey& rhs);
NET_EXPORT bool operator<(const ReportingEndpointGroupKey& lhs,
const ReportingEndpointGroupKey& rhs);
NET_EXPORT bool operator>(const ReportingEndpointGroupKey& lhs,
const ReportingEndpointGroupKey& rhs);
struct NET_EXPORT ReportingEndpoint {
struct NET_EXPORT EndpointInfo {
static const int kDefaultPriority;
static const int kDefaultWeight;
GURL url;
int priority = kDefaultPriority;
int weight = kDefaultWeight;
};
struct Statistics {
int attempted_uploads = 0;
int successful_uploads = 0;
int attempted_reports = 0;
int successful_reports = 0;
};
ReportingEndpoint();
ReportingEndpoint(const ReportingEndpointGroupKey& group,
const EndpointInfo& info);
ReportingEndpoint(const ReportingEndpoint& other);
ReportingEndpoint(ReportingEndpoint&& other);
ReportingEndpoint& operator=(const ReportingEndpoint&);
ReportingEndpoint& operator=(ReportingEndpoint&&);
~ReportingEndpoint();
bool is_valid() const;
explicit operator bool() const { return is_valid(); }
ReportingEndpointGroupKey group_key;
EndpointInfo info;
Statistics stats;
};
enum class OriginSubdomains { EXCLUDE, INCLUDE, DEFAULT = EXCLUDE };
struct NET_EXPORT ReportingEndpointGroup {
ReportingEndpointGroup();
ReportingEndpointGroup(const ReportingEndpointGroup& other);
~ReportingEndpointGroup();
ReportingEndpointGroupKey group_key;
OriginSubdomains include_subdomains = OriginSubdomains::DEFAULT;
base::TimeDelta ttl;
std::vector<ReportingEndpoint::EndpointInfo> endpoints;
};
struct NET_EXPORT CachedReportingEndpointGroup {
CachedReportingEndpointGroup(const ReportingEndpointGroupKey& group_key,
OriginSubdomains include_subdomains,
base::Time expires,
base::Time last_used);
CachedReportingEndpointGroup(const ReportingEndpointGroup& endpoint_group,
base::Time now);
ReportingEndpointGroupKey group_key;
OriginSubdomains include_subdomains = OriginSubdomains::DEFAULT;
base::Time expires;
base::Time last_used;
};
}
#endif