1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_IP_PROTECTION_COMMON_IP_PROTECTION_CORE_H_
#define COMPONENTS_IP_PROTECTION_COMMON_IP_PROTECTION_CORE_H_
#include <cstddef>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "components/content_settings/core/common/content_settings.h"
class GURL;
namespace net {
class ProxyChain;
class NetworkAnonymizationKey;
} // namespace net
namespace ip_protection {
struct BlindSignedAuthToken;
// Core business logic for IP Protection.
class IpProtectionCore {
public:
virtual ~IpProtectionCore() = default;
virtual bool IsIpProtectionEnabled() = 0;
// Check whether the masked domain list is populated.
virtual bool IsMdlPopulated() = 0;
// Check whether the given request URL and NAK should be proxied.
virtual bool RequestShouldBeProxied(
const GURL& request_url,
const net::NetworkAnonymizationKey& network_anonymization_key) = 0;
// Check whether tokens are available in all token caches.
//
// This function is called on every URL load, so it should complete quickly.
virtual bool AreAuthTokensAvailable() = 0;
// Check whether probabilistic reveal tokens are available.
// This function is called during the URL loads, so it should complete
// quickly.
virtual bool IsProbabilisticRevealTokenAvailable() = 0;
// Check whether the tokens in either cache have ever been filled.
//
// If even one cache has not been filled at least once, this method should
// return false. Also, this method will ALWAYS return false if the proxy list
// is unavailable.
virtual bool WereTokenCachesEverFilled() = 0;
// Get a token, if one is available.
//
// Returns `nullopt` if no token is available, whether for a transient or
// permanent reason. This method may return `nullopt` even if
// `IsAuthTokenAvailable()` recently returned `true`.
virtual std::optional<BlindSignedAuthToken> GetAuthToken(
size_t chain_index) = 0;
// Get a serialized and base64 encoded probabilistic reveal token if one is
// available.
//
// Returns `nullopt` if no token is available, whether for a transient or
// permanent reason, or if the serialization fails.
virtual std::optional<std::string> GetProbabilisticRevealToken(
const std::string& top_level,
const std::string& third_party) = 0;
// Check whether a proxy chain list is available.
virtual bool IsProxyListAvailable() = 0;
// Notifies that QUIC proxies failed for a request, suggesting that QUIC may
// not work on this network.
virtual void QuicProxiesFailed() = 0;
// Return the currently cached proxy chain lists. This contains the lists of
// hostnames corresponding to each proxy chain that should be used. This
// may be empty even if `IsProxyListAvailable()` returned true.
virtual std::vector<net::ProxyChain> GetProxyChainList() = 0;
// Request a refresh of the proxy chain list. Call this when it's likely that
// the proxy chain list is out of date.
virtual void RequestRefreshProxyList() = 0;
// Callback function used by `IpProtectionProxyConfigManager` and
// `IpProtectionTokenManager` to signal a possible geo change due to a
// refreshed proxy list or refill of tokens.
virtual void GeoObserved(const std::string& geo_id) = 0;
// Returns whether `first_party_url` has a tracking protection exception. This
// url can match a subdomain of an exception (i.e. an exception for
// example.com covers all domains in this pattern: [*.]example.com).
virtual bool HasTrackingProtectionException(
const GURL& first_party_url) const = 0;
// Sets the TRACKING_PROTECTION content settings list to `settings`.
virtual void SetTrackingProtectionContentSetting(
const ContentSettingsForOneType& settings) = 0;
// Check whether the given request URL is eligible to receive
// ProbabilisticRevealToken headers.
virtual bool ShouldRequestIncludeProbabilisticRevealToken(
const GURL& request_url) = 0;
};
} // namespace ip_protection
#endif // COMPONENTS_IP_PROTECTION_COMMON_IP_PROTECTION_CORE_H_
|