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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/metrics/metrics_util.cc
diff --git a/chrome/common/metrics/metrics_util.cc b/chrome/common/metrics/metrics_util.cc
index 775501d98f8e019fd81d5b47b866e96ba1bc4d0e..a69aa01af2a2fe8134bf05baded49b13ee24c19f 100644
--- a/chrome/common/metrics/metrics_util.cc
+++ b/chrome/common/metrics/metrics_util.cc
@@ -5,6 +5,8 @@
#include "chrome/common/metrics/metrics_util.h"
#include "base/sha1.h"
+#include "base/string_util.h"
+#include "base/strings/string_tokenizer.h"
#include "base/sys_byteorder.h"
namespace metrics {
@@ -24,4 +26,26 @@ uint32 HashName(const std::string& name) {
return base::ByteSwapToLE32(bits);
}
+int ToLanguageCode(const std::string& locale) {
+ base::StringTokenizer parts(locale, "-_");
+ if (!parts.GetNext())
+ return 0;
+
+ std::string language_part = parts.token();
+ StringToLowerASCII(&language_part);
+
+ int language_code = 0;
+ for (std::string::iterator it = language_part.begin();
+ it != language_part.end(); ++it) {
+ char ch = *it;
+ if (ch < 'a' || 'z' < ch)
+ return 0;
+
+ language_code <<= 8;
+ language_code += ch;
+ }
+
+ return language_code;
+}
+
} // namespace metrics

Powered by Google App Engine
This is Rietveld 408576698