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 |
(...skipping 30 matching lines...) Expand all Loading... |
57 const base::Histogram::SampleSet& snapshot); | 58 const base::Histogram::SampleSet& snapshot); |
58 | 59 |
59 // Stop writing to this record and generate the encoded representation. | 60 // Stop writing to this record and generate the encoded representation. |
60 // None of the Record* methods can be called after this is called. | 61 // None of the Record* methods can be called after this is called. |
61 void CloseLog(); | 62 void CloseLog(); |
62 | 63 |
63 // These methods allow retrieval of the encoded representation of the | 64 // These methods allow retrieval of the encoded representation of the |
64 // record. They can only be called after CloseLog() has been called. | 65 // record. They can only be called after CloseLog() has been called. |
65 // GetEncodedLog returns false if buffer_size is less than | 66 // GetEncodedLog returns false if buffer_size is less than |
66 // GetEncodedLogSize(); | 67 // GetEncodedLogSize(); |
67 int GetEncodedLogSize(); | 68 int GetEncodedLogSizeXml(); |
68 bool GetEncodedLog(char* buffer, int buffer_size); | 69 bool GetEncodedLogXml(char* buffer, int buffer_size); |
69 // Returns an empty string on failure. | 70 |
70 std::string GetEncodedLogString(); | 71 // Fills |encoded_log| with the protobuf representation of the record. Can |
| 72 // only be called after CloseLog() has been called. |
| 73 void GetEncodedLogProto(std::string* encoded_log); |
71 | 74 |
72 // 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. |
73 int GetElapsedSeconds(); | 76 int GetElapsedSeconds(); |
74 | 77 |
75 int num_events() { return num_events_; } | 78 int num_events() { return num_events_; } |
76 | 79 |
77 void set_hardware_class(const std::string& hardware_class) { | 80 void set_hardware_class(const std::string& hardware_class) { |
78 hardware_class_ = hardware_class; | 81 hardware_class_ = hardware_class; |
79 } | 82 } |
80 | 83 |
81 // Creates an MD5 hash of the given value, and returns hash as a byte | 84 // Computes the MD5 hash of the given string. |
82 // buffer encoded as a std::string. | 85 // Fills |base64_encoded_hash| with the hash, encoded in base64. |
83 static std::string CreateHash(const std::string& value); | 86 // Fills |numeric_hash| with the first 8 bytes of the hash. |
84 | 87 static void CreateHashes(const std::string& string, |
85 // Return a base64-encoded MD5 hash of the given string. | 88 std::string* base64_encoded_hash, |
86 static std::string CreateBase64Hash(const std::string& string); | 89 uint64* numeric_hash); |
87 | 90 |
88 // 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 |
89 // Januray 1, 1970 GMT. | 92 // Januray 1, 1970 GMT. |
90 // 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 |
91 // reliability stats, from other builds, can be abandoned. | 94 // reliability stats, from other builds, can be abandoned. |
92 static int64 GetBuildTime(); | 95 static int64 GetBuildTime(); |
93 | 96 |
94 protected: | 97 protected: |
95 class XmlWrapper; | 98 class XmlWrapper; |
96 | 99 |
(...skipping 52 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 | 152 // 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 | 153 // no longer be written to. It is only used for sanity checking and is |
151 // not a real lock. | 154 // not a real lock. |
152 bool locked_; | 155 bool locked_; |
153 | 156 |
154 // Isolated to limit the dependency on the XML library for our consumers. | 157 // Isolated to limit the dependency on the XML library for our consumers. |
155 XmlWrapper* xml_wrapper_; | 158 XmlWrapper* xml_wrapper_; |
156 | 159 |
157 int num_events_; // the number of events recorded in this log | 160 int num_events_; // the number of events recorded in this log |
158 | 161 |
| 162 // Stores the protocol buffer representation for this log. |
| 163 metrics::ChromeUserMetricsExtension uma_proto_; |
| 164 |
159 private: | 165 private: |
160 DISALLOW_COPY_AND_ASSIGN(MetricsLogBase); | 166 DISALLOW_COPY_AND_ASSIGN(MetricsLogBase); |
161 }; | 167 }; |
162 | 168 |
163 #endif // CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ | 169 #endif // CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ |
OLD | NEW |