chromium/components/page_load_metrics/browser/layout_shift_normalization.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/page_load_metrics/browser/layout_shift_normalization.h"

namespace page_load_metrics {
constexpr auto NEW_SHIFT_BUFFER_WINDOW_DURATION =;
constexpr auto MAX_SHIFT_BUFFER_SIZE =;

LayoutShiftNormalization::LayoutShiftNormalization() = default;
LayoutShiftNormalization::~LayoutShiftNormalization() = default;

void LayoutShiftNormalization::AddNewLayoutShifts(
    const std::vector<page_load_metrics::mojom::LayoutShiftPtr>& new_shifts,
    base::TimeTicks current_time,
    float cumulative_layout_shift_score) {}

void LayoutShiftNormalization::ClearAllLayoutShifts() {}

void LayoutShiftNormalization::UpdateSessionWindow(
    SessionWindow* session_window,
    base::TimeDelta gap,
    base::TimeDelta max_duration,
    std::vector<std::pair<base::TimeTicks, double>>::const_iterator begin,
    std::vector<std::pair<base::TimeTicks, double>>::const_iterator end,
    float& max_score) {}

// This function will update layout shift normalization results for sliding
// windows and session windows twice. The first update is processing stale
// layout shifts (current_time - layout_shift_time >= 5s) in
// recent_layout_shifts_. The second update is continuing the first update by
// processing remaining layout shifts in recent_layout_shifts_. Processing
// layout shifts in order is very important to our algorithm or we may
// miscalculate the number of windows or layout shift score for a window.
// We assume the browser process can receive any layout shift within 5 seconds,
// so there might be some non-stale layout shifts on the way and a newer layout
// shift can be received earlier than an old one. This is one reason why we
// update layout shift normalization twice. Another reason is we can't updating
// normalization on demand when we record UKM because of constant class objects.
// The first update is for updating the normalization for all stale layout shift
// we received. The second update is for all layout shifts we received so far in
// case we need to record UKM right away.
void LayoutShiftNormalization::UpdateWindowCLS(
    std::vector<std::pair<base::TimeTicks, double>>::const_iterator first,
    std::vector<std::pair<base::TimeTicks, double>>::const_iterator
        first_non_stale,
    std::vector<std::pair<base::TimeTicks, double>>::const_iterator last,
    float cumulative_layout_shift_score) {}
}  // namespace page_load_metrics