#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include "base/allocator/partition_alloc_support.h"
#include "base/command_line.h"
#include "base/cpu.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/sparse_histogram.h"
#include "base/power_monitor/power_monitor_buildflags.h"
#include "base/rand_util.h"
#include "base/strings/strcat.h"
#include "base/system/sys_info.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/time/time.h"
#include "base/trace_event/trace_log.h"
#include "base/version.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "build/config/compiler/compiler_buildflags.h"
#include "chrome/browser/about_flags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/buildflags.h"
#include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/enterprise/browser_management/management_service_factory.h"
#include "chrome/browser/google/google_brand.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/metrics/process_memory_metrics_emitter.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/performance_controls/performance_controls_metrics.h"
#include "chrome/common/chrome_switches.h"
#include "components/flags_ui/pref_service_flags_storage.h"
#include "components/metrics/android_metrics_helper.h"
#include "components/performance_manager/public/features.h"
#include "components/performance_manager/public/performance_manager.h"
#include "components/policy/core/common/management/management_service.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/variations/synthetic_trials.h"
#include "components/variations/variations_ids_provider.h"
#include "components/variations/variations_switches.h"
#include "components/version_info/version_info_values.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h"
#include "crypto/unexportable_key.h"
#include "crypto/unexportable_key_metrics.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/browser_metrics.h"
#include "ui/base/pointer/pointer_device.h"
#include "ui/base/ui_base_switches.h"
#include "ui/display/screen.h"
#if !BUILDFLAG(IS_ANDROID)
#include "base/power_monitor/battery_state_sampler.h"
#include "chrome/browser/metrics/first_web_contents_profiler.h"
#include "chrome/browser/metrics/power/battery_discharge_reporter.h"
#include "chrome/browser/metrics/power/power_metrics_reporter.h"
#include "chrome/browser/metrics/power/process_monitor.h"
#include "chrome/browser/metrics/tab_stats/tab_stats_tracker.h"
#endif
#if BUILDFLAG(IS_ANDROID)
#if defined(__arm__)
#include <cpu-features.h>
#endif
#include "base/android/build_info.h"
#include "chrome/browser/flags/android/chrome_session_state.h"
#endif
#if defined(__GLIBC__) && (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
#include <gnu/libc-version.h>
#include "base/linux_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#endif
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/win/registry.h"
#include "base/win/scoped_handle.h"
#include "base/win/windows_version.h"
#include "chrome/browser/metrics/key_credential_manager_support_reporter_win.h"
#include "chrome/browser/shell_integration_win.h"
#include "chrome/installer/util/taskbar_util.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/crosapi/cpp/crosapi_constants.h"
#endif
#if BUILDFLAG(IS_LINUX)
#include "chrome/browser/metrics/pressure/pressure_metrics_reporter.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/ash/components/browser_context_helper/browser_context_helper.h"
#include "components/user_manager/user_manager.h"
#endif
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "components/power_metrics/system_power_monitor.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "chrome/common/chrome_version.h"
#endif
namespace {
constexpr int kEnableBenchmarkingCountdownDefault = …;
constexpr char kEnableBenchmarkingPrefId[] = …;
#if BUILDFLAG(IS_MAC)
constexpr char kUnexportableKeysKeychainAccessGroup[] =
MAC_TEAM_IDENTIFIER_STRING "." MAC_BUNDLE_IDENTIFIER_STRING
".unexportable-keys";
#endif
void RecordMemoryMetrics();
base::TimeDelta GetDelayForNextMemoryLogTest() { … }
void RecordMemoryMetricsAfterDelay() { … }
void RecordMemoryMetrics() { … }
enum class UmaLinuxDistro { … };
enum UMALinuxGlibcVersion : uint32_t { … };
#if BUILDFLAG(IS_CHROMEOS_LACROS)
enum class ChromeOSChannel {
kUnknown = 0,
kCanary = 1,
kDev = 2,
kBeta = 3,
kStable = 4,
kMaxValue = kStable,
};
void RecordChromeOSChannel() {
ChromeOSChannel os_channel = ChromeOSChannel::kUnknown;
std::string release_track;
if (base::SysInfo::GetLsbReleaseValue(crosapi::kChromeOSReleaseTrack,
&release_track)) {
if (release_track == crosapi::kReleaseChannelStable)
os_channel = ChromeOSChannel::kStable;
else if (release_track == crosapi::kReleaseChannelBeta)
os_channel = ChromeOSChannel::kBeta;
else if (release_track == crosapi::kReleaseChannelDev)
os_channel = ChromeOSChannel::kDev;
else if (release_track == crosapi::kReleaseChannelCanary)
os_channel = ChromeOSChannel::kCanary;
}
base::UmaHistogramEnumeration("ChromeOS.Lacros.OSChannel", os_channel);
}
#endif
void RecordMicroArchitectureStats() { … }
#if BUILDFLAG(IS_LINUX)
void RecordLinuxDistroSpecific(const std::string& version_string,
size_t parts,
const char* histogram_name) { … }
std::string TrimLinuxDistro(const std::string& distro) { … }
void RecordLinuxDistro() { … }
#endif
void RecordLinuxGlibcVersion() { … }
#if BUILDFLAG(IS_WIN)
void OnIsPinnedToTaskbarResult(bool succeeded, bool is_pinned_to_taskbar) {
enum Result { NOT_PINNED = 0, PINNED = 1, FAILURE = 2, NUM_RESULTS };
Result result = FAILURE;
if (succeeded)
result = is_pinned_to_taskbar ? PINNED : NOT_PINNED;
base::UmaHistogramEnumeration("Windows.IsPinnedToTaskbar", result,
NUM_RESULTS);
if (GetInstallerPinnedChromeToTaskbar().value_or(false)) {
if (result == NOT_PINNED)
SetInstallerPinnedChromeToTaskbar(false);
if (result != FAILURE) {
base::UmaHistogramBoolean("Windows.InstallerPinUnpinned",
result == NOT_PINNED);
}
}
}
void RecordIsPinnedToTaskbarHistogram() {
shell_integration::win::GetIsPinnedToTaskbarState(
base::BindOnce(&OnIsPinnedToTaskbarResult));
}
bool IsParallelDllLoadingEnabled() {
base::FilePath exe_path;
if (!base::PathService::Get(base::FILE_EXE, &exe_path))
return false;
const wchar_t kIFEOKey[] =
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution "
L"Options\\";
std::wstring browser_process_key = kIFEOKey + exe_path.BaseName().value();
base::win::RegKey key;
if (ERROR_SUCCESS != key.Open(HKEY_LOCAL_MACHINE, browser_process_key.c_str(),
KEY_QUERY_VALUE))
return true;
const wchar_t kMaxLoaderThreads[] = L"MaxLoaderThreads";
DWORD max_loader_threads = 0;
if (ERROR_SUCCESS != key.ReadValueDW(kMaxLoaderThreads, &max_loader_threads))
return true;
return max_loader_threads != 1;
}
void RecordAppCompatMetrics() {
HMODULE mod = ::GetModuleHandleW(L"AcLayers.dll");
base::UmaHistogramBoolean("Windows.AcLayersLoaded", !!mod);
}
#endif
void RecordDisplayHDRStatus(const display::Display& display) { … }
void RecordStartupMetrics() { … }
}
#if BUILDFLAG(IS_ANDROID)
bool IsBundleForMixedDeviceAccordingToVersionCode(
const std::string& version_code) {
if (version_code.length() < 2) {
return false;
}
std::set<char> arch_codes_mixed = {'1', '2', '3', '7', '8'};
char arch_code = version_code.back();
constexpr char kTriChromeVariant = '3';
char variant = version_code[version_code.length() - 2];
return arch_codes_mixed.count(arch_code) > 0 && variant == kTriChromeVariant;
}
#endif
ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics()
: … { … }
ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() =
default;
void ChromeBrowserMainExtraPartsMetrics::PreCreateThreads() { … }
void ChromeBrowserMainExtraPartsMetrics::PostCreateMainMessageLoop() { … }
void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() { … }
void ChromeBrowserMainExtraPartsMetrics::PreBrowserStart() { … }
void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() { … }
void ChromeBrowserMainExtraPartsMetrics::PreMainMessageLoopRun() { … }
void ChromeBrowserMainExtraPartsMetrics::PostDestroyThreads() { … }
void ChromeBrowserMainExtraPartsMetrics::RegisterPrefs(
PrefRegistrySimple* registry) { … }
void ChromeBrowserMainExtraPartsMetrics::HandleEnableBenchmarkingCountdown(
PrefService* pref_service,
std::unique_ptr<flags_ui::FlagsStorage> storage,
flags_ui::FlagAccess access) { … }
void ChromeBrowserMainExtraPartsMetrics::
HandleEnableBenchmarkingCountdownAsync() { … }
void ChromeBrowserMainExtraPartsMetrics::OnDisplayAdded(
const display::Display& new_display) { … }
void ChromeBrowserMainExtraPartsMetrics::OnDisplaysRemoved(
const display::Displays& removed_displays) { … }
void ChromeBrowserMainExtraPartsMetrics::OnDisplayMetricsChanged(
const display::Display& display,
uint32_t changed_metrics) { … }
void ChromeBrowserMainExtraPartsMetrics::EmitDisplaysChangedMetric() { … }
namespace chrome {
void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts) { … }
}