• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ENVIRONMENT_RECORDER_H_
6 #define COMPONENTS_METRICS_ENVIRONMENT_RECORDER_H_
7 
8 #include <string>
9 
10 #include "base/memory/raw_ptr.h"
11 
12 class PrefService;
13 class PrefRegistrySimple;
14 
15 namespace metrics {
16 
17 class SystemProfileProto;
18 
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 {
22  public:
23   explicit EnvironmentRecorder(PrefService* local_state);
24 
25   EnvironmentRecorder(const EnvironmentRecorder&) = delete;
26   EnvironmentRecorder& operator=(const EnvironmentRecorder&) = delete;
27 
28   ~EnvironmentRecorder();
29 
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);
35 
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);
40 
41   // Deletes system profile data from prefs.
42   void ClearEnvironmentFromPrefs();
43 
44   // Stores the buildtime of the current binary and version in prefs.
45   void SetBuildtimeAndVersion(int64_t buildtime, const std::string& version);
46 
47   // Gets the buildtime stored in prefs.
48   int64_t GetLastBuildtime();
49 
50   // Gets the version stored in prefs.
51   std::string GetLastVersion();
52 
53   static void RegisterPrefs(PrefRegistrySimple* registry);
54 
55  private:
56   raw_ptr<PrefService> local_state_;
57 };
58 
59 }  // namespace metrics
60 
61 #endif  // COMPONENTS_METRICS_ENVIRONMENT_RECORDER_H_
62