| 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 base::Base64Encode(it->log_text(), &encoded_log); | 144 if (!base::Base64Encode(it->log_text(), &encoded_log)) { |
| 145 list->Clear(); |
| 146 return; |
| 147 } |
| 145 base::MD5Update(&ctx, encoded_log); | 148 base::MD5Update(&ctx, encoded_log); |
| 146 list->Append(Value::CreateStringValue(encoded_log)); | 149 list->Append(Value::CreateStringValue(encoded_log)); |
| 147 } | 150 } |
| 148 | 151 |
| 149 // Append hash to the end of the list. | 152 // Append hash to the end of the list. |
| 150 base::MD5Digest digest; | 153 base::MD5Digest digest; |
| 151 base::MD5Final(&digest, &ctx); | 154 base::MD5Final(&digest, &ctx); |
| 152 list->Append(Value::CreateStringValue(base::MD5DigestToBase16(digest))); | 155 list->Append(Value::CreateStringValue(base::MD5DigestToBase16(digest))); |
| 153 DCHECK(list->GetSize() >= 3); // Minimum of 3 elements (size, data, hash). | 156 DCHECK(list->GetSize() >= 3); // Minimum of 3 elements (size, data, hash). |
| 154 } | 157 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 if (!valid) { | 217 if (!valid) { |
| 215 local_list->clear(); | 218 local_list->clear(); |
| 216 return MakeRecallStatusHistogram(CHECKSUM_STRING_CORRUPTION); | 219 return MakeRecallStatusHistogram(CHECKSUM_STRING_CORRUPTION); |
| 217 } | 220 } |
| 218 if (recovered_md5 != base::MD5DigestToBase16(digest)) { | 221 if (recovered_md5 != base::MD5DigestToBase16(digest)) { |
| 219 local_list->clear(); | 222 local_list->clear(); |
| 220 return MakeRecallStatusHistogram(CHECKSUM_CORRUPTION); | 223 return MakeRecallStatusHistogram(CHECKSUM_CORRUPTION); |
| 221 } | 224 } |
| 222 return MakeRecallStatusHistogram(RECALL_SUCCESS); | 225 return MakeRecallStatusHistogram(RECALL_SUCCESS); |
| 223 } | 226 } |
| OLD | NEW |