Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/common/metrics/metrics_util.cc

Issue 15311006: Added and replaced some UMAs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_util.h" 5 #include "chrome/common/metrics/metrics_util.h"
6 6
7 #include "base/sha1.h" 7 #include "base/sha1.h"
8 #include "base/string_util.h"
9 #include "base/strings/string_tokenizer.h"
8 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
9 11
10 namespace metrics { 12 namespace metrics {
11 13
12 uint32 HashName(const std::string& name) { 14 uint32 HashName(const std::string& name) {
13 // SHA-1 is designed to produce a uniformly random spread in its output space, 15 // SHA-1 is designed to produce a uniformly random spread in its output space,
14 // even for nearly-identical inputs. 16 // even for nearly-identical inputs.
15 unsigned char sha1_hash[base::kSHA1Length]; 17 unsigned char sha1_hash[base::kSHA1Length];
16 base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(name.c_str()), 18 base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(name.c_str()),
17 name.size(), 19 name.size(),
18 sha1_hash); 20 sha1_hash);
19 21
20 uint32 bits; 22 uint32 bits;
21 COMPILE_ASSERT(sizeof(bits) < sizeof(sha1_hash), need_more_data); 23 COMPILE_ASSERT(sizeof(bits) < sizeof(sha1_hash), need_more_data);
22 memcpy(&bits, sha1_hash, sizeof(bits)); 24 memcpy(&bits, sha1_hash, sizeof(bits));
23 25
24 return base::ByteSwapToLE32(bits); 26 return base::ByteSwapToLE32(bits);
25 } 27 }
26 28
29 int ToLanguageCode(const std::string& locale) {
30 base::StringTokenizer parts(locale, "-_");
31 if (!parts.GetNext())
32 return 0;
33
34 std::string language_part = parts.token();
35 StringToLowerASCII(&language_part);
36
37 int language_code = 0;
38 for (std::string::iterator it = language_part.begin();
39 it != language_part.end(); ++it) {
40 char ch = *it;
41 if (ch < 'a' || 'z' < ch)
42 return 0;
43
44 language_code <<= 8;
45 language_code += ch;
46 }
47
48 return language_code;
49 }
50
27 } // namespace metrics 51 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698