#include "components/safe_browsing/core/browser/tailored_security_service/tailored_security_service.h"
#include <memory>
#include <optional>
#include <utility>
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/observer_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/browser/tailored_security_service/tailored_security_notification_result.h"
#include "components/safe_browsing/core/browser/tailored_security_service/tailored_security_service_observer.h"
#include "components/safe_browsing/core/browser/tailored_security_service/tailored_security_service_util.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/safe_browsing_policy_handler.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/primary_account_access_token_fetcher.h"
#include "components/signin/public/identity_manager/scope_set.h"
#include "components/sync/base/user_selectable_type.h"
#include "components/sync/service/sync_service.h"
#include "components/sync/service/sync_user_settings.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_urls.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/base/load_flags.h"
#include "net/base/url_util.h"
#include "net/http/http_status_code.h"
#include "net/http/http_util.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"
#include "url/gurl.h"
namespace safe_browsing {
namespace {
const int kRepeatingCheckTailoredSecurityBitDelayInMinutes = …;
const char kQueryTailoredSecurityServiceUrl[] = …;
const size_t kMaxRetries = …;
CoreAccountId GetAccountForRequest(
const signin::IdentityManager* identity_manager) { … }
class RequestImpl : public TailoredSecurityService::Request { … };
}
TailoredSecurityService::Request::Request() = default;
TailoredSecurityService::Request::~Request() = default;
TailoredSecurityService::TailoredSecurityService(
signin::IdentityManager* identity_manager,
syncer::SyncService* sync_service,
PrefService* prefs)
: … { … }
TailoredSecurityService::~TailoredSecurityService() { … }
void TailoredSecurityService::AddObserver(
TailoredSecurityServiceObserver* observer) { … }
void TailoredSecurityService::RemoveObserver(
TailoredSecurityServiceObserver* observer) { … }
std::unique_ptr<TailoredSecurityService::Request>
TailoredSecurityService::CreateRequest(
const GURL& url,
CompletionCallback callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation) { … }
size_t
TailoredSecurityService::GetNumberOfPendingTailoredSecurityServiceRequests() { … }
bool TailoredSecurityService::AddQueryRequest() { … }
void TailoredSecurityService::RemoveQueryRequest() { … }
void TailoredSecurityService::QueryTailoredSecurityBit() { … }
void TailoredSecurityService::StartRequest(
QueryTailoredSecurityBitCallback callback) { … }
void TailoredSecurityService::OnTailoredSecurityBitRetrieved(
bool is_enabled,
base::Time previous_update) { … }
void TailoredSecurityService::MaybeNotifySyncUser(bool is_enabled,
base::Time previous_update) { … }
bool TailoredSecurityService::HistorySyncEnabledForUser() { … }
void TailoredSecurityService::
ExtractTailoredSecurityBitFromResponseAndRunCallback(
QueryTailoredSecurityBitCallback callback,
Request* request,
bool success) { … }
void TailoredSecurityService::SetTailoredSecurityBitForTesting(
bool is_enabled,
QueryTailoredSecurityBitCallback callback,
const net::NetworkTrafficAnnotationTag& traffic_annotation) { … }
base::Value::Dict TailoredSecurityService::ReadResponse(Request* request) { … }
void TailoredSecurityService::Shutdown() { … }
void TailoredSecurityService::TailoredSecurityTimestampUpdateCallback() { … }
void TailoredSecurityService::SaveRetryState(TailoredSecurityRetryState state) { … }
void TailoredSecurityService::SetCanQuery(bool can_query) { … }
}