| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/md5.h" | 10 #include "base/md5.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 if (bytes_used >= min_log_bytes_ && | 123 if (bytes_used >= min_log_bytes_ && |
| 124 saved_log_count >= min_log_count_) { | 124 saved_log_count >= min_log_count_) { |
| 125 break; | 125 break; |
| 126 } | 126 } |
| 127 // Oversized logs won't be persisted, so don't count them. | 127 // Oversized logs won't be persisted, so don't count them. |
| 128 if (log_size > max_log_size_) | 128 if (log_size > max_log_size_) |
| 129 continue; | 129 continue; |
| 130 bytes_used += log_size; | 130 bytes_used += log_size; |
| 131 ++saved_log_count; | 131 ++saved_log_count; |
| 132 } | 132 } |
| 133 int dropped_logs_num = start - 1; |
| 133 | 134 |
| 134 for (size_t i = start; i < list_.size(); ++i) { | 135 for (size_t i = start; i < list_.size(); ++i) { |
| 135 size_t log_size = list_[i].compressed_log_data.length(); | 136 size_t log_size = list_[i].compressed_log_data.length(); |
| 136 if (log_size > max_log_size_) { | 137 if (log_size > max_log_size_) { |
| 137 UMA_HISTOGRAM_COUNTS("UMA.Large Accumulated Log Not Persisted", | 138 UMA_HISTOGRAM_COUNTS("UMA.Large Accumulated Log Not Persisted", |
| 138 static_cast<int>(log_size)); | 139 static_cast<int>(log_size)); |
| 140 dropped_logs_num++; |
| 139 continue; | 141 continue; |
| 140 } | 142 } |
| 141 AppendBase64String(list_[i].compressed_log_data, list_value); | 143 AppendBase64String(list_[i].compressed_log_data, list_value); |
| 142 AppendBase64String(list_[i].hash, list_value); | 144 AppendBase64String(list_[i].hash, list_value); |
| 143 } | 145 } |
| 146 if (dropped_logs_num > 0) |
| 147 UMA_HISTOGRAM_COUNTS("UMA.UnSentLogs.Dropped", dropped_logs_num); |
| 144 } | 148 } |
| 145 | 149 |
| 146 PersistedLogs::LogReadStatus PersistedLogs::ReadLogsFromPrefList( | 150 PersistedLogs::LogReadStatus PersistedLogs::ReadLogsFromPrefList( |
| 147 const base::ListValue& list_value) { | 151 const base::ListValue& list_value) { |
| 148 if (list_value.empty()) | 152 if (list_value.empty()) |
| 149 return MakeRecallStatusHistogram(LIST_EMPTY); | 153 return MakeRecallStatusHistogram(LIST_EMPTY); |
| 150 | 154 |
| 151 // For each log, there's two entries in the list (the data and the hash). | 155 // For each log, there's two entries in the list (the data and the hash). |
| 152 DCHECK_EQ(0U, list_value.GetSize() % 2); | 156 DCHECK_EQ(0U, list_value.GetSize() % 2); |
| 153 const size_t log_count = list_value.GetSize() / 2; | 157 const size_t log_count = list_value.GetSize() / 2; |
| 154 | 158 |
| 155 // Resize |list_| ahead of time, so that values can be decoded directly into | 159 // Resize |list_| ahead of time, so that values can be decoded directly into |
| 156 // the elements of the list. | 160 // the elements of the list. |
| 157 DCHECK(list_.empty()); | 161 DCHECK(list_.empty()); |
| 158 list_.resize(log_count); | 162 list_.resize(log_count); |
| 159 | 163 |
| 160 for (size_t i = 0; i < log_count; ++i) { | 164 for (size_t i = 0; i < log_count; ++i) { |
| 161 if (!ReadBase64String(list_value, i * 2, &list_[i].compressed_log_data) || | 165 if (!ReadBase64String(list_value, i * 2, &list_[i].compressed_log_data) || |
| 162 !ReadBase64String(list_value, i * 2 + 1, &list_[i].hash)) { | 166 !ReadBase64String(list_value, i * 2 + 1, &list_[i].hash)) { |
| 163 list_.clear(); | 167 list_.clear(); |
| 164 return MakeRecallStatusHistogram(LOG_STRING_CORRUPTION); | 168 return MakeRecallStatusHistogram(LOG_STRING_CORRUPTION); |
| 165 } | 169 } |
| 166 } | 170 } |
| 167 | 171 |
| 168 return MakeRecallStatusHistogram(RECALL_SUCCESS); | 172 return MakeRecallStatusHistogram(RECALL_SUCCESS); |
| 169 } | 173 } |
| 170 | 174 |
| 171 } // namespace metrics | 175 } // namespace metrics |
| OLD | NEW |