#ifndef NET_COOKIES_COOKIE_PARTITION_KEY_COLLECTION_H_
#define NET_COOKIES_COOKIE_PARTITION_KEY_COLLECTION_H_
#include <iosfwd>
#include <optional>
#include "base/containers/flat_set.h"
#include "base/functional/callback_forward.h"
#include "net/base/net_export.h"
#include "net/cookies/cookie_partition_key.h"
namespace net {
class NET_EXPORT CookiePartitionKeyCollection {
public:
CookiePartitionKeyCollection();
explicit CookiePartitionKeyCollection(CookiePartitionKey key);
explicit CookiePartitionKeyCollection(
base::flat_set<CookiePartitionKey> keys);
explicit CookiePartitionKeyCollection(
std::optional<CookiePartitionKey> opt_key);
CookiePartitionKeyCollection(const CookiePartitionKeyCollection& other);
CookiePartitionKeyCollection(CookiePartitionKeyCollection&& other);
CookiePartitionKeyCollection& operator=(
const CookiePartitionKeyCollection& other);
CookiePartitionKeyCollection& operator=(CookiePartitionKeyCollection&& other);
~CookiePartitionKeyCollection();
static CookiePartitionKeyCollection ContainsAll() {
return CookiePartitionKeyCollection(PrivateTag{}, InternalState());
}
static CookiePartitionKeyCollection MatchesSite(
const net::SchemefulSite& top_level_site);
static CookiePartitionKeyCollection Todo() {
return CookiePartitionKeyCollection();
}
bool IsEmpty() const { return state_ && state_->empty(); }
bool ContainsAllKeys() const { return !state_; }
const base::flat_set<CookiePartitionKey>& PartitionKeys() const {
CHECK(!ContainsAllKeys())
<< "Do not call PartitionKeys when ContainsAllKeys is true";
return state_.value();
}
bool Contains(const CookiePartitionKey& key) const;
friend bool operator==(const CookiePartitionKeyCollection& lhs,
const CookiePartitionKeyCollection& rhs) = default;
private:
using InternalState = std::optional<base::flat_set<CookiePartitionKey>>;
struct PrivateTag {};
explicit CookiePartitionKeyCollection(PrivateTag, InternalState state);
InternalState state_;
};
NET_EXPORT std::ostream& operator<<(std::ostream& os,
const CookiePartitionKeyCollection& keys);
}
#endif