• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "base/metrics/metrics_hashes.h"
6 
7 #include "base/logging.h"
8 #include "base/md5.h"
9 #include "base/sys_byteorder.h"
10 
11 namespace base {
12 
13 namespace {
14 
15 // Converts the 8-byte prefix of an MD5 hash into a uint64_t value.
DigestToUInt64(const base::MD5Digest & digest)16 inline uint64_t DigestToUInt64(const base::MD5Digest& digest) {
17   uint64_t value;
18   DCHECK_GE(sizeof(digest.a), sizeof(value));
19   memcpy(&value, digest.a, sizeof(value));
20   return base::NetToHost64(value);
21 }
22 
23 }  // namespace
24 
HashMetricName(base::StringPiece name)25 uint64_t HashMetricName(base::StringPiece name) {
26   base::MD5Digest digest;
27   base::MD5Sum(name.data(), name.size(), &digest);
28   return DigestToUInt64(digest);
29 }
30 
31 }  // namespace metrics
32