OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_METRICS_LOG_BASE_H_ | 8 #ifndef CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ |
9 #define CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ | 9 #define CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ |
10 #pragma once | 10 #pragma once |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "chrome/common/metrics/proto/chrome_user_metrics_extension.pb.h" |
17 #include "content/public/common/page_transition_types.h" | 18 #include "content/public/common/page_transition_types.h" |
18 | 19 |
19 class GURL; | 20 class GURL; |
20 | 21 |
21 // This class provides base functionality for logging metrics data. | 22 // This class provides base functionality for logging metrics data. |
22 class MetricsLogBase { | 23 class MetricsLogBase { |
23 public: | 24 public: |
24 // Creates a new metrics log | 25 // Creates a new metrics log |
25 // client_id is the identifier for this profile on this installation | 26 // client_id is the identifier for this profile on this installation |
26 // session_id is an integer that's incremented on each application launch | 27 // session_id is an integer that's incremented on each application launch |
27 MetricsLogBase(const std::string& client_id, | 28 MetricsLogBase(const std::string& client_id, |
28 int session_id, | 29 int session_id, |
29 const std::string& version_string); | 30 const std::string& version_string); |
30 virtual ~MetricsLogBase(); | 31 virtual ~MetricsLogBase(); |
31 | 32 |
| 33 // Computes the MD5 hash of the given string. |
| 34 // Fills |base64_encoded_hash| with the hash, encoded in base64. |
| 35 // Fills |numeric_hash| with the first 8 bytes of the hash. |
| 36 static void CreateHashes(const std::string& string, |
| 37 std::string* base64_encoded_hash, |
| 38 uint64* numeric_hash); |
| 39 |
| 40 // Get the GMT buildtime for the current binary, expressed in seconds since |
| 41 // Januray 1, 1970 GMT. |
| 42 // The value is used to identify when a new build is run, so that previous |
| 43 // reliability stats, from other builds, can be abandoned. |
| 44 static int64 GetBuildTime(); |
| 45 |
| 46 // Convenience function to return the current time at a resolution in seconds. |
| 47 // This wraps base::TimeTicks, and hence provides an abstract time that is |
| 48 // always incrementing for use in measuring time durations. |
| 49 static int64 GetCurrentTime(); |
| 50 |
32 // Records a user-initiated action. | 51 // Records a user-initiated action. |
33 void RecordUserAction(const char* key); | 52 void RecordUserAction(const char* key); |
34 | 53 |
35 enum WindowEventType { | 54 enum WindowEventType { |
36 WINDOW_CREATE = 0, | 55 WINDOW_CREATE = 0, |
37 WINDOW_OPEN, | 56 WINDOW_OPEN, |
38 WINDOW_CLOSE, | 57 WINDOW_CLOSE, |
39 WINDOW_DESTROY | 58 WINDOW_DESTROY |
40 }; | 59 }; |
41 | 60 |
(...skipping 15 matching lines...) Expand all Loading... |
57 const base::Histogram::SampleSet& snapshot); | 76 const base::Histogram::SampleSet& snapshot); |
58 | 77 |
59 // Stop writing to this record and generate the encoded representation. | 78 // Stop writing to this record and generate the encoded representation. |
60 // None of the Record* methods can be called after this is called. | 79 // None of the Record* methods can be called after this is called. |
61 void CloseLog(); | 80 void CloseLog(); |
62 | 81 |
63 // These methods allow retrieval of the encoded representation of the | 82 // These methods allow retrieval of the encoded representation of the |
64 // record. They can only be called after CloseLog() has been called. | 83 // record. They can only be called after CloseLog() has been called. |
65 // GetEncodedLog returns false if buffer_size is less than | 84 // GetEncodedLog returns false if buffer_size is less than |
66 // GetEncodedLogSize(); | 85 // GetEncodedLogSize(); |
67 int GetEncodedLogSize(); | 86 int GetEncodedLogSizeXml(); |
68 bool GetEncodedLog(char* buffer, int buffer_size); | 87 bool GetEncodedLogXml(char* buffer, int buffer_size); |
69 // Returns an empty string on failure. | 88 |
70 std::string GetEncodedLogString(); | 89 // Fills |encoded_log| with the protobuf representation of the record. Can |
| 90 // only be called after CloseLog() has been called. |
| 91 void GetEncodedLogProto(std::string* encoded_log); |
71 | 92 |
72 // Returns the amount of time in seconds that this log has been in use. | 93 // Returns the amount of time in seconds that this log has been in use. |
73 int GetElapsedSeconds(); | 94 int GetElapsedSeconds(); |
74 | 95 |
75 int num_events() { return num_events_; } | 96 int num_events() { return num_events_; } |
76 | 97 |
77 void set_hardware_class(const std::string& hardware_class) { | 98 void set_hardware_class(const std::string& hardware_class) { |
78 hardware_class_ = hardware_class; | 99 hardware_class_ = hardware_class; |
79 } | 100 } |
80 | 101 |
81 // Creates an MD5 hash of the given value, and returns hash as a byte | |
82 // buffer encoded as a std::string. | |
83 static std::string CreateHash(const std::string& value); | |
84 | |
85 // Return a base64-encoded MD5 hash of the given string. | |
86 static std::string CreateBase64Hash(const std::string& string); | |
87 | |
88 // Get the GMT buildtime for the current binary, expressed in seconds since | |
89 // Januray 1, 1970 GMT. | |
90 // The value is used to identify when a new build is run, so that previous | |
91 // reliability stats, from other builds, can be abandoned. | |
92 static int64 GetBuildTime(); | |
93 | |
94 protected: | 102 protected: |
95 class XmlWrapper; | 103 class XmlWrapper; |
96 | 104 |
97 // Returns a string containing the current time. | 105 // Returns a string containing the current time. |
98 // Virtual so that it can be overridden for testing. | 106 // Virtual so that it can be overridden for testing. |
99 virtual std::string GetCurrentTimeString(); | 107 virtual std::string GetCurrentTimeString(); |
100 // Helper class that invokes StartElement from constructor, and EndElement | 108 // Helper class that invokes StartElement from constructor, and EndElement |
101 // from destructor. | 109 // from destructor. |
102 // | 110 // |
103 // Use the macro OPEN_ELEMENT_FOR_SCOPE to help avoid usage problems. | 111 // Use the macro OPEN_ELEMENT_FOR_SCOPE to help avoid usage problems. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // locked_ is true when record has been packed up for sending, and should | 157 // locked_ is true when record has been packed up for sending, and should |
150 // no longer be written to. It is only used for sanity checking and is | 158 // no longer be written to. It is only used for sanity checking and is |
151 // not a real lock. | 159 // not a real lock. |
152 bool locked_; | 160 bool locked_; |
153 | 161 |
154 // Isolated to limit the dependency on the XML library for our consumers. | 162 // Isolated to limit the dependency on the XML library for our consumers. |
155 XmlWrapper* xml_wrapper_; | 163 XmlWrapper* xml_wrapper_; |
156 | 164 |
157 int num_events_; // the number of events recorded in this log | 165 int num_events_; // the number of events recorded in this log |
158 | 166 |
| 167 // Stores the protocol buffer representation for this log. |
| 168 metrics::ChromeUserMetricsExtension uma_proto_; |
| 169 |
159 private: | 170 private: |
160 DISALLOW_COPY_AND_ASSIGN(MetricsLogBase); | 171 DISALLOW_COPY_AND_ASSIGN(MetricsLogBase); |
161 }; | 172 }; |
162 | 173 |
163 #endif // CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ | 174 #endif // CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ |
OLD | NEW |