#include "chrome/browser/page_load_metrics/observers/multi_tab_loading_page_load_metrics_observer.h"
#include "base/metrics/histogram_functions.h"
#include "build/build_config.h"
#include "chrome/browser/page_load_metrics/observers/histogram_suffixes.h"
#include "components/page_load_metrics/browser/page_load_metrics_util.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h"
#if BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/android/tab_model/tab_model.h"
#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
#else
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#endif
namespace {
void PageLoadHistogram(const std::string& name, base::TimeDelta sample) { … }
}
namespace internal {
const char kHistogramPrefixMultiTabLoading[] = …;
const char kHistogramPrefixMultiTabLoading1OrMore[] = …;
const char kHistogramPrefixMultiTabLoading2OrMore[] = …;
const char kHistogramPrefixMultiTabLoading5OrMore[] = …;
const char kHistogramPrefixMultiTabLoading0[] = …;
const char kHistogramPrefixMultiTabLoading1[] = …;
const char kHistogramPrefixMultiTabLoading2[] = …;
const char kHistogramPrefixMultiTabLoading3[] = …;
const char kHistogramPrefixMultiTabLoading4[] = …;
const char kHistogramPrefixMultiTabLoading5[] = …;
const char kHistogramPrefixMultiTab0[] = …;
const char kHistogramPrefixMultiTab1[] = …;
const char kHistogramPrefixMultiTab2[] = …;
const char kHistogramPrefixMultiTab4[] = …;
const char kHistogramPrefixMultiTab8[] = …;
const char kHistogramPrefixMultiTab16[] = …;
const char kHistogramPrefixMultiTab32[] = …;
const char kHistogramPrefixMultiTab64[] = …;
}
MultiTabLoadingPageLoadMetricsObserver::
MultiTabLoadingPageLoadMetricsObserver() = default;
MultiTabLoadingPageLoadMetricsObserver::
~MultiTabLoadingPageLoadMetricsObserver() = default;
page_load_metrics::PageLoadMetricsObserver::ObservePolicy
MultiTabLoadingPageLoadMetricsObserver::OnStart(
content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url,
bool started_in_foreground) { … }
page_load_metrics::PageLoadMetricsObserver::ObservePolicy
MultiTabLoadingPageLoadMetricsObserver::OnFencedFramesStart(
content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url) { … }
page_load_metrics::PageLoadMetricsObserver::ObservePolicy
MultiTabLoadingPageLoadMetricsObserver::OnPrerenderStart(
content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url) { … }
#define RECORD_HISTOGRAM(condition, name) …
void MultiTabLoadingPageLoadMetricsObserver::OnFirstContentfulPaintInPage(
const page_load_metrics::mojom::PageLoadTiming& timing) { … }
void MultiTabLoadingPageLoadMetricsObserver::
OnFirstMeaningfulPaintInMainFrameDocument(
const page_load_metrics::mojom::PageLoadTiming& timing) { … }
void MultiTabLoadingPageLoadMetricsObserver::OnDomContentLoadedEventStart(
const page_load_metrics::mojom::PageLoadTiming& timing) { … }
void MultiTabLoadingPageLoadMetricsObserver::OnLoadEventStart(
const page_load_metrics::mojom::PageLoadTiming& timing) { … }
void MultiTabLoadingPageLoadMetricsObserver::OnComplete(
const page_load_metrics::mojom::PageLoadTiming& timing) { … }
page_load_metrics::PageLoadMetricsObserver::ObservePolicy
MultiTabLoadingPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground(
const page_load_metrics::mojom::PageLoadTiming& timing) { … }
void MultiTabLoadingPageLoadMetricsObserver::RecordTimingHistograms() { … }
void MultiTabLoadingPageLoadMetricsObserver::RecordHistograms(
const char* suffix,
base::TimeDelta sample) { … }
#if BUILDFLAG(IS_ANDROID)
int MultiTabLoadingPageLoadMetricsObserver::NumberOfTabsWithInflightLoad(
content::NavigationHandle* navigation_handle) {
content::WebContents* this_contents = navigation_handle->GetWebContents();
int num_loading = 0;
for (const TabModel* model : TabModelList::models()) {
for (int i = 0; i < model->GetTabCount(); ++i) {
content::WebContents* other_contents = model->GetWebContentsAt(i);
if (other_contents && other_contents != this_contents &&
other_contents->IsLoading()) {
num_loading++;
}
}
}
return num_loading;
}
int MultiTabLoadingPageLoadMetricsObserver::NumberOfTabs(
content::NavigationHandle* navigation_handle) {
int num_of_tabs = 0;
for (const TabModel* model : TabModelList::models()) {
num_of_tabs += model->GetTabCount();
}
return num_of_tabs;
}
#else
int MultiTabLoadingPageLoadMetricsObserver::NumberOfTabsWithInflightLoad(
content::NavigationHandle* navigation_handle) { … }
int MultiTabLoadingPageLoadMetricsObserver::NumberOfTabs(
content::NavigationHandle* navigation_handle) { … }
#endif