stability_metrics_provider.h 2.0 KB

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