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_BROWSER_METRICS_METRICS_LOG_H_ | 8 #ifndef CHROME_BROWSER_METRICS_METRICS_LOG_H_ |
9 #define CHROME_BROWSER_METRICS_METRICS_LOG_H_ | 9 #define CHROME_BROWSER_METRICS_METRICS_LOG_H_ |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // record. They can only be called after CloseLog() has been called. | 88 // record. They can only be called after CloseLog() has been called. |
89 // GetEncodedLog returns false if buffer_size is less than | 89 // GetEncodedLog returns false if buffer_size is less than |
90 // GetEncodedLogSize(); | 90 // GetEncodedLogSize(); |
91 int GetEncodedLogSize(); | 91 int GetEncodedLogSize(); |
92 bool GetEncodedLog(char* buffer, int buffer_size); | 92 bool GetEncodedLog(char* buffer, int buffer_size); |
93 | 93 |
94 // Returns the amount of time in seconds that this log has been in use. | 94 // Returns the amount of time in seconds that this log has been in use. |
95 int GetElapsedSeconds(); | 95 int GetElapsedSeconds(); |
96 | 96 |
97 int num_events() { return num_events_; } | 97 int num_events() { return num_events_; } |
| 98 void set_hardware_class(const std::string& hardware_class) { |
| 99 hardware_class_ = hardware_class; |
| 100 } |
98 | 101 |
99 // Creates an MD5 hash of the given value, and returns hash as a byte | 102 // Creates an MD5 hash of the given value, and returns hash as a byte |
100 // buffer encoded as a std::string. | 103 // buffer encoded as a std::string. |
101 static std::string CreateHash(const std::string& value); | 104 static std::string CreateHash(const std::string& value); |
102 | 105 |
103 // Return a base64-encoded MD5 hash of the given string. | 106 // Return a base64-encoded MD5 hash of the given string. |
104 static std::string CreateBase64Hash(const std::string& string); | 107 static std::string CreateBase64Hash(const std::string& string); |
105 | 108 |
106 // Get the current version of the application as a string. | 109 // Get the current version of the application as a string. |
107 static std::string GetVersionString(); | 110 static std::string GetVersionString(); |
108 | 111 |
109 // Get the GMT buildtime for the current binary, expressed in seconds since | 112 // Get the GMT buildtime for the current binary, expressed in seconds since |
110 // Januray 1, 1970 GMT. | 113 // January 1, 1970 GMT. |
111 // The value is used to identify when a new build is run, so that previous | 114 // The value is used to identify when a new build is run, so that previous |
112 // reliability stats, from other builds, can be abandoned. | 115 // reliability stats, from other builds, can be abandoned. |
113 static int64 GetBuildTime(); | 116 static int64 GetBuildTime(); |
114 | 117 |
115 // Get the amount of uptime in seconds since this function was last called. | 118 // Get the amount of uptime in seconds since this function was last called. |
116 // This updates the cumulative uptime metric for uninstall as a side effect. | 119 // This updates the cumulative uptime metric for uninstall as a side effect. |
117 static int64 GetIncrementalUptime(PrefService* pref); | 120 static int64 GetIncrementalUptime(PrefService* pref); |
118 | 121 |
119 // Use |extension| in all uploaded appversions in addition to the standard | 122 // Use |extension| in all uploaded appversions in addition to the standard |
120 // version string. | 123 // version string. |
121 static void set_version_extension(const std::string& extension) { | 124 static void set_version_extension(const std::string& extension) { |
122 version_extension_ = extension; | 125 version_extension_ = extension; |
123 } | 126 } |
| 127 |
124 protected: | 128 protected: |
125 // Returns a string containing the current time. | 129 // Returns a string containing the current time. |
126 // Virtual so that it can be overridden for testing. | 130 // Virtual so that it can be overridden for testing. |
127 virtual std::string GetCurrentTimeString(); | 131 virtual std::string GetCurrentTimeString(); |
128 | 132 |
129 private: | 133 private: |
130 // Helper class that invokes StartElement from constructor, and EndElement | 134 // Helper class that invokes StartElement from constructor, and EndElement |
131 // from destructor. | 135 // from destructor. |
132 // | 136 // |
133 // Use the macro OPEN_ELEMENT_FOR_SCOPE to help avoid usage problems. | 137 // Use the macro OPEN_ELEMENT_FOR_SCOPE to help avoid usage problems. |
(...skipping 13 matching lines...) Expand all Loading... |
147 log_->EndElement(); | 151 log_->EndElement(); |
148 } | 152 } |
149 | 153 |
150 private: | 154 private: |
151 MetricsLog* log_; | 155 MetricsLog* log_; |
152 }; | 156 }; |
153 friend class ScopedElement; | 157 friend class ScopedElement; |
154 | 158 |
155 static const char* WindowEventTypeToString(WindowEventType type); | 159 static const char* WindowEventTypeToString(WindowEventType type); |
156 | 160 |
| 161 // Frees the resources allocated by the XML document writer: the |
| 162 // main writer object as well as the XML tree structure, if |
| 163 // applicable. |
| 164 void FreeDocWriter(); |
| 165 |
157 // Convenience versions of xmlWriter functions | 166 // Convenience versions of xmlWriter functions |
158 void StartElement(const char* name); | 167 void StartElement(const char* name); |
159 void EndElement(); | 168 void EndElement(); |
160 void WriteAttribute(const std::string& name, const std::string& value); | 169 void WriteAttribute(const std::string& name, const std::string& value); |
161 void WriteIntAttribute(const std::string& name, int value); | 170 void WriteIntAttribute(const std::string& name, int value); |
162 void WriteInt64Attribute(const std::string& name, int64 value); | 171 void WriteInt64Attribute(const std::string& name, int64 value); |
163 | 172 |
164 // Write the attributes that are common to every metrics event type. | 173 // Write the attributes that are common to every metrics event type. |
165 void WriteCommonEventAttributes(); | 174 void WriteCommonEventAttributes(); |
166 | 175 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 const DictionaryValue& profile_metrics); | 209 const DictionaryValue& profile_metrics); |
201 | 210 |
202 // An extension that is appended to the appversion in each log. | 211 // An extension that is appended to the appversion in each log. |
203 static std::string version_extension_; | 212 static std::string version_extension_; |
204 | 213 |
205 base::Time start_time_; | 214 base::Time start_time_; |
206 base::Time end_time_; | 215 base::Time end_time_; |
207 | 216 |
208 std::string client_id_; | 217 std::string client_id_; |
209 std::string session_id_; | 218 std::string session_id_; |
| 219 std::string hardware_class_; |
210 | 220 |
211 // locked_ is true when record has been packed up for sending, and should | 221 // locked_ is true when record has been packed up for sending, and should |
212 // no longer be written to. It is only used for sanity checking and is | 222 // no longer be written to. It is only used for sanity checking and is |
213 // not a real lock. | 223 // not a real lock. |
214 bool locked_; | 224 bool locked_; |
215 | 225 |
| 226 xmlDocPtr doc_; |
216 xmlBufferPtr buffer_; | 227 xmlBufferPtr buffer_; |
217 xmlTextWriterPtr writer_; | 228 xmlTextWriterPtr writer_; |
218 int num_events_; // the number of events recorded in this log | 229 int num_events_; // the number of events recorded in this log |
219 | 230 |
220 DISALLOW_EVIL_CONSTRUCTORS(MetricsLog); | 231 DISALLOW_EVIL_CONSTRUCTORS(MetricsLog); |
221 }; | 232 }; |
222 | 233 |
223 #endif // CHROME_BROWSER_METRICS_METRICS_LOG_H_ | 234 #endif // CHROME_BROWSER_METRICS_METRICS_LOG_H_ |
OLD | NEW |