OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file defines a set of user experience metrics data recorded by | 5 // This file defines a set of user experience metrics data recorded by |
6 // the MetricsService. This is the unit of data that is sent to the server. | 6 // the MetricsService. This is the unit of data that is sent to the server. |
7 | 7 |
8 #ifndef COMPONENTS_METRICS_METRICS_LOG_H_ | 8 #ifndef COMPONENTS_METRICS_METRICS_LOG_H_ |
9 #define COMPONENTS_METRICS_METRICS_LOG_H_ | 9 #define COMPONENTS_METRICS_METRICS_LOG_H_ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" | 16 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" |
17 | 17 |
18 class PrefRegistrySimple; | 18 class PrefRegistrySimple; |
19 class PrefService; | 19 class PrefService; |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 class DictionaryValue; | 22 class DictionaryValue; |
23 class HistogramSamples; | 23 class HistogramSamples; |
24 } | 24 } |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 struct WebPluginInfo; | 27 struct WebPluginInfo; |
28 } | 28 } |
29 | 29 |
30 namespace metrics { | |
31 class MetricsProvider; | |
32 class MetricsServiceClient; | |
33 } | |
34 | |
35 namespace tracked_objects { | 30 namespace tracked_objects { |
36 struct ProcessDataSnapshot; | 31 struct ProcessDataSnapshot; |
37 } | 32 } |
38 | 33 |
39 namespace variations { | 34 namespace variations { |
40 struct ActiveGroupId; | 35 struct ActiveGroupId; |
41 } | 36 } |
42 | 37 |
| 38 namespace metrics { |
| 39 |
| 40 class MetricsProvider; |
| 41 class MetricsServiceClient; |
| 42 |
43 class MetricsLog { | 43 class MetricsLog { |
44 public: | 44 public: |
45 enum LogType { | 45 enum LogType { |
46 INITIAL_STABILITY_LOG, // The initial log containing stability stats. | 46 INITIAL_STABILITY_LOG, // The initial log containing stability stats. |
47 ONGOING_LOG, // Subsequent logs in a session. | 47 ONGOING_LOG, // Subsequent logs in a session. |
48 }; | 48 }; |
49 | 49 |
50 // Creates a new metrics log of the specified type. | 50 // Creates a new metrics log of the specified type. |
51 // |client_id| is the identifier for this profile on this installation | 51 // |client_id| is the identifier for this profile on this installation |
52 // |session_id| is an integer that's incremented on each application launch | 52 // |session_id| is an integer that's incremented on each application launch |
53 // |client| is used to interact with the embedder. | 53 // |client| is used to interact with the embedder. |
54 // |local_state| is the PrefService that this instance should use. | 54 // |local_state| is the PrefService that this instance should use. |
55 // Note: |this| instance does not take ownership of the |client|, but rather | 55 // Note: |this| instance does not take ownership of the |client|, but rather |
56 // stores a weak pointer to it. The caller should ensure that the |client| is | 56 // stores a weak pointer to it. The caller should ensure that the |client| is |
57 // valid for the lifetime of this class. | 57 // valid for the lifetime of this class. |
58 MetricsLog(const std::string& client_id, | 58 MetricsLog(const std::string& client_id, |
59 int session_id, | 59 int session_id, |
60 LogType log_type, | 60 LogType log_type, |
61 metrics::MetricsServiceClient* client, | 61 MetricsServiceClient* client, |
62 PrefService* local_state); | 62 PrefService* local_state); |
63 virtual ~MetricsLog(); | 63 virtual ~MetricsLog(); |
64 | 64 |
65 // Registers local state prefs used by this class. | 65 // Registers local state prefs used by this class. |
66 static void RegisterPrefs(PrefRegistrySimple* registry); | 66 static void RegisterPrefs(PrefRegistrySimple* registry); |
67 | 67 |
68 // Computes the MD5 hash of the given string, and returns the first 8 bytes of | 68 // Computes the MD5 hash of the given string, and returns the first 8 bytes of |
69 // the hash. | 69 // the hash. |
70 static uint64 Hash(const std::string& value); | 70 static uint64 Hash(const std::string& value); |
71 | 71 |
(...skipping 16 matching lines...) Expand all Loading... |
88 const base::HistogramSamples& snapshot); | 88 const base::HistogramSamples& snapshot); |
89 | 89 |
90 // Records the current operating environment, including metrics provided by | 90 // Records the current operating environment, including metrics provided by |
91 // the specified set of |metrics_providers|. Takes the list of installed | 91 // the specified set of |metrics_providers|. Takes the list of installed |
92 // plugins, Google Update statistics, and synthetic trial IDs as parameters | 92 // plugins, Google Update statistics, and synthetic trial IDs as parameters |
93 // because those can't be obtained synchronously from the UI thread. | 93 // because those can't be obtained synchronously from the UI thread. |
94 // A synthetic trial is one that is set up dynamically by code in Chrome. For | 94 // A synthetic trial is one that is set up dynamically by code in Chrome. For |
95 // example, a pref may be mapped to a synthetic trial such that the group | 95 // example, a pref may be mapped to a synthetic trial such that the group |
96 // is determined by the pref value. | 96 // is determined by the pref value. |
97 void RecordEnvironment( | 97 void RecordEnvironment( |
98 const std::vector<metrics::MetricsProvider*>& metrics_providers, | 98 const std::vector<MetricsProvider*>& metrics_providers, |
99 const std::vector<variations::ActiveGroupId>& synthetic_trials, | 99 const std::vector<variations::ActiveGroupId>& synthetic_trials, |
100 int64 install_date); | 100 int64 install_date); |
101 | 101 |
102 // Loads the environment proto that was saved by the last RecordEnvironment() | 102 // Loads the environment proto that was saved by the last RecordEnvironment() |
103 // call from prefs and clears the pref value. Returns true on success or false | 103 // call from prefs and clears the pref value. Returns true on success or false |
104 // if there was no saved environment in prefs or it could not be decoded. | 104 // if there was no saved environment in prefs or it could not be decoded. |
105 bool LoadSavedEnvironmentFromPrefs(); | 105 bool LoadSavedEnvironmentFromPrefs(); |
106 | 106 |
107 // Writes application stability metrics, including stability metrics provided | 107 // Writes application stability metrics, including stability metrics provided |
108 // by the specified set of |metrics_providers|. The system profile portion of | 108 // by the specified set of |metrics_providers|. The system profile portion of |
109 // the log must have already been filled in by a call to RecordEnvironment() | 109 // the log must have already been filled in by a call to RecordEnvironment() |
110 // or LoadSavedEnvironmentFromPrefs(). | 110 // or LoadSavedEnvironmentFromPrefs(). |
111 // NOTE: Has the side-effect of clearing the stability prefs.. | 111 // NOTE: Has the side-effect of clearing the stability prefs.. |
112 // | 112 // |
113 // If this log is of type INITIAL_STABILITY_LOG, records additional info such | 113 // If this log is of type INITIAL_STABILITY_LOG, records additional info such |
114 // as number of incomplete shutdowns as well as extra breakpad and debugger | 114 // as number of incomplete shutdowns as well as extra breakpad and debugger |
115 // stats. | 115 // stats. |
116 void RecordStabilityMetrics( | 116 void RecordStabilityMetrics( |
117 const std::vector<metrics::MetricsProvider*>& metrics_providers, | 117 const std::vector<MetricsProvider*>& metrics_providers, |
118 base::TimeDelta incremental_uptime, | 118 base::TimeDelta incremental_uptime, |
119 base::TimeDelta uptime); | 119 base::TimeDelta uptime); |
120 | 120 |
121 // Records general metrics based on the specified |metrics_providers|. | 121 // Records general metrics based on the specified |metrics_providers|. |
122 void RecordGeneralMetrics( | 122 void RecordGeneralMetrics( |
123 const std::vector<metrics::MetricsProvider*>& metrics_providers); | 123 const std::vector<MetricsProvider*>& metrics_providers); |
124 | 124 |
125 // Stop writing to this record and generate the encoded representation. | 125 // Stop writing to this record and generate the encoded representation. |
126 // None of the Record* methods can be called after this is called. | 126 // None of the Record* methods can be called after this is called. |
127 void CloseLog(); | 127 void CloseLog(); |
128 | 128 |
129 // Fills |encoded_log| with the serialized protobuf representation of the | 129 // Fills |encoded_log| with the serialized protobuf representation of the |
130 // record. Must only be called after CloseLog() has been called. | 130 // record. Must only be called after CloseLog() has been called. |
131 void GetEncodedLog(std::string* encoded_log); | 131 void GetEncodedLog(std::string* encoded_log); |
132 | 132 |
133 const base::TimeTicks& creation_time() const { | 133 const base::TimeTicks& creation_time() const { |
134 return creation_time_; | 134 return creation_time_; |
135 } | 135 } |
136 | 136 |
137 int num_events() const { | 137 int num_events() const { |
138 return uma_proto_.omnibox_event_size() + | 138 return uma_proto_.omnibox_event_size() + |
139 uma_proto_.user_action_event_size(); | 139 uma_proto_.user_action_event_size(); |
140 } | 140 } |
141 | 141 |
142 LogType log_type() const { return log_type_; } | 142 LogType log_type() const { return log_type_; } |
143 | 143 |
144 protected: | 144 protected: |
145 // Exposed for the sake of mocking/accessing in test code. | 145 // Exposed for the sake of mocking/accessing in test code. |
146 | 146 |
147 // Fills |field_trial_ids| with the list of initialized field trials name and | 147 // Fills |field_trial_ids| with the list of initialized field trials name and |
148 // group ids. | 148 // group ids. |
149 virtual void GetFieldTrialIds( | 149 virtual void GetFieldTrialIds( |
150 std::vector<variations::ActiveGroupId>* field_trial_ids) const; | 150 std::vector<variations::ActiveGroupId>* field_trial_ids) const; |
151 | 151 |
152 metrics::ChromeUserMetricsExtension* uma_proto() { return &uma_proto_; } | 152 ChromeUserMetricsExtension* uma_proto() { return &uma_proto_; } |
153 const metrics::ChromeUserMetricsExtension* uma_proto() const { | 153 const ChromeUserMetricsExtension* uma_proto() const { |
154 return &uma_proto_; | 154 return &uma_proto_; |
155 } | 155 } |
156 | 156 |
157 private: | 157 private: |
158 // Returns true if the environment has already been filled in by a call to | 158 // Returns true if the environment has already been filled in by a call to |
159 // RecordEnvironment() or LoadSavedEnvironmentFromPrefs(). | 159 // RecordEnvironment() or LoadSavedEnvironmentFromPrefs(). |
160 bool HasEnvironment() const; | 160 bool HasEnvironment() const; |
161 | 161 |
162 // Returns true if the stability metrics have already been filled in by a | 162 // Returns true if the stability metrics have already been filled in by a |
163 // call to RecordStabilityMetrics(). | 163 // call to RecordStabilityMetrics(). |
(...skipping 11 matching lines...) Expand all Loading... |
175 base::TimeDelta uptime); | 175 base::TimeDelta uptime); |
176 | 176 |
177 // closed_ is true when record has been packed up for sending, and should | 177 // closed_ is true when record has been packed up for sending, and should |
178 // no longer be written to. It is only used for sanity checking. | 178 // no longer be written to. It is only used for sanity checking. |
179 bool closed_; | 179 bool closed_; |
180 | 180 |
181 // The type of the log, i.e. initial or ongoing. | 181 // The type of the log, i.e. initial or ongoing. |
182 const LogType log_type_; | 182 const LogType log_type_; |
183 | 183 |
184 // Stores the protocol buffer representation for this log. | 184 // Stores the protocol buffer representation for this log. |
185 metrics::ChromeUserMetricsExtension uma_proto_; | 185 ChromeUserMetricsExtension uma_proto_; |
186 | 186 |
187 // Used to interact with the embedder. Weak pointer; must outlive |this| | 187 // Used to interact with the embedder. Weak pointer; must outlive |this| |
188 // instance. | 188 // instance. |
189 metrics::MetricsServiceClient* const client_; | 189 MetricsServiceClient* const client_; |
190 | 190 |
191 // The time when the current log was created. | 191 // The time when the current log was created. |
192 const base::TimeTicks creation_time_; | 192 const base::TimeTicks creation_time_; |
193 | 193 |
194 PrefService* local_state_; | 194 PrefService* local_state_; |
195 | 195 |
196 DISALLOW_COPY_AND_ASSIGN(MetricsLog); | 196 DISALLOW_COPY_AND_ASSIGN(MetricsLog); |
197 }; | 197 }; |
198 | 198 |
| 199 } // namespace metrics |
| 200 |
199 #endif // COMPONENTS_METRICS_METRICS_LOG_H_ | 201 #endif // COMPONENTS_METRICS_METRICS_LOG_H_ |
OLD | NEW |