Replace usage of cloud_storage in archive_info_unittest.
[chromium-blink-merge.git] / components / metrics / metrics_hashes.cc
bloba042bcdf2c18e42de2da8a1beeb5230a5df7fa80
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"
8 #include "base/md5.h"
9 #include "base/sys_byteorder.h"
11 namespace metrics {
13 namespace {
15 // Converts the 8-byte prefix of an MD5 hash into a uint64 value.
16 inline uint64 HashToUInt64(const std::string& hash) {
17 uint64 value;
18 DCHECK_GE(hash.size(), sizeof(value));
19 memcpy(&value, hash.data(), sizeof(value));
20 return base::HostToNet64(value);
23 } // namespace
25 uint64 HashMetricName(const std::string& name) {
26 // Create an MD5 hash of the given |name|, represented as a byte buffer
27 // encoded as an std::string.
28 base::MD5Context context;
29 base::MD5Init(&context);
30 base::MD5Update(&context, name);
32 base::MD5Digest digest;
33 base::MD5Final(&digest, &context);
35 std::string hash_str(reinterpret_cast<char*>(digest.a), arraysize(digest.a));
36 return HashToUInt64(hash_str);
39 } // namespace metrics