| 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/common/metrics/metrics_log_base.h" | 5 #include "chrome/common/metrics/metrics_log_base.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/md5.h" | 9 #include "base/md5.h" |
| 10 #include "base/perftimer.h" | 10 #include "base/perftimer.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // Any id less than 16 bytes is considered to be a testing id. | 36 // Any id less than 16 bytes is considered to be a testing id. |
| 37 bool IsTestingID(const std::string& id) { | 37 bool IsTestingID(const std::string& id) { |
| 38 return id.size() < 16; | 38 return id.size() < 16; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // Converts the 8-byte prefix of an MD5 hash into a uint64 value. | 41 // Converts the 8-byte prefix of an MD5 hash into a uint64 value. |
| 42 inline uint64 HashToUInt64(const std::string& hash) { | 42 inline uint64 HashToUInt64(const std::string& hash) { |
| 43 uint64 value; | 43 uint64 value; |
| 44 DCHECK_GE(hash.size(), sizeof(value)); | 44 DCHECK_GE(hash.size(), sizeof(value)); |
| 45 memcpy(&value, hash.data(), sizeof(value)); | 45 memcpy(&value, hash.data(), sizeof(value)); |
| 46 return base::htonll(value); | 46 return base::HostToNet64(value); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Creates an MD5 hash of the given value, and returns hash as a byte buffer | 49 // Creates an MD5 hash of the given value, and returns hash as a byte buffer |
| 50 // encoded as an std::string. | 50 // encoded as an std::string. |
| 51 std::string CreateHash(const std::string& value) { | 51 std::string CreateHash(const std::string& value) { |
| 52 base::MD5Context context; | 52 base::MD5Context context; |
| 53 base::MD5Init(&context); | 53 base::MD5Init(&context); |
| 54 base::MD5Update(&context, value); | 54 base::MD5Update(&context, value); |
| 55 | 55 |
| 56 base::MD5Digest digest; | 56 base::MD5Digest digest; |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 for (size_t i = 0; i < histogram.bucket_count(); ++i) { | 464 for (size_t i = 0; i < histogram.bucket_count(); ++i) { |
| 465 if (snapshot.counts(i)) { | 465 if (snapshot.counts(i)) { |
| 466 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket(); | 466 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket(); |
| 467 bucket->set_min(histogram.ranges(i)); | 467 bucket->set_min(histogram.ranges(i)); |
| 468 bucket->set_max(histogram.ranges(i + 1)); | 468 bucket->set_max(histogram.ranges(i + 1)); |
| 469 bucket->set_bucket_index(i); | 469 bucket->set_bucket_index(i); |
| 470 bucket->set_count(snapshot.counts(i)); | 470 bucket->set_count(snapshot.counts(i)); |
| 471 } | 471 } |
| 472 } | 472 } |
| 473 } | 473 } |
| OLD | NEW |