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 #ifndef COMPONENTS_LANGUAGE_USAGE_METRICS_LANGUAGE_USAGE_METRICS_H_
6 #define COMPONENTS_LANGUAGE_USAGE_METRICS_LANGUAGE_USAGE_METRICS_H_
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
14 namespace language_usage_metrics
{
16 // Methods to record language usage as UMA histograms.
17 class LanguageUsageMetrics
{
19 // Records accept languages as a UMA histogram. |accept_languages| is a
20 // case-insensitive comma-separated list of languages/locales of either xx,
21 // xx-YY, or xx_YY format where xx is iso-639 language code and YY is iso-3166
22 // country code. Country code is ignored. That is, xx and XX-YY are considered
23 // identical and recorded once.
24 static void RecordAcceptLanguages(const std::string
& accept_languages
);
26 // Records the application language as a UMA histogram. |application_locale|
27 // is a case-insensitive locale string of either xx, xx-YY, or xx_YY format.
28 // Only the language part (xx in the example) is considered.
29 static void RecordApplicationLanguage(const std::string
& application_locale
);
31 // Parses |locale| and returns the language code. Returns 0 in case of errors.
32 // The language code is calculated from two alphabets. For example, if
33 // |locale| is 'en' which represents 'English', the codes of 'e' and 'n' are
34 // 101 and 110 respectively, and the language code will be 101 * 256 + 100 =
36 // |locale| should consist of only lower-case letters. This function doesn't
37 // check whether |locale| is valid locale or not strictly.
38 static int ToLanguageCode(const std::string
&locale
);
41 DISALLOW_IMPLICIT_CONSTRUCTORS(LanguageUsageMetrics
);
43 // Parses |accept_languages| and returns a set of language codes in
45 static void ParseAcceptLanguages(const std::string
& accept_languages
,
46 std::set
<int>* languages
);
48 FRIEND_TEST_ALL_PREFIXES(LanguageUsageMetricsTest
, ParseAcceptLanguages
);
51 } // namespace language_usage_metrics
53 #endif // COMPONENTS_LANGUAGE_USAGE_METRICS_LANGUAGE_USAGE_METRICS_H_