#ifndef CONTENT_BROWSER_PRELOADING_PRELOAD_SERVING_METRICS_H_
#define CONTENT_BROWSER_PRELOADING_PRELOAD_SERVING_METRICS_H_
#include <memory>
#include <optional>
#include <vector>
#include "base/time/time.h"
#include "content/browser/preloading/prefetch/prefetch_servable_state.h"
#include "content/browser/preloading/prefetch/prefetch_streaming_url_loader_common_types.h"
#include "content/common/content_export.h"
#include "content/public/browser/preload_serving_metrics_capsule.h"
namespace content {
enum class PrefetchPotentialCandidateServingResult;
class NavigationHandle;
class PrefetchContainer;
enum class PrefetchStatus;
struct CONTENT_EXPORT PrefetchContainerMetrics final {
PrefetchContainerMetrics();
~PrefetchContainerMetrics();
PrefetchContainerMetrics(PrefetchContainerMetrics&& other) = delete;
PrefetchContainerMetrics& operator=(PrefetchContainerMetrics&& other) =
delete;
PrefetchContainerMetrics(const PrefetchContainerMetrics&);
PrefetchContainerMetrics& operator=(const PrefetchContainerMetrics&);
std::optional<base::TimeTicks> time_added_to_prefetch_service;
std::optional<base::TimeTicks> time_initial_eligibility_got;
std::optional<base::TimeTicks> time_prefetch_started;
std::optional<base::TimeTicks> time_url_request_started;
std::optional<base::TimeTicks> time_domain_lookup_started;
std::optional<base::TimeTicks> time_header_determined_successfully;
std::optional<base::TimeTicks> time_prefetch_completed_successfully;
std::optional<base::TimeDelta> create_stream_delay;
std::optional<base::TimeDelta> connected_callback_delay;
std::optional<base::TimeDelta> initialize_stream_delay;
};
struct CONTENT_EXPORT PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics final {
PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics();
~PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics();
PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics(
PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics&& other) = delete;
PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics& operator=(
PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics&& other) = delete;
PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics(
const PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics&) = delete;
PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics& operator=(
const PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics&) = delete;
PrefetchStatus prefetch_status;
PrefetchServableState servable_state;
PrefetchMatchResolverAction match_resolver_action;
int queue_size;
std::optional<int> queue_index;
};
struct CONTENT_EXPORT PrefetchMatchPrerenderDebugMetrics final {
PrefetchMatchPrerenderDebugMetrics();
~PrefetchMatchPrerenderDebugMetrics();
PrefetchMatchPrerenderDebugMetrics(
PrefetchMatchPrerenderDebugMetrics&& other) = delete;
PrefetchMatchPrerenderDebugMetrics& operator=(
PrefetchMatchPrerenderDebugMetrics&& other) = delete;
PrefetchMatchPrerenderDebugMetrics(
const PrefetchMatchPrerenderDebugMetrics&) = delete;
PrefetchMatchPrerenderDebugMetrics& operator=(
const PrefetchMatchPrerenderDebugMetrics&) = delete;
std::unique_ptr<PrefetchMatchPrefetchAheadOfPrerenderDebugMetrics>
prefetch_ahead_of_prerender_debug_metrics;
};
struct CONTENT_EXPORT PrefetchMatchMetrics final {
PrefetchMatchMetrics();
~PrefetchMatchMetrics();
PrefetchMatchMetrics(PrefetchMatchMetrics&& other) = delete;
PrefetchMatchMetrics& operator=(PrefetchMatchMetrics&& other) = delete;
PrefetchMatchMetrics(const PrefetchMatchMetrics&) = delete;
PrefetchMatchMetrics& operator=(const PrefetchMatchMetrics&) = delete;
bool IsPotentialMatch() const;
bool IsActualMatch() const;
PrefetchPotentialCandidateServingResult
GetPrefetchPotentialCandidateServingResultLast() const;
PrefetchServiceWorkerState expected_service_worker_state;
base::TimeTicks time_match_start;
base::TimeTicks time_match_end;
int n_initial_candidates = -1;
int n_initial_candidates_block_until_head = -1;
std::unique_ptr<PrefetchContainerMetrics> prefetch_container_metrics =
nullptr;
std::optional<PrefetchPotentialCandidateServingResult>
prefetch_potential_candidate_serving_result_last = std::nullopt;
std::optional<PrefetchPotentialCandidateServingResult>
prefetch_potential_candidate_serving_result_ahead_of_prerender =
std::nullopt;
std::unique_ptr<PrefetchContainerMetrics>
prefetch_container_metrics_ahead_of_prerender = nullptr;
std::unique_ptr<PrefetchMatchPrerenderDebugMetrics> prerender_debug_metrics;
};
struct CONTENT_EXPORT PreloadServingMetrics final {
PreloadServingMetrics();
~PreloadServingMetrics();
PreloadServingMetrics(PreloadServingMetrics&& other) = delete;
PreloadServingMetrics& operator=(PreloadServingMetrics&& other) = delete;
PreloadServingMetrics(const PreloadServingMetrics&) = delete;
PreloadServingMetrics& operator=(const PreloadServingMetrics&) = delete;
const PrefetchMatchMetrics* GetMeaningfulPrefetchMatchMetrics() const;
void RecordMetricsForNonPrerenderNavigationCommitted() const;
void RecordMetricsForPrerenderInitialNavigationFailed() const;
void RecordFirstContentfulPaint(
base::TimeDelta corrected_first_contentful_paint) const;
std::vector<std::unique_ptr<PrefetchMatchMetrics>>
prefetch_match_metrics_list;
std::unique_ptr<PreloadServingMetrics>
prerender_initial_preload_serving_metrics = nullptr;
bool is_prerender_aborted_by_prerender_url_loader_throttle = false;
};
class CONTENT_EXPORT PreloadServingMetricsCapsuleImpl final
: public PreloadServingMetricsCapsule {
public:
static std::unique_ptr<PreloadServingMetricsCapsule> TakeFromNavigationHandle(
NavigationHandle& navigation_handle);
void RecordMetricsForNonPrerenderNavigationCommitted() const override;
void RecordFirstContentfulPaint(
base::TimeDelta corrected_first_contentful_paint) const override;
private:
explicit PreloadServingMetricsCapsuleImpl(
std::unique_ptr<PreloadServingMetrics> preload_serving_metrics);
~PreloadServingMetricsCapsuleImpl() override;
friend struct std::default_delete<PreloadServingMetricsCapsuleImpl>;
std::unique_ptr<PreloadServingMetrics> preload_serving_metrics_ = nullptr;
};
}
#endif