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