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