#ifndef SERVICES_NETWORK_CORS_PREFLIGHT_CACHE_H_
#define SERVICES_NETWORK_CORS_PREFLIGHT_CACHE_H_
#include <map>
#include <memory>
#include <string>
#include <tuple>
#include "base/component_export.h"
#include "net/base/network_isolation_key.h"
#include "net/http/http_request_headers.h"
#include "services/network/cors/preflight_result.h"
#include "services/network/public/mojom/clear_data_filter.mojom-forward.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "url/origin.h"
class GURL;
namespace net {
class NetLogWithSource;
}
namespace network {
namespace cors {
class COMPONENT_EXPORT(NETWORK_SERVICE) PreflightCache final {
public:
PreflightCache();
PreflightCache(const PreflightCache&) = delete;
PreflightCache& operator=(const PreflightCache&) = delete;
~PreflightCache();
void AppendEntry(const url::Origin& origin,
const GURL& url,
const net::NetworkIsolationKey& network_isolation_key,
std::unique_ptr<PreflightResult> preflight_result);
bool CheckIfRequestCanSkipPreflight(
const url::Origin& origin,
const GURL& url,
const net::NetworkIsolationKey& network_isolation_key,
mojom::CredentialsMode credentials_mode,
const std::string& method,
const net::HttpRequestHeaders& headers,
bool is_revalidating,
const net::NetLogWithSource& net_log,
bool acam_preflight_spec_conformant);
void ClearCache(mojom::ClearDataFilterPtr url_filter);
size_t CountEntriesForTesting() const;
bool DoesEntryExistForTesting(
const url::Origin& origin,
const std::string& url,
const net::NetworkIsolationKey& network_isolation_key);
void MayPurgeForTesting(size_t max_entries, size_t purge_unit);
private:
void MayPurge(size_t max_entries, size_t purge_unit);
std::map<std::tuple<url::Origin ,
std::string ,
net::NetworkIsolationKey >,
std::unique_ptr<PreflightResult>>
cache_;
};
}
}
#endif