#include "components/metrics/stability_metrics_provider.h"
#include <string>
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/stability_metrics_helper.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "third_party/metrics_proto/system_profile.pb.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "components/metrics/system_session_analyzer/system_session_analyzer_win.h"
#endif
namespace metrics {
namespace {
#if BUILDFLAG(IS_ANDROID)
bool HasGmsCoreVersionChanged(PrefService* local_state) {
std::string previous_version =
local_state->GetString(prefs::kStabilityGmsCoreVersion);
std::string current_version =
base::android::BuildInfo::GetInstance()->gms_version_code();
if (previous_version.empty())
return false;
return previous_version != current_version;
}
void UpdateGmsCoreVersionPref(PrefService* local_state) {
std::string current_version =
base::android::BuildInfo::GetInstance()->gms_version_code();
local_state->SetString(prefs::kStabilityGmsCoreVersion, current_version);
}
#endif
}
StabilityMetricsProvider::StabilityMetricsProvider(PrefService* local_state)
: … { … }
StabilityMetricsProvider::~StabilityMetricsProvider() = default;
void StabilityMetricsProvider::RegisterPrefs(PrefRegistrySimple* registry) { … }
void StabilityMetricsProvider::Init() { … }
void StabilityMetricsProvider::ClearSavedStabilityMetrics() { … }
void StabilityMetricsProvider::ProvideStabilityMetrics(
SystemProfileProto* system_profile) { … }
void StabilityMetricsProvider::LogCrash(base::Time last_live_timestamp) { … }
void StabilityMetricsProvider::LogLaunch() { … }
#if BUILDFLAG(IS_WIN)
bool StabilityMetricsProvider::IsUncleanSystemSession(
base::Time last_live_timestamp) {
DCHECK_NE(base::Time(), last_live_timestamp);
SystemSessionAnalyzer analyzer(3);
SystemSessionAnalyzer::Status status =
analyzer.IsSessionUnclean(last_live_timestamp);
return status == SystemSessionAnalyzer::UNCLEAN;
}
void StabilityMetricsProvider::MaybeLogSystemCrash(
base::Time last_live_timestamp) {
if (last_live_timestamp != base::Time() &&
IsUncleanSystemSession(last_live_timestamp)) {
IncrementPrefValue(prefs::kStabilitySystemCrashCount);
}
}
#endif
void StabilityMetricsProvider::IncrementPrefValue(const char* path) { … }
int StabilityMetricsProvider::GetAndClearPrefValue(const char* path,
int* value) { … }
}