#include "components/metrics/stability_metrics_helper.h"
#include <stdint.h>
#include <string>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/system/sys_info.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/variations/hashing.h"
#include "extensions/buildflags/buildflags.h"
#include "third_party/metrics_proto/system_profile.pb.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#endif
#if BUILDFLAG(IS_ANDROID)
#include "base/android/application_status_listener.h"
#endif
namespace metrics {
namespace {
#if !BUILDFLAG(IS_ANDROID)
int MapCrashExitCodeForHistogram(int exit_code) { … }
#endif
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
const char* HostedContentTypeToString(
RendererHostedContentType hosted_content_type) { … }
void RecordRendererAbnormalTerminationByHostedContentType(
RendererHostedContentType hosted_content_type,
base::TerminationStatus status) { … }
#endif
}
StabilityMetricsHelper::StabilityMetricsHelper(PrefService* local_state)
: … { … }
StabilityMetricsHelper::~StabilityMetricsHelper() { … }
#if BUILDFLAG(IS_ANDROID)
void StabilityMetricsHelper::ProvideStabilityMetrics(
SystemProfileProto* system_profile_proto) {
SystemProfileProto_Stability* stability_proto =
system_profile_proto->mutable_stability();
int count = local_state_->GetInteger(prefs::kStabilityPageLoadCount);
if (count) {
stability_proto->set_page_load_count(count);
local_state_->SetInteger(prefs::kStabilityPageLoadCount, 0);
}
count = local_state_->GetInteger(prefs::kStabilityRendererLaunchCount);
if (count) {
stability_proto->set_renderer_launch_count(count);
local_state_->SetInteger(prefs::kStabilityRendererLaunchCount, 0);
}
}
void StabilityMetricsHelper::ClearSavedStabilityMetrics() {
local_state_->SetInteger(prefs::kStabilityPageLoadCount, 0);
local_state_->SetInteger(prefs::kStabilityRendererLaunchCount, 0);
}
#endif
void StabilityMetricsHelper::RegisterPrefs(PrefRegistrySimple* registry) { … }
void StabilityMetricsHelper::IncreaseRendererCrashCount() { … }
void StabilityMetricsHelper::IncreaseGpuCrashCount() { … }
void StabilityMetricsHelper::BrowserUtilityProcessLaunched(
const std::string& metrics_name) { … }
void StabilityMetricsHelper::BrowserUtilityProcessCrashed(
const std::string& metrics_name,
int exit_code) { … }
void StabilityMetricsHelper::BrowserUtilityProcessLaunchFailed(
const std::string& metrics_name,
int launch_error_code
#if BUILDFLAG(IS_WIN)
,
DWORD last_error
#endif
) { … }
void StabilityMetricsHelper::LogLoadStarted() { … }
#if BUILDFLAG(IS_IOS)
void StabilityMetricsHelper::LogRendererCrash() {
constexpr int kDummyExitCode = 105;
LogRendererCrashImpl(CoarseRendererType::kRenderer, kDummyExitCode);
}
#elif !BUILDFLAG(IS_ANDROID)
void StabilityMetricsHelper::LogRendererCrash(
RendererHostedContentType hosted_content_type,
base::TerminationStatus status,
int exit_code) { … }
#endif
void StabilityMetricsHelper::LogRendererLaunched(bool was_extension_process) { … }
void StabilityMetricsHelper::IncrementPrefValue(const char* path) { … }
void StabilityMetricsHelper::RecordStabilityEvent(
StabilityEventType stability_event_type) { … }
#if !BUILDFLAG(IS_ANDROID)
void StabilityMetricsHelper::LogRendererCrashImpl(
CoarseRendererType renderer_type,
int exit_code) { … }
#endif
}