| 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 #include "chrome/browser/metrics/metrics_log_serializer.h" | 5 #include "chrome/browser/metrics/metrics_log_serializer.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/md5.h" | 8 #include "base/md5.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 return; | 148 return; |
| 149 | 149 |
| 150 size_t start = 0; | 150 size_t start = 0; |
| 151 // If there are too many logs, keep the most recent logs up to the length | 151 // If there are too many logs, keep the most recent logs up to the length |
| 152 // limit, and at least to the minimum number of bytes. | 152 // limit, and at least to the minimum number of bytes. |
| 153 if (local_list.size() > list_length_limit) { | 153 if (local_list.size() > list_length_limit) { |
| 154 start = local_list.size(); | 154 start = local_list.size(); |
| 155 size_t bytes_used = 0; | 155 size_t bytes_used = 0; |
| 156 for (std::vector<MetricsLogManager::SerializedLog>::const_reverse_iterator | 156 for (std::vector<MetricsLogManager::SerializedLog>::const_reverse_iterator |
| 157 it = local_list.rbegin(); it != local_list.rend(); ++it) { | 157 it = local_list.rbegin(); it != local_list.rend(); ++it) { |
| 158 // TODO(isherman): Always uses XML length so both formats of a given log | 158 size_t log_size = it->length(); |
| 159 // will be saved; switch to proto once that's the primary format. | |
| 160 size_t log_size = it->xml.length(); | |
| 161 if (bytes_used >= byte_limit && | 159 if (bytes_used >= byte_limit && |
| 162 (local_list.size() - start) >= list_length_limit) | 160 (local_list.size() - start) >= list_length_limit) |
| 163 break; | 161 break; |
| 164 bytes_used += log_size; | 162 bytes_used += log_size; |
| 165 --start; | 163 --start; |
| 166 } | 164 } |
| 167 } | 165 } |
| 168 DCHECK_LT(start, local_list.size()); | 166 DCHECK_LT(start, local_list.size()); |
| 169 if (start >= local_list.size()) | 167 if (start >= local_list.size()) |
| 170 return; | 168 return; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 if (!valid) { | 262 if (!valid) { |
| 265 local_list->clear(); | 263 local_list->clear(); |
| 266 return MakeRecallStatusHistogram(CHECKSUM_STRING_CORRUPTION, is_xml); | 264 return MakeRecallStatusHistogram(CHECKSUM_STRING_CORRUPTION, is_xml); |
| 267 } | 265 } |
| 268 if (recovered_md5 != base::MD5DigestToBase16(digest)) { | 266 if (recovered_md5 != base::MD5DigestToBase16(digest)) { |
| 269 local_list->clear(); | 267 local_list->clear(); |
| 270 return MakeRecallStatusHistogram(CHECKSUM_CORRUPTION, is_xml); | 268 return MakeRecallStatusHistogram(CHECKSUM_CORRUPTION, is_xml); |
| 271 } | 269 } |
| 272 return MakeRecallStatusHistogram(RECALL_SUCCESS, is_xml); | 270 return MakeRecallStatusHistogram(RECALL_SUCCESS, is_xml); |
| 273 } | 271 } |
| OLD | NEW |