#include "chrome/browser/metrics/tab_stats/tab_stats_tracker.h"
#include <algorithm>
#include <string>
#include <utility>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/observer_list.h"
#include "base/power_monitor/power_monitor.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/resource_coordinator/lifecycle_unit.h"
#include "chrome/browser/resource_coordinator/lifecycle_unit_observer.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/resource_coordinator/tab_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_group.h"
#include "chrome/browser/ui/tabs/tab_group_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/daily_event.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/visibility.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
#include "chrome/browser/background/background_mode_manager.h"
#endif
namespace metrics {
namespace {
constexpr base::TimeDelta kDailyEventIntervalTimeDelta = …;
const base::TimeDelta kTabsHeartbeatReportingInterval = …;
TabStatsTracker* g_tab_stats_tracker_instance = …;
void UmaHistogramCounts10000WithBatteryStateVariant(const char* histogram_name,
size_t value) { … }
}
const char TabStatsTracker::UmaStatsReportingDelegate::
kNumberOfTabsOnResumeHistogramName[] = …;
const char
TabStatsTracker::UmaStatsReportingDelegate::kMaxTabsInADayHistogramName[] = …;
const char TabStatsTracker::UmaStatsReportingDelegate::
kMaxTabsPerWindowInADayHistogramName[] = …;
const char TabStatsTracker::UmaStatsReportingDelegate::
kMaxWindowsInADayHistogramName[] = …;
const char
TabStatsTracker::UmaStatsReportingDelegate::kTabCountHistogramName[] = …;
const char
TabStatsTracker::UmaStatsReportingDelegate::kWindowCountHistogramName[] = …;
const char
TabStatsTracker::UmaStatsReportingDelegate::kWindowWidthHistogramName[] = …;
const char TabStatsTracker::UmaStatsReportingDelegate::
kDailyDiscardsExternalHistogramName[] = …;
const char TabStatsTracker::UmaStatsReportingDelegate::
kDailyDiscardsUrgentHistogramName[] = …;
const char TabStatsTracker::UmaStatsReportingDelegate::
kDailyDiscardsProactiveHistogramName[] = …;
const char TabStatsTracker::UmaStatsReportingDelegate::
kDailyDiscardsSuggestedHistogramName[] = …;
const char TabStatsTracker::UmaStatsReportingDelegate::
kDailyReloadsExternalHistogramName[] = …;
const char TabStatsTracker::UmaStatsReportingDelegate::
kDailyReloadsUrgentHistogramName[] = …;
const char TabStatsTracker::UmaStatsReportingDelegate::
kDailyReloadsProactiveHistogramName[] = …;
const char TabStatsTracker::UmaStatsReportingDelegate::
kDailyReloadsSuggestedHistogramName[] = …;
const TabStatsDataStore::TabsStats& TabStatsTracker::tab_stats() const { … }
TabStatsTracker::TabStatsTracker(PrefService* pref_service)
: … { … }
TabStatsTracker::~TabStatsTracker() { … }
void TabStatsTracker::SetInstance(std::unique_ptr<TabStatsTracker> instance) { … }
void TabStatsTracker::ClearInstance() { … }
TabStatsTracker* TabStatsTracker::GetInstance() { … }
bool TabStatsTracker::HasInstance() { … }
void TabStatsTracker::AddObserverAndSetInitialState(
TabStatsObserver* observer) { … }
void TabStatsTracker::RegisterPrefs(PrefRegistrySimple* registry) { … }
void TabStatsTracker::TabStatsDailyObserver::OnDailyEvent(
DailyEvent::IntervalType type) { … }
class TabStatsTracker::WebContentsUsageObserver
: public content::WebContentsObserver { … };
void TabStatsTracker::OnBrowserAdded(Browser* browser) { … }
void TabStatsTracker::OnBrowserRemoved(Browser* browser) { … }
void TabStatsTracker::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) { … }
void TabStatsTracker::OnResume() { … }
void TabStatsTracker::OnDiscardedStateChange(
content::WebContents* contents,
::mojom::LifecycleUnitDiscardReason reason,
bool is_discarded) { … }
void TabStatsTracker::OnAutoDiscardableStateChange(
content::WebContents* contents,
bool is_auto_discardable) { … }
void TabStatsTracker::OnInitialOrInsertedTab(
content::WebContents* web_contents) { … }
void TabStatsTracker::OnWebContentsDestroyed(
content::WebContents* web_contents) { … }
void TabStatsTracker::OnHeartbeatEvent() { … }
void TabStatsTracker::UmaStatsReportingDelegate::ReportTabCountOnResume(
size_t tab_count) { … }
void TabStatsTracker::UmaStatsReportingDelegate::ReportDailyMetrics(
const TabStatsDataStore::TabsStats& tab_stats) { … }
void TabStatsTracker::UmaStatsReportingDelegate::ReportHeartbeatMetrics(
const TabStatsDataStore::TabsStats& tab_stats) { … }
bool TabStatsTracker::UmaStatsReportingDelegate::
IsChromeBackgroundedWithoutWindows() { … }
}