environment_recorder.h 1.9 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_ENVIRONMENT_RECORDER_H_
  5. #define COMPONENTS_METRICS_ENVIRONMENT_RECORDER_H_
  6. #include <string>
  7. #include "base/memory/raw_ptr.h"
  8. class PrefService;
  9. class PrefRegistrySimple;
  10. namespace metrics {
  11. class SystemProfileProto;
  12. // Stores system profile information to prefs for creating stability logs
  13. // in the next launch of chrome, and reads data from previous launches.
  14. class EnvironmentRecorder {
  15. public:
  16. explicit EnvironmentRecorder(PrefService* local_state);
  17. EnvironmentRecorder(const EnvironmentRecorder&) = delete;
  18. EnvironmentRecorder& operator=(const EnvironmentRecorder&) = delete;
  19. ~EnvironmentRecorder();
  20. // Serializes the system profile and records it in prefs for the next
  21. // session. Returns the uncompressed serialized proto for passing to crash
  22. // reports, or the empty string if the proto can't be serialized.
  23. std::string SerializeAndRecordEnvironmentToPrefs(
  24. const SystemProfileProto& system_profile);
  25. // Loads the system_profile data stored in a previous chrome session, and
  26. // stores it in the |system_profile| object.
  27. // Returns true iff a system profile was successfully read.
  28. bool LoadEnvironmentFromPrefs(SystemProfileProto* system_profile);
  29. // Deletes system profile data from prefs.
  30. void ClearEnvironmentFromPrefs();
  31. // Stores the buildtime of the current binary and version in prefs.
  32. void SetBuildtimeAndVersion(int64_t buildtime, const std::string& version);
  33. // Gets the buildtime stored in prefs.
  34. int64_t GetLastBuildtime();
  35. // Gets the version stored in prefs.
  36. std::string GetLastVersion();
  37. static void RegisterPrefs(PrefRegistrySimple* registry);
  38. private:
  39. raw_ptr<PrefService> local_state_;
  40. };
  41. } // namespace metrics
  42. #endif // COMPONENTS_METRICS_ENVIRONMENT_RECORDER_H_