Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: components/metrics/persisted_logs.h

Issue 2358223002: Add log date to the metrics log (Closed)
Patch Set: No explicit migration Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef COMPONENTS_METRICS_PERSISTED_LOGS_H_ 5 #ifndef COMPONENTS_METRICS_PERSISTED_LOGS_H_
6 #define COMPONENTS_METRICS_PERSISTED_LOGS_H_ 6 #define COMPONENTS_METRICS_PERSISTED_LOGS_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 // Calling code is responsible for ensuring that the lifetime of |local_state| 44 // Calling code is responsible for ensuring that the lifetime of |local_state|
45 // is longer than the lifetime of PersistedLogs. 45 // is longer than the lifetime of PersistedLogs.
46 // 46 //
47 // When saving logs to disk, stores either the first |min_log_count| logs, or 47 // When saving logs to disk, stores either the first |min_log_count| logs, or
48 // at least |min_log_bytes| bytes of logs, whichever is greater. 48 // at least |min_log_bytes| bytes of logs, whichever is greater.
49 // 49 //
50 // If the optional |max_log_size| parameter is non-zero, all logs larger than 50 // If the optional |max_log_size| parameter is non-zero, all logs larger than
51 // that limit will be skipped when writing to disk. 51 // that limit will be skipped when writing to disk.
52 PersistedLogs(PrefService* local_state, 52 PersistedLogs(PrefService* local_state,
53 const char* pref_name, 53 const char* pref_name,
54 const char* outdated_pref_name,
54 size_t min_log_count, 55 size_t min_log_count,
55 size_t min_log_bytes, 56 size_t min_log_bytes,
56 size_t max_log_size); 57 size_t max_log_size);
57 ~PersistedLogs(); 58 ~PersistedLogs();
58 59
59 // Write list to storage. 60 // Write list to storage.
60 void SerializeLogs() const; 61 void SerializeLogs() const;
61 62
62 // Reads the list from the preference. 63 // Reads the list from the preference.
63 LogReadStatus DeserializeLogs(); 64 LogReadStatus DeserializeLogs();
(...skipping 16 matching lines...) Expand all
80 DCHECK(has_staged_log()); 81 DCHECK(has_staged_log());
81 return list_[staged_log_index_].compressed_log_data; 82 return list_[staged_log_index_].compressed_log_data;
82 } 83 }
83 84
84 // Returns the element in the front of the list. 85 // Returns the element in the front of the list.
85 const std::string& staged_log_hash() const { 86 const std::string& staged_log_hash() const {
86 DCHECK(has_staged_log()); 87 DCHECK(has_staged_log());
87 return list_[staged_log_index_].hash; 88 return list_[staged_log_index_].hash;
88 } 89 }
89 90
91 // Returns the timestamp of the element in the front of the list.
92 const std::string& staged_log_timestamp() const {
93 DCHECK(has_staged_log());
94 return list_[staged_log_index_].timestamp;
95 }
96
90 // The number of elements currently stored. 97 // The number of elements currently stored.
91 size_t size() const { return list_.size(); } 98 size_t size() const { return list_.size(); }
92 99
93 // True if there are no stored logs. 100 // True if there are no stored logs.
94 bool empty() const { return list_.empty(); } 101 bool empty() const { return list_.empty(); }
95 102
96 private: 103 private:
97 // Writes the list to the ListValue. 104 // Writes the list to the ListValue.
98 void WriteLogsToPrefList(base::ListValue* list) const; 105 void WriteLogsToPrefList(base::ListValue* list) const;
99 106
100 // Reads the list from the ListValue. 107 // Reads the list from the ListValue.
101 LogReadStatus ReadLogsFromPrefList(const base::ListValue& list); 108 LogReadStatus ReadLogsFromPrefList(const base::ListValue& list);
102 109
110 // Reads the list from the ListValue in the old Log-hash pair format.
111 LogReadStatus ReadLogsFromOldFormatPrefList(const base::ListValue& list);
112
103 // A weak pointer to the PrefService object to read and write the preference 113 // A weak pointer to the PrefService object to read and write the preference
104 // from. Calling code should ensure this object continues to exist for the 114 // from. Calling code should ensure this object continues to exist for the
105 // lifetime of the PersistedLogs object. 115 // lifetime of the PersistedLogs object.
106 PrefService* local_state_; 116 PrefService* local_state_;
107 117
108 // The name of the preference to serialize logs to/from. 118 // The name of the preference to serialize logs to/from.
109 const char* pref_name_; 119 const char* pref_name_;
110 120
121 // The name of the preference to serialize logs to/from which may contain log
122 // in the old formatting.
123 const char* outdated_pref_name_;
124
111 // We will keep at least this |min_log_count_| logs or |min_log_bytes_| bytes 125 // We will keep at least this |min_log_count_| logs or |min_log_bytes_| bytes
112 // of logs, whichever is greater, when writing to disk. These apply after 126 // of logs, whichever is greater, when writing to disk. These apply after
113 // skipping logs greater than |max_log_size_|. 127 // skipping logs greater than |max_log_size_|.
114 const size_t min_log_count_; 128 const size_t min_log_count_;
115 const size_t min_log_bytes_; 129 const size_t min_log_bytes_;
116 130
117 // Logs greater than this size will not be written to disk. 131 // Logs greater than this size will not be written to disk.
118 const size_t max_log_size_; 132 const size_t max_log_size_;
119 133
120 struct LogHashPair { 134 struct LogInfo {
gayane -on leave until 09-2017 2016/09/30 17:01:56 no constructor here because we turned the timestam
121 // Initializes the members based on uncompressed |log_data|. 135 // Initializes the members based on uncompressed |log_data|.
122 void Init(const std::string& log_data); 136 void Init(const std::string& log_data);
123 137
124 // Compressed log data - a serialized protobuf that's been gzipped. 138 // Compressed log data - a serialized protobuf that's been gzipped.
125 std::string compressed_log_data; 139 std::string compressed_log_data;
126 140
127 // The SHA1 hash of log, stored to catch errors from memory corruption. 141 // The SHA1 hash of log, stored to catch errors from memory corruption.
128 std::string hash; 142 std::string hash;
143
144 // The timestamp of when the log was created in seconds. Seconds is enough
145 // as decision for removing old logs wouldn't need more granularity.
146 std::string timestamp;
129 }; 147 };
130 // A list of all of the stored logs, stored with SHA1 hashes to check for 148 // A list of all of the stored logs, stored with SHA1 hashes to check for
131 // corruption while they are stored in memory. 149 // corruption while they are stored in memory.
132 std::vector<LogHashPair> list_; 150 std::vector<LogInfo> list_;
133 151
134 // The index and type of the log staged for upload. If nothing has been 152 // The index and type of the log staged for upload. If nothing has been
135 // staged, the index will be -1. 153 // staged, the index will be -1.
136 int staged_log_index_; 154 int staged_log_index_;
137 155
138 DISALLOW_COPY_AND_ASSIGN(PersistedLogs); 156 DISALLOW_COPY_AND_ASSIGN(PersistedLogs);
139 }; 157 };
140 158
141 } // namespace metrics 159 } // namespace metrics
142 160
143 #endif // COMPONENTS_METRICS_PERSISTED_LOGS_H_ 161 #endif // COMPONENTS_METRICS_PERSISTED_LOGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698