1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_FOREGROUND_DURATION_UKM_OBSERVER_H_
#define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_FOREGROUND_DURATION_UKM_OBSERVER_H_
#include "base/time/time.h"
#include "components/page_load_metrics/browser/page_load_metrics_observer.h"
#include "components/page_load_metrics/common/page_load_metrics.mojom.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
// Observer responsible for appending previews information to the PLM UKM
// report.
class ForegroundDurationUKMObserver
: public page_load_metrics::PageLoadMetricsObserver {
public:
ForegroundDurationUKMObserver();
ForegroundDurationUKMObserver(const ForegroundDurationUKMObserver&) = delete;
ForegroundDurationUKMObserver& operator=(
const ForegroundDurationUKMObserver&) = delete;
~ForegroundDurationUKMObserver() override;
// page_load_metrics::PageLoadMetricsObserver:
ObservePolicy OnStart(content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url,
bool started_in_foreground) override;
ObservePolicy OnFencedFramesStart(
content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url) override;
ObservePolicy OnPrerenderStart(content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url) override;
ObservePolicy FlushMetricsOnAppEnterBackground(
const page_load_metrics::mojom::PageLoadTiming& timing) override;
ObservePolicy OnHidden(
const page_load_metrics::mojom::PageLoadTiming& timing) override;
ObservePolicy OnShown() override;
void OnComplete(
const page_load_metrics::mojom::PageLoadTiming& timing) override;
void DidActivatePrerenderedPage(
content::NavigationHandle* navigation_handle) override;
private:
// True when the visibility of WebContents is Visibility::VISIBLE (not
// OCCLUDED or HIDDEN).
bool currently_in_foreground_ = false;
base::TimeTicks last_time_shown_;
page_load_metrics::mojom::InputTimingPtr last_page_input_timing_;
void RecordUkmIfInForeground(base::TimeTicks end_time);
};
#endif // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_FOREGROUND_DURATION_UKM_OBSERVER_H_
|