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 #include "components/metrics/persisted_logs.h" | 5 #include "components/metrics/persisted_logs.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 DCHECK(has_staged_log()); | 102 DCHECK(has_staged_log()); |
103 } | 103 } |
104 | 104 |
105 void PersistedLogs::DiscardStagedLog() { | 105 void PersistedLogs::DiscardStagedLog() { |
106 DCHECK(has_staged_log()); | 106 DCHECK(has_staged_log()); |
107 DCHECK_LT(static_cast<size_t>(staged_log_index_), list_.size()); | 107 DCHECK_LT(static_cast<size_t>(staged_log_index_), list_.size()); |
108 list_.erase(list_.begin() + staged_log_index_); | 108 list_.erase(list_.begin() + staged_log_index_); |
109 staged_log_index_ = -1; | 109 staged_log_index_ = -1; |
110 } | 110 } |
111 | 111 |
| 112 void PersistedLogs::Purge() { |
| 113 if (has_staged_log()) { |
| 114 DiscardStagedLog(); |
| 115 } |
| 116 list_.clear(); |
| 117 local_state_->ClearPref(pref_name_); |
| 118 } |
| 119 |
112 PersistedLogs::LogReadStatus PersistedLogs::ReadLogsFromPrefList( | 120 PersistedLogs::LogReadStatus PersistedLogs::ReadLogsFromPrefList( |
113 const base::ListValue& list_value) { | 121 const base::ListValue& list_value) { |
114 if (list_value.empty()) | 122 if (list_value.empty()) |
115 return metrics_->RecordLogReadStatus(LIST_EMPTY); | 123 return metrics_->RecordLogReadStatus(LIST_EMPTY); |
116 | 124 |
117 const size_t log_count = list_value.GetSize(); | 125 const size_t log_count = list_value.GetSize(); |
118 | 126 |
119 DCHECK(list_.empty()); | 127 DCHECK(list_.empty()); |
120 list_.resize(log_count); | 128 list_.resize(log_count); |
121 | 129 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 dict_value->SetString(kLogDataKey, | 185 dict_value->SetString(kLogDataKey, |
178 EncodeToBase64(list_[i].compressed_log_data)); | 186 EncodeToBase64(list_[i].compressed_log_data)); |
179 dict_value->SetString(kLogTimestampKey, list_[i].timestamp); | 187 dict_value->SetString(kLogTimestampKey, list_[i].timestamp); |
180 list_value->Append(std::move(dict_value)); | 188 list_value->Append(std::move(dict_value)); |
181 } | 189 } |
182 if (dropped_logs_num > 0) | 190 if (dropped_logs_num > 0) |
183 metrics_->RecordDroppedLogsNum(dropped_logs_num); | 191 metrics_->RecordDroppedLogsNum(dropped_logs_num); |
184 } | 192 } |
185 | 193 |
186 } // namespace metrics | 194 } // namespace metrics |
OLD | NEW |