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 <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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 list->Append(Value::CreateIntegerValue(local_list.size() - start)); | 134 list->Append(Value::CreateIntegerValue(local_list.size() - start)); |
135 | 135 |
136 base::MD5Context ctx; | 136 base::MD5Context ctx; |
137 base::MD5Init(&ctx); | 137 base::MD5Init(&ctx); |
138 std::string encoded_log; | 138 std::string encoded_log; |
139 for (std::vector<MetricsLogManager::SerializedLog>::const_iterator it = | 139 for (std::vector<MetricsLogManager::SerializedLog>::const_iterator it = |
140 local_list.begin() + start; | 140 local_list.begin() + start; |
141 it != local_list.end(); ++it) { | 141 it != local_list.end(); ++it) { |
142 // We encode the compressed log as Value::CreateStringValue() expects to | 142 // We encode the compressed log as Value::CreateStringValue() expects to |
143 // take a valid UTF8 string. | 143 // take a valid UTF8 string. |
144 if (!base::Base64Encode(it->log_text(), &encoded_log)) { | 144 base::Base64Encode(it->log_text(), &encoded_log); |
145 list->Clear(); | |
146 return; | |
147 } | |
148 base::MD5Update(&ctx, encoded_log); | 145 base::MD5Update(&ctx, encoded_log); |
149 list->Append(Value::CreateStringValue(encoded_log)); | 146 list->Append(Value::CreateStringValue(encoded_log)); |
150 } | 147 } |
151 | 148 |
152 // Append hash to the end of the list. | 149 // Append hash to the end of the list. |
153 base::MD5Digest digest; | 150 base::MD5Digest digest; |
154 base::MD5Final(&digest, &ctx); | 151 base::MD5Final(&digest, &ctx); |
155 list->Append(Value::CreateStringValue(base::MD5DigestToBase16(digest))); | 152 list->Append(Value::CreateStringValue(base::MD5DigestToBase16(digest))); |
156 DCHECK(list->GetSize() >= 3); // Minimum of 3 elements (size, data, hash). | 153 DCHECK(list->GetSize() >= 3); // Minimum of 3 elements (size, data, hash). |
157 } | 154 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 if (!valid) { | 214 if (!valid) { |
218 local_list->clear(); | 215 local_list->clear(); |
219 return MakeRecallStatusHistogram(CHECKSUM_STRING_CORRUPTION); | 216 return MakeRecallStatusHistogram(CHECKSUM_STRING_CORRUPTION); |
220 } | 217 } |
221 if (recovered_md5 != base::MD5DigestToBase16(digest)) { | 218 if (recovered_md5 != base::MD5DigestToBase16(digest)) { |
222 local_list->clear(); | 219 local_list->clear(); |
223 return MakeRecallStatusHistogram(CHECKSUM_CORRUPTION); | 220 return MakeRecallStatusHistogram(CHECKSUM_CORRUPTION); |
224 } | 221 } |
225 return MakeRecallStatusHistogram(RECALL_SUCCESS); | 222 return MakeRecallStatusHistogram(RECALL_SUCCESS); |
226 } | 223 } |
OLD | NEW |