#include "chrome/browser/predictors/lcp_critical_path_predictor/lcp_critical_path_predictor_util.h"
#include "base/containers/contains.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
#include "net/base/network_change_notifier.h"
#include "net/base/url_util.h"
#include "third_party/blink/public/common/features.h"
#include "url/origin.h"
namespace predictors {
namespace {
constexpr std::string_view kLcppTableName = …;
constexpr std::string_view kLcppTableNameInitiatorOrigin = …;
const char kCreateProtoTableStatementTemplate[] = …;
std::vector<std::pair<double, std::string>> ConvertToFrequencyStringPair(
const LcppStringFrequencyStatData& data) { … }
bool IsValidUrlInLcppStringFrequencyStatData(const std::string& url) { … }
std::vector<std::string> PredictLcpElementLocators(const LcppStat& stat) { … }
std::vector<GURL> PredictLcpInfluencerScripts(const LcppStat& stat) { … }
double SumOfFrequency(const std::map<std::string, double>& histogram,
double other_bucket_frequency) { … }
class LcppFrequencyStatDataUpdater { … };
bool RecordLcpElementLocatorHistogram(const LoadingPredictorConfig& config,
const std::string& lcp_element_locator,
LcppStat& stat) { … }
bool RecordLcpInfluencerScriptUrlsHistogram(
const LoadingPredictorConfig& config,
const std::vector<GURL>& lcp_influencer_scripts,
LcppStat& stat) { … }
bool RecordPreconnectOriginsHistogram(const LoadingPredictorConfig& config,
const std::vector<GURL>& origins,
LcppStat& stat) { … }
bool RecordFetchedFontUrlsHistogram(const LoadingPredictorConfig& config,
const std::vector<GURL>& fetched_font_urls,
LcppStat& stat) { … }
bool RecordFetchedSubresourceUrlsHistogram(
const LoadingPredictorConfig& config,
const std::map<GURL, base::TimeDelta>& fetched_subresource_urls,
LcppStat& stat) { … }
bool IsValidLcpElementLocatorHistogram(
const LcpElementLocatorStat& lcp_element_locator_stat) { … }
bool RecordUnusedPreloadUrlsHistogram(const LoadingPredictorConfig& config,
const std::vector<GURL>& unused_preloads,
LcppStat& stat) { … }
bool IsValidLcpUrlsHistogram(
const LcppStringFrequencyStatData& lcpp_stat_data) { … }
size_t GetLCPPMultipleKeyMaxPathLength() { … }
bool IsKeyLengthValidForMultipleKey(const std::string& host,
const std::string& first_level_path) { … }
bool IsLcppMultipleKeyKeyStatEnabled() { … }
std::string GetLCPPDatabaseKey(const GURL& url) { … }
LcppStat* TryToGetLcppStatForKeyStat(const LoadingPredictorConfig& config,
const GURL& url,
LcppData& data,
bool& data_updated) { … }
bool IsLCPPFontPrefetchExcludedHost(const GURL& url) { … }
class FakeLoadingPredictorKeyValueTable
: public sqlite_proto::KeyValueTable<LcppData> { … };
bool EnsureTable(sql::Database* db, const std::string_view& table_name) { … }
bool IsInitiatorOriginEnabled() { … }
void DeleteTables(std::unique_ptr<LcppDataMap::DataTable> data_table,
std::unique_ptr<LcppDataMap::OriginTable> origin_table) { … }
}
std::optional<blink::mojom::LCPCriticalPathPredictorNavigationTimeHint>
ConvertLcppStatToLCPCriticalPathPredictorNavigationTimeHint(
const LcppStat& lcpp_stat) { … }
std::vector<GURL> PredictFetchedFontUrls(const LcppStat& stat) { … }
std::vector<GURL> PredictPreconnectableOrigins(const LcppStat& stat) { … }
std::vector<GURL> PredictFetchedSubresourceUrls(const LcppStat& stat) { … }
std::vector<GURL> PredictUnusedPreloads(const LcppStat& stat) { … }
LcppDataInputs::LcppDataInputs() = default;
LcppDataInputs::~LcppDataInputs() = default;
bool UpdateLcppStatWithLcppDataInputs(const LoadingPredictorConfig& config,
const LcppDataInputs& inputs,
LcppStat& stat) { … }
void UpdateLcppStringFrequencyStatData(
size_t sliding_window_size,
size_t max_histogram_buckets,
const std::string& new_entry,
LcppStringFrequencyStatData& lcpp_stat_data,
std::optional<std::string>& dropped_entry) { … }
bool IsValidLcppStat(const LcppStat& lcpp_stat) { … }
bool IsURLValidForLcpp(const GURL& url) { … }
std::string GetFirstLevelPath(const GURL& url) { … }
LcppDataMap::LcppDataMap(scoped_refptr<sqlite_proto::TableManager> manager,
const LoadingPredictorConfig& config)
: … { … }
LcppDataMap::LcppDataMap(scoped_refptr<sqlite_proto::TableManager> manager,
const LoadingPredictorConfig& config,
std::unique_ptr<DataTable> data_table)
: … { … }
std::unique_ptr<LcppDataMap> LcppDataMap::CreateWithMockTableForTesting(
scoped_refptr<sqlite_proto::TableManager> manager,
const LoadingPredictorConfig& config) { … }
LcppDataMap::~LcppDataMap() { … }
void LcppDataMap::InitializeOnDBSequence() { … }
void LcppDataMap::InitializeAfterDBInitialization() { … }
bool LcppDataMap::LearnLcpp(const std::optional<url::Origin>& initiator_origin,
const GURL& url,
const LcppDataInputs& inputs) { … }
std::optional<LcppStat> LcppDataMap::GetLcppStat(
const std::optional<url::Origin>& initiator_origin,
const GURL& url) const { … }
void LcppDataMap::DeleteUrls(const std::vector<GURL>& urls) { … }
void LcppDataMap::DeleteAllData() { … }
const std::map<std::string, LcppData>& LcppDataMap::GetAllCachedForTesting() { … }
const std::map<std::string, LcppOrigin>&
LcppDataMap::GetAllCachedOriginForTesting() { … }
bool LcppDataMap::CreateOrClearTablesIfNecessary(sql::Database* db) { … }
}