diff options
author | yuzo@chromium.org <yuzo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-21 08:42:08 +0000 |
---|---|---|
committer | yuzo@chromium.org <yuzo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-21 08:42:08 +0000 |
commit | 0426103d3c8a307b691bdf7752ce8bdf75c3e638 (patch) | |
tree | 643cfa100ad3d705575fd08c2178386df91a80ce /chrome/browser/language_usage_metrics.h | |
parent | 8b7ddc7fa369ba9bb74d784cc13f3eda98361246 (diff) | |
download | chromium_src-0426103d3c8a307b691bdf7752ce8bdf75c3e638.zip chromium_src-0426103d3c8a307b691bdf7752ce8bdf75c3e638.tar.gz chromium_src-0426103d3c8a307b691bdf7752ce8bdf75c3e638.tar.bz2 |
Record language usage as UMA histograms.
Record accept languages and application language as UMA histograms on
browser start-up.
See also http://crosbug.com/17419
BUG=none
TEST=run the unit tests
Review URL: http://codereview.chromium.org/7348004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93360 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/language_usage_metrics.h')
-rwxr-xr-x | chrome/browser/language_usage_metrics.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/chrome/browser/language_usage_metrics.h b/chrome/browser/language_usage_metrics.h new file mode 100755 index 0000000..e5cc708 --- /dev/null +++ b/chrome/browser/language_usage_metrics.h @@ -0,0 +1,48 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_LANGUAGE_USAGE_METRICS_H_ +#define CHROME_BROWSER_LANGUAGE_USAGE_METRICS_H_ +#pragma once + +#include <set> +#include <string> + +#include "base/gtest_prod_util.h" +#include "third_party/cld/languages/public/languages.h" + +// Methods to record language usage as UMA histograms. +// Language codes are defined in third_party/cld/languages/proto/languages.pb.h +class LanguageUsageMetrics { + public: + // Records accept languages as a UMA histogram. |accept_languages| is a + // case-insensitive comma-separated list of languages/locales of either xx, + // xx-YY, or xx_YY format where xx is iso-639 language code and YY is iso-3166 + // country code. Country code is ignored. That is, xx and XX-YY are considered + // identical and recorded once. + static void RecordAcceptLanguages(const std::string& accept_languages); + + // Records the application language as a UMA histogram. |application_locale| + // is a case-insensitive locale string of either xx, xx-YY, or xx_YY format. + // Only the language part (xx in the example) is considered. + static void RecordApplicationLanguage(const std::string& application_locale); + + private: + // This class must not be instantiated. + LanguageUsageMetrics(); + + // Parses |accept_languages| and returns a set of language codes in + // |languages|. + static void ParseAcceptLanguages(const std::string& accept_languages, + std::set<Language>* languages); + + // Parses |locale| and returns the language code. Returns UNKNOWN_LANGUAGE in + // case of errors. + static Language ToLanguage(const std::string& locale); + + FRIEND_TEST_ALL_PREFIXES(LanguageUsageMetricsTest, ParseAcceptLanguages); + FRIEND_TEST_ALL_PREFIXES(LanguageUsageMetricsTest, ToLanguage); +}; + +#endif // CHROME_BROWSER_LANGUAGE_USAGE_METRICS_H_ |