#include "components/affiliations/core/browser/affiliation_backend.h"
#include <stdint.h>
#include <algorithm>
#include <utility>
#include <vector>
#include "base/barrier_closure.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/clock.h"
#include "base/time/tick_clock.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "components/affiliations/core/browser/affiliation_database.h"
#include "components/affiliations/core/browser/affiliation_fetch_throttler.h"
#include "components/affiliations/core/browser/affiliation_fetcher_factory_impl.h"
#include "components/affiliations/core/browser/affiliation_fetcher_interface.h"
#include "components/affiliations/core/browser/affiliation_utils.h"
#include "components/affiliations/core/browser/facet_manager.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace affiliations {
namespace {
void IgnoreResult(base::OnceClosure callback, const AffiliatedFacets&, bool) { … }
}
AffiliationBackend::AffiliationBackend(
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
base::Clock* time_source,
const base::TickClock* time_tick_source)
: … { … }
AffiliationBackend::~AffiliationBackend() = default;
void AffiliationBackend::Initialize(
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory,
network::NetworkConnectionTracker* network_connection_tracker,
const base::FilePath& db_path) { … }
void AffiliationBackend::GetAffiliationsAndBranding(
const FacetURI& facet_uri,
StrategyOnCacheMiss cache_miss_strategy,
AffiliationService::ResultCallback callback,
const scoped_refptr<base::TaskRunner>& callback_task_runner) { … }
void AffiliationBackend::Prefetch(const FacetURI& facet_uri,
const base::Time& keep_fresh_until) { … }
void AffiliationBackend::CancelPrefetch(const FacetURI& facet_uri,
const base::Time& keep_fresh_until) { … }
void AffiliationBackend::KeepPrefetchForFacets(
std::vector<FacetURI> facet_uris) { … }
void AffiliationBackend::TrimCacheForFacetURI(const FacetURI& facet_uri) { … }
void AffiliationBackend::TrimUnusedCache(std::vector<FacetURI> facet_uris) { … }
std::vector<GroupedFacets> AffiliationBackend::GetGroupingInfo(
std::vector<FacetURI> facet_uris) const { … }
std::vector<std::string> AffiliationBackend::GetPSLExtensions() const { … }
void AffiliationBackend::UpdateAffiliationsAndBranding(
const std::vector<FacetURI>& facets,
base::OnceClosure callback) { … }
void AffiliationBackend::DeleteCache(const base::FilePath& db_path) { … }
void AffiliationBackend::SetFetcherFactoryForTesting(
std::unique_ptr<AffiliationFetcherFactory> fetcher_factory) { … }
AffiliationDatabase& AffiliationBackend::GetAffiliationDatabaseForTesting() { … }
FacetManager* AffiliationBackend::GetOrCreateFacetManager(
const FacetURI& facet_uri) { … }
void AffiliationBackend::DiscardCachedDataIfNoLongerNeeded(
const AffiliatedFacets& affiliated_facets) { … }
void AffiliationBackend::OnSendNotification(const FacetURI& facet_uri) { … }
bool AffiliationBackend::ReadAffiliationsAndBrandingFromDatabase(
const FacetURI& facet_uri,
AffiliatedFacetsWithUpdateTime* affiliations) { … }
void AffiliationBackend::SignalNeedNetworkRequest() { … }
void AffiliationBackend::RequestNotificationAtTime(const FacetURI& facet_uri,
base::Time time) { … }
void AffiliationBackend::OnFetchSucceeded(
AffiliationFetcherInterface* fetcher,
std::unique_ptr<AffiliationFetcherDelegate::Result> result) { … }
void AffiliationBackend::OnFetchFailed(AffiliationFetcherInterface* fetcher) { … }
void AffiliationBackend::OnMalformedResponse(
AffiliationFetcherInterface* fetcher) { … }
bool AffiliationBackend::OnCanSendNetworkRequest() { … }
void AffiliationBackend::ReportStatistics(size_t requested_facet_uri_count) { … }
void AffiliationBackend::SetThrottlerForTesting(
std::unique_ptr<AffiliationFetchThrottler> throttler) { … }
}