#include "content/browser/preloading/prerender/prerender_metrics.h"
#include <cmath>
#include <memory>
#include <optional>
#include "base/check_op.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/metrics_hashes.h"
#include "base/strings/string_util.h"
#include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/preloading/preloading_trigger_type_impl.h"
#include "content/browser/preloading/prerender/prerender_final_status.h"
#include "content/browser/preloading/prerender/prerender_host.h"
#include "content/public/browser/preloading_trigger_type.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
namespace content {
namespace {
enum HeaderMismatchType : uint32_t { … };
PrerenderCancelledInterface GetCancelledInterfaceType(
const std::string& interface_name) { … }
int32_t InterfaceNameHasher(const std::string& interface_name) { … }
int32_t HeaderMismatchHasher(const std::string& header,
HeaderMismatchType mismatch_type) { … }
std::string GenerateHistogramName(const std::string& histogram_base_name,
PreloadingTriggerType trigger_type,
const std::string& embedder_suffix) { … }
void ReportHeaderMismatch(const std::string& key,
HeaderMismatchType mismatch_type,
const std::string& histogram_suffix) { … }
void ReportAllPrerenderMismatchedHeaders(
const std::vector<PrerenderMismatchedHeaders>& mismatched_headers,
const std::string& histogram_suffix) { … }
void RecordPrerenderCancelledInterface(const std::string& interface_name,
const std::string& histogram_suffix) { … }
void RecordPrerenderFinalStatusUma(
PrerenderFinalStatus final_status,
PreloadingTriggerType trigger_type,
const std::string& embedder_histogram_suffix) { … }
void RecordDidFailLoadErrorType(int32_t error_code,
const std::string& histogram_suffix) { … }
}
PrerenderCancellationReason
PrerenderCancellationReason::BuildForDisallowActivationState(
uint64_t disallow_activation_reason) { … }
PrerenderCancellationReason
PrerenderCancellationReason::BuildForMojoBinderPolicy(
const std::string& interface_name) { … }
const std::vector<PrerenderMismatchedHeaders>*
PrerenderCancellationReason::GetPrerenderMismatchedHeaders() const { … }
PrerenderCancellationReason PrerenderCancellationReason::
CreateCandidateReasonForActivationParameterMismatch() { … }
void PrerenderCancellationReason::SetPrerenderMismatchedHeaders(
std::unique_ptr<std::vector<PrerenderMismatchedHeaders>>
mismatched_headers) { … }
PrerenderCancellationReason PrerenderCancellationReason::BuildForLoadingError(
int32_t error_code) { … }
PrerenderCancellationReason::PrerenderCancellationReason(
PrerenderFinalStatus final_status)
: … { … }
PrerenderCancellationReason::PrerenderCancellationReason(
PrerenderCancellationReason&& reason) = default;
PrerenderCancellationReason::~PrerenderCancellationReason() = default;
PrerenderCancellationReason::PrerenderCancellationReason(
PrerenderFinalStatus final_status,
DetailedReasonVariant explanation)
: … { … }
void PrerenderCancellationReason::ReportMetrics(
const std::string& histogram_suffix) const { … }
std::optional<std::string>
PrerenderCancellationReason::DisallowedMojoInterface() const { … }
PrerenderMismatchedHeaders::PrerenderMismatchedHeaders(
const std::string& header_name,
const std::optional<std::string> initial_value,
const std::optional<std::string> activation_value)
: … { … }
PrerenderMismatchedHeaders::~PrerenderMismatchedHeaders() = default;
PrerenderMismatchedHeaders::PrerenderMismatchedHeaders(
const PrerenderMismatchedHeaders& other) = default;
PrerenderMismatchedHeaders::PrerenderMismatchedHeaders(
PrerenderMismatchedHeaders&& other) = default;
PrerenderMismatchedHeaders& PrerenderMismatchedHeaders::operator=(
const PrerenderMismatchedHeaders& other) = default;
PrerenderMismatchedHeaders& PrerenderMismatchedHeaders::operator=(
PrerenderMismatchedHeaders&& other) = default;
std::string GeneratePrerenderHistogramSuffix(
PreloadingTriggerType trigger_type,
const std::string& embedder_suffix) { … }
void RecordPrerenderTriggered(ukm::SourceId ukm_id) { … }
void RecordPrerenderActivationTime(
base::TimeDelta delta,
PreloadingTriggerType trigger_type,
const std::string& embedder_histogram_suffix) { … }
void RecordFailedPrerenderFinalStatus(
const PrerenderCancellationReason& cancellation_reason,
const PrerenderAttributes& attributes) { … }
void ReportSuccessActivation(const PrerenderAttributes& attributes,
ukm::SourceId prerendered_ukm_id) { … }
void RecordPrerenderActivationNavigationParamsMatch(
PrerenderHost::ActivationNavigationParamsMatch result,
const std::string& histogram_suffix) { … }
void RecordPrerenderRedirectionMismatchType(
PrerenderCrossOriginRedirectionMismatch mismatch_type,
const std::string& histogram_suffix) { … }
void RecordPrerenderRedirectionProtocolChange(
PrerenderCrossOriginRedirectionProtocolChange change_type,
const std::string& histogram_suffix) { … }
void RecordPrerenderActivationTransition(
int32_t potential_activation_transition,
const std::string& histogram_suffix) { … }
static_assert …;
PreloadingEligibility ToPreloadingEligibility(
PrerenderBackNavigationEligibility eligibility) { … }
void RecordPrerenderBackNavigationEligibility(
PreloadingPredictor predictor,
PrerenderBackNavigationEligibility eligibility,
PreloadingAttempt* preloading_attempt) { … }
void RecordPrerenderActivationCommitDeferTime(
base::TimeDelta time_delta,
PreloadingTriggerType trigger_type,
const std::string& embedder_histogram_suffix) { … }
void RecordReceivedPrerendersPerPrimaryPageChangedCount(
int number,
PreloadingTriggerType trigger_type,
const std::string& eagerness_category) { … }
}