#include "components/safe_browsing/core/browser/hashprefix_realtime/ohttp_key_service.h"
#include "base/base64.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/strings/escape.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/browser/utils/backoff_operator.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/hashprefix_realtime/hash_realtime_utils.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/common/utils.h"
#include "google_apis/google_api_keys.h"
#include "net/base/net_errors.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace {
constexpr base::TimeDelta kKeyFetchTimeout = …;
constexpr char kKeyFetchServerUrl[] = …;
constexpr base::TimeDelta kKeyExpirationDuration = …;
constexpr base::TimeDelta kSlowerKeyExpirationDuration = …;
constexpr base::TimeDelta kKeyCloseToExpirationThreshold = …;
constexpr base::TimeDelta kAsyncFetchCheckInterval = …;
constexpr base::TimeDelta kAsyncFetchCheckMinInterval = …;
constexpr net::HttpStatusCode kKeyRelatedHttpErrorCode = …;
constexpr char kKeyRotatedHeader[] = …;
constexpr int kServerTriggeredFetchMaxDelayTimeSec = …;
const size_t kNumFailuresToEnforceBackoff = …;
const size_t kMinBackOffResetDurationInSeconds = …;
const size_t kMaxBackOffResetDurationInSeconds = …;
constexpr net::NetworkTrafficAnnotationTag kOhttpKeyTrafficAnnotation = …;
bool IsEnabled(PrefService* pref_service, std::optional<std::string> country) { … }
GURL GetKeyFetchingUrl() { … }
}
namespace safe_browsing {
OhttpKeyService::OhttpKeyService(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* pref_service,
PrefService* local_state,
base::RepeatingCallback<std::optional<std::string>()> country_getter)
: … { … }
OhttpKeyService::~OhttpKeyService() = default;
void OhttpKeyService::OnConfiguringPrefsChanged() { … }
void OhttpKeyService::SetEnabled(bool enable) { … }
void OhttpKeyService::GetOhttpKey(Callback callback) { … }
void OhttpKeyService::NotifyLookupResponse(
const std::string& key,
int response_code,
scoped_refptr<net::HttpResponseHeaders> headers) { … }
void OhttpKeyService::StartFetch(Callback callback,
FetchTriggerReason trigger_reason) { … }
void OhttpKeyService::OnURLLoaderComplete(
base::TimeTicks request_start_time,
std::unique_ptr<std::string> response_body) { … }
void OhttpKeyService::MaybeStartOrRescheduleAsyncFetch() { … }
void OhttpKeyService::OnAsyncFetchCompleted(
std::optional<std::string> ohttp_key) { … }
bool OhttpKeyService::ShouldStartAsyncFetch() { … }
void OhttpKeyService::MaybeStartServerTriggeredFetch(
std::string previous_key,
FetchTriggerReason trigger_reason) { … }
void OhttpKeyService::PopulateKeyFromPref() { … }
void OhttpKeyService::StoreKeyToPref() { … }
void OhttpKeyService::Shutdown() { … }
void OhttpKeyService::set_ohttp_key_for_testing(
OhttpKeyAndExpiration ohttp_key) { … }
std::optional<OhttpKeyService::OhttpKeyAndExpiration>
OhttpKeyService::get_ohttp_key_for_testing() { … }
}