1 // Copyright 2017 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_METRICS_STABILITY_METRICS_PROVIDER_H_ 6 #define COMPONENTS_METRICS_STABILITY_METRICS_PROVIDER_H_ 7 8 #include "base/memory/raw_ptr.h" 9 #include "base/time/time.h" 10 #include "build/build_config.h" 11 #include "components/metrics/metrics_provider.h" 12 13 class PrefService; 14 class PrefRegistrySimple; 15 16 namespace metrics { 17 18 class SystemProfileProto; 19 20 // Stores and loads system information to prefs for stability logs. 21 class StabilityMetricsProvider : public MetricsProvider { 22 public: 23 explicit StabilityMetricsProvider(PrefService* local_state); 24 25 StabilityMetricsProvider(const StabilityMetricsProvider&) = delete; 26 StabilityMetricsProvider& operator=(const StabilityMetricsProvider&) = delete; 27 28 ~StabilityMetricsProvider() override; 29 30 static void RegisterPrefs(PrefRegistrySimple* registry); 31 32 void LogCrash(base::Time last_live_timestamp); 33 void LogLaunch(); 34 35 private: 36 #if BUILDFLAG(IS_WIN) 37 // This function is virtual for testing. The |last_live_timestamp| is a 38 // time point where the previous browser was known to be alive, and is used 39 // to determine whether the system session embedding that timestamp terminated 40 // uncleanly. 41 virtual bool IsUncleanSystemSession(base::Time last_live_timestamp); 42 void MaybeLogSystemCrash(base::Time last_live_timestamp); 43 #endif 44 // Increments an Integer pref value specified by |path|. 45 void IncrementPrefValue(const char* path); 46 47 // Gets pref value specified by |path| and resets it to 0 after retrieving. 48 int GetAndClearPrefValue(const char* path, int* value); 49 50 // MetricsProvider: 51 void Init() override; 52 void ClearSavedStabilityMetrics() override; 53 void ProvideStabilityMetrics( 54 SystemProfileProto* system_profile_proto) override; 55 56 raw_ptr<PrefService> local_state_; 57 }; 58 59 } // namespace metrics 60 61 #endif // COMPONENTS_METRICS_STABILITY_METRICS_PROVIDER_H_ 62