OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_COMMON_METRICS_HELPERS_H_ | 8 #ifndef CHROME_COMMON_METRICS_HELPERS_H_ |
9 #define CHROME_COMMON_METRICS_HELPERS_H_ | 9 #define CHROME_COMMON_METRICS_HELPERS_H_ |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 int GetEncodedLogSize(); | 70 int GetEncodedLogSize(); |
71 bool GetEncodedLog(char* buffer, int buffer_size); | 71 bool GetEncodedLog(char* buffer, int buffer_size); |
72 // Returns an empty string on failure. | 72 // Returns an empty string on failure. |
73 std::string GetEncodedLogString(); | 73 std::string GetEncodedLogString(); |
74 | 74 |
75 // Returns the amount of time in seconds that this log has been in use. | 75 // Returns the amount of time in seconds that this log has been in use. |
76 int GetElapsedSeconds(); | 76 int GetElapsedSeconds(); |
77 | 77 |
78 int num_events() { return num_events_; } | 78 int num_events() { return num_events_; } |
79 | 79 |
| 80 void set_hardware_class(const std::string& hardware_class) { |
| 81 hardware_class_ = hardware_class; |
| 82 } |
| 83 |
80 // Creates an MD5 hash of the given value, and returns hash as a byte | 84 // Creates an MD5 hash of the given value, and returns hash as a byte |
81 // buffer encoded as a std::string. | 85 // buffer encoded as a std::string. |
82 static std::string CreateHash(const std::string& value); | 86 static std::string CreateHash(const std::string& value); |
83 | 87 |
84 // Return a base64-encoded MD5 hash of the given string. | 88 // Return a base64-encoded MD5 hash of the given string. |
85 static std::string CreateBase64Hash(const std::string& string); | 89 static std::string CreateBase64Hash(const std::string& string); |
86 | 90 |
87 // Get the GMT buildtime for the current binary, expressed in seconds since | 91 // Get the GMT buildtime for the current binary, expressed in seconds since |
88 // Januray 1, 1970 GMT. | 92 // Januray 1, 1970 GMT. |
89 // The value is used to identify when a new build is run, so that previous | 93 // The value is used to identify when a new build is run, so that previous |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 log_->EndElement(); | 128 log_->EndElement(); |
125 } | 129 } |
126 | 130 |
127 private: | 131 private: |
128 MetricsLogBase* log_; | 132 MetricsLogBase* log_; |
129 }; | 133 }; |
130 friend class ScopedElement; | 134 friend class ScopedElement; |
131 | 135 |
132 static const char* WindowEventTypeToString(WindowEventType type); | 136 static const char* WindowEventTypeToString(WindowEventType type); |
133 | 137 |
| 138 // Frees the resources allocated by the XML document writer: the |
| 139 // main writer object as well as the XML tree structure, if |
| 140 // applicable. |
| 141 void FreeDocWriter(); |
| 142 |
134 // Convenience versions of xmlWriter functions | 143 // Convenience versions of xmlWriter functions |
135 void StartElement(const char* name); | 144 void StartElement(const char* name); |
136 void EndElement(); | 145 void EndElement(); |
137 void WriteAttribute(const std::string& name, const std::string& value); | 146 void WriteAttribute(const std::string& name, const std::string& value); |
138 void WriteIntAttribute(const std::string& name, int value); | 147 void WriteIntAttribute(const std::string& name, int value); |
139 void WriteInt64Attribute(const std::string& name, int64 value); | 148 void WriteInt64Attribute(const std::string& name, int64 value); |
140 | 149 |
141 // Write the attributes that are common to every metrics event type. | 150 // Write the attributes that are common to every metrics event type. |
142 void WriteCommonEventAttributes(); | 151 void WriteCommonEventAttributes(); |
143 | 152 |
144 // An extension that is appended to the appversion in each log. | 153 // An extension that is appended to the appversion in each log. |
145 static std::string version_extension_; | 154 static std::string version_extension_; |
146 | 155 |
147 base::Time start_time_; | 156 base::Time start_time_; |
148 base::Time end_time_; | 157 base::Time end_time_; |
149 | 158 |
150 std::string client_id_; | 159 std::string client_id_; |
151 std::string session_id_; | 160 std::string session_id_; |
| 161 std::string hardware_class_; |
152 | 162 |
153 // locked_ is true when record has been packed up for sending, and should | 163 // locked_ is true when record has been packed up for sending, and should |
154 // no longer be written to. It is only used for sanity checking and is | 164 // no longer be written to. It is only used for sanity checking and is |
155 // not a real lock. | 165 // not a real lock. |
156 bool locked_; | 166 bool locked_; |
157 | 167 |
| 168 xmlDocPtr doc_; |
158 xmlBufferPtr buffer_; | 169 xmlBufferPtr buffer_; |
159 xmlTextWriterPtr writer_; | 170 xmlTextWriterPtr writer_; |
160 int num_events_; // the number of events recorded in this log | 171 int num_events_; // the number of events recorded in this log |
161 | 172 |
162 DISALLOW_COPY_AND_ASSIGN(MetricsLogBase); | 173 DISALLOW_COPY_AND_ASSIGN(MetricsLogBase); |
163 }; | 174 }; |
164 | 175 |
165 // This class provides base functionality for logging metrics data. | 176 // This class provides base functionality for logging metrics data. |
166 // TODO(ananta) | 177 // TODO(ananta) |
167 // Factor out more common code from chrome and chrome frame metrics service | 178 // Factor out more common code from chrome and chrome frame metrics service |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // Maintain a map of histogram names to the sample stats we've sent. | 215 // Maintain a map of histogram names to the sample stats we've sent. |
205 typedef std::map<std::string, Histogram::SampleSet> LoggedSampleMap; | 216 typedef std::map<std::string, Histogram::SampleSet> LoggedSampleMap; |
206 | 217 |
207 // For histograms, record what we've already logged (as a sample for each | 218 // For histograms, record what we've already logged (as a sample for each |
208 // histogram) so that we can send only the delta with the next log. | 219 // histogram) so that we can send only the delta with the next log. |
209 LoggedSampleMap logged_samples_; | 220 LoggedSampleMap logged_samples_; |
210 }; | 221 }; |
211 | 222 |
212 #endif // CHROME_COMMON_METRICS_HELPERS_H_ | 223 #endif // CHROME_COMMON_METRICS_HELPERS_H_ |
213 | 224 |
OLD | NEW |