#ifndef CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_KEY_H_
#define CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_KEY_H_
#include <optional>
#include <variant>
#include "content/common/content_export.h"
#include "net/base/network_isolation_key.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "url/gurl.h"
namespace content {
class CONTENT_EXPORT PrefetchKey final {
public:
PrefetchKey() = delete;
PrefetchKey(net::NetworkIsolationKey nik, GURL url);
PrefetchKey(std::optional<blink::DocumentToken> referring_document_token,
GURL url);
~PrefetchKey();
PrefetchKey(PrefetchKey&& other);
PrefetchKey& operator=(PrefetchKey&& other);
PrefetchKey(const PrefetchKey& other);
PrefetchKey& operator=(const PrefetchKey& other);
bool operator==(const PrefetchKey& rhs) const = default;
bool operator<(const PrefetchKey& rhs) const {
if (referring_document_token_or_nik_ !=
rhs.referring_document_token_or_nik_) {
return referring_document_token_or_nik_ <
rhs.referring_document_token_or_nik_;
}
return url_ < rhs.url_;
}
const GURL& url() const { return url_; }
PrefetchKey WithNewUrl(const GURL& new_url) const {
return std::visit([&](const auto& e) { return PrefetchKey(e, new_url); },
referring_document_token_or_nik_);
}
bool NonUrlPartIsSame(const PrefetchKey& other) const {
return referring_document_token_or_nik_ ==
other.referring_document_token_or_nik_;
}
private:
friend CONTENT_EXPORT std::ostream& operator<<(
std::ostream& ostream,
const PrefetchKey& prefetch_key);
std::variant<std::optional<blink::DocumentToken>, net::NetworkIsolationKey>
referring_document_token_or_nik_;
GURL url_;
};
CONTENT_EXPORT std::ostream& operator<<(std::ostream& ostream,
const PrefetchKey& prefetch_key);
}
#endif