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
3 // found in the LICENSE file.
5 #include "components/metrics/metrics_hashes.h"
7 #include "base/logging.h"
9 #include "base/sys_byteorder.h"
15 // Converts the 8-byte prefix of an MD5 hash into a uint64 value.
16 inline uint64
DigestToUInt64(const base::MD5Digest
& digest
) {
18 DCHECK_GE(arraysize(digest
.a
), sizeof(value
));
19 memcpy(&value
, digest
.a
, sizeof(value
));
20 return base::HostToNet64(value
);
25 uint64
HashMetricName(const std::string
& name
) {
26 base::MD5Digest digest
;
27 base::MD5Sum(name
.c_str(), name
.size(), &digest
);
28 return DigestToUInt64(digest
);
31 } // namespace metrics