OLD | NEW |
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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 // Constructs a PersistedLogs that stores data in |local_state| under the | 45 // Constructs a PersistedLogs that stores data in |local_state| under the |
46 // preference |pref_name| and also reads from legacy pref |old_pref_name|. | 46 // preference |pref_name| and also reads from legacy pref |old_pref_name|. |
47 // Calling code is responsible for ensuring that the lifetime of |local_state| | 47 // Calling code is responsible for ensuring that the lifetime of |local_state| |
48 // is longer than the lifetime of PersistedLogs. | 48 // is longer than the lifetime of PersistedLogs. |
49 // | 49 // |
50 // When saving logs to disk, stores either the first |min_log_count| logs, or | 50 // When saving logs to disk, stores either the first |min_log_count| logs, or |
51 // at least |min_log_bytes| bytes of logs, whichever is greater. | 51 // at least |min_log_bytes| bytes of logs, whichever is greater. |
52 // | 52 // |
53 // If the optional |max_log_size| parameter is non-zero, all logs larger than | 53 // If the optional |max_log_size| parameter is non-zero, all logs larger than |
54 // that limit will be dropped before logs are written to disk. | 54 // that limit will be skipped when writing to disk. |
55 PersistedLogs(PrefService* local_state, | 55 PersistedLogs(PrefService* local_state, |
56 const char* pref_name, | 56 const char* pref_name, |
57 const char* old_pref_name, | 57 const char* old_pref_name, |
58 size_t min_log_count, | 58 size_t min_log_count, |
59 size_t min_log_bytes, | 59 size_t min_log_bytes, |
60 size_t max_log_size); | 60 size_t max_log_size); |
61 ~PersistedLogs(); | 61 ~PersistedLogs(); |
62 | 62 |
63 // Write list to storage. | 63 // Write list to storage. |
64 void SerializeLogs(); | 64 void SerializeLogs() const; |
65 | 65 |
66 // Reads the list from the preference. | 66 // Reads the list from the preference. |
67 LogReadStatus DeserializeLogs(); | 67 LogReadStatus DeserializeLogs(); |
68 | 68 |
69 // Adds a log to the list. | 69 // Adds a log to the list. |
70 void StoreLog(const std::string& log_data); | 70 void StoreLog(const std::string& log_data); |
71 | 71 |
72 // Stages the most recent log. The staged_log will remain the same even if | 72 // Stages the most recent log. The staged_log will remain the same even if |
73 // additional logs are added. | 73 // additional logs are added. |
74 void StageLog(); | 74 void StageLog(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } | 108 } |
109 | 109 |
110 // The number of elements currently stored. | 110 // The number of elements currently stored. |
111 size_t size() const { return list_.size(); } | 111 size_t size() const { return list_.size(); } |
112 | 112 |
113 // True if there are no stored logs. | 113 // True if there are no stored logs. |
114 bool empty() const { return list_.empty(); } | 114 bool empty() const { return list_.empty(); } |
115 | 115 |
116 private: | 116 private: |
117 // Writes the list to the ListValue. | 117 // Writes the list to the ListValue. |
118 void WriteLogsToPrefList(base::ListValue* list); | 118 void WriteLogsToPrefList(base::ListValue* list) const; |
119 | 119 |
120 // Reads the list from the ListValue. | 120 // Reads the list from the ListValue. |
121 LogReadStatus ReadLogsFromPrefList(const base::ListValue& list); | 121 LogReadStatus ReadLogsFromPrefList(const base::ListValue& list); |
122 | 122 |
123 // Reads the list from the old pref's ListValue. | 123 // Reads the list from the old pref's ListValue. |
124 // TODO(asvitkine): Remove the old pref in M39. | 124 // TODO(asvitkine): Remove the old pref in M39. |
125 LogReadStatus ReadLogsFromOldPrefList(const base::ListValue& list); | 125 LogReadStatus ReadLogsFromOldPrefList(const base::ListValue& list); |
126 | 126 |
127 // A weak pointer to the PrefService object to read and write the preference | 127 // A weak pointer to the PrefService object to read and write the preference |
128 // from. Calling code should ensure this object continues to exist for the | 128 // from. Calling code should ensure this object continues to exist for the |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // and current) and a client might store them in either order, so it's | 175 // and current) and a client might store them in either order, so it's |
176 // not necessarily the case that the provisional store is the last store. | 176 // not necessarily the case that the provisional store is the last store. |
177 int last_provisional_store_index_; | 177 int last_provisional_store_index_; |
178 | 178 |
179 DISALLOW_COPY_AND_ASSIGN(PersistedLogs); | 179 DISALLOW_COPY_AND_ASSIGN(PersistedLogs); |
180 }; | 180 }; |
181 | 181 |
182 } // namespace metrics | 182 } // namespace metrics |
183 | 183 |
184 #endif // COMPONENTS_METRICS_PERSISTED_LOGS_H_ | 184 #endif // COMPONENTS_METRICS_PERSISTED_LOGS_H_ |
OLD | NEW |