OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_LANGUAGE_USAGE_METRICS_H_ | 5 #ifndef CHROME_BROWSER_LANGUAGE_USAGE_METRICS_H_ |
6 #define CHROME_BROWSER_LANGUAGE_USAGE_METRICS_H_ | 6 #define CHROME_BROWSER_LANGUAGE_USAGE_METRICS_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 | 12 |
13 // Methods to record language usage as UMA histograms. | 13 // Methods to record language usage as UMA histograms. |
14 // Language codes are defined in third_party/cld/languages/proto/languages.pb.h | |
15 class LanguageUsageMetrics { | 14 class LanguageUsageMetrics { |
16 public: | 15 public: |
17 // Records accept languages as a UMA histogram. |accept_languages| is a | 16 // Records accept languages as a UMA histogram. |accept_languages| is a |
18 // case-insensitive comma-separated list of languages/locales of either xx, | 17 // 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 | 18 // 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 | 19 // country code. Country code is ignored. That is, xx and XX-YY are considered |
21 // identical and recorded once. | 20 // identical and recorded once. |
22 static void RecordAcceptLanguages(const std::string& accept_languages); | 21 static void RecordAcceptLanguages(const std::string& accept_languages); |
23 | 22 |
24 // Records the application language as a UMA histogram. |application_locale| | 23 // 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. | 24 // 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. | 25 // Only the language part (xx in the example) is considered. |
27 static void RecordApplicationLanguage(const std::string& application_locale); | 26 static void RecordApplicationLanguage(const std::string& application_locale); |
28 | 27 |
29 private: | |
30 // This class must not be instantiated. | |
31 LanguageUsageMetrics(); | |
32 | |
33 // Parses |accept_languages| and returns a set of language codes in | |
34 // |languages|. | |
35 static void ParseAcceptLanguages(const std::string& accept_languages, | |
36 std::set<int>* languages); | |
37 | |
38 // Parses |locale| and returns the language code. Returns 0 in case of errors. | 28 // Parses |locale| and returns the language code. Returns 0 in case of errors. |
39 // The language code is calculated from two alphabets. For example, if | 29 // The language code is calculated from two alphabets. For example, if |
40 // |locale| is 'en' which represents 'English', the codes of 'e' and 'n' are | 30 // |locale| is 'en' which represents 'English', the codes of 'e' and 'n' are |
41 // 101 and 110 respectively, and the language code will be 101 * 256 + 100 = | 31 // 101 and 110 respectively, and the language code will be 101 * 256 + 100 = |
42 // 25966. | 32 // 25966. |
43 // |locale| should consist of only lower-case letters. This function doesn't | 33 // |locale| should consist of only lower-case letters. This function doesn't |
44 // check whether |locale| is valid locale or not strictly. | 34 // check whether |locale| is valid locale or not strictly. |
45 static int ToLanguageCode(const std::string &locale); | 35 static int ToLanguageCode(const std::string &locale); |
46 | 36 |
37 private: | |
38 // This class must not be instantiated. | |
39 LanguageUsageMetrics(); | |
sky
2013/05/24 15:28:28
DISALLOW_IMPLICIT_CONSTRUCTORS.
hajimehoshi
2013/05/27 00:55:22
Done.
| |
40 | |
41 // Parses |accept_languages| and returns a set of language codes in | |
42 // |languages|. | |
43 static void ParseAcceptLanguages(const std::string& accept_languages, | |
44 std::set<int>* languages); | |
45 | |
47 FRIEND_TEST_ALL_PREFIXES(LanguageUsageMetricsTest, ParseAcceptLanguages); | 46 FRIEND_TEST_ALL_PREFIXES(LanguageUsageMetricsTest, ParseAcceptLanguages); |
48 FRIEND_TEST_ALL_PREFIXES(LanguageUsageMetricsTest, ToLanguageCode); | |
49 }; | 47 }; |
50 | 48 |
51 #endif // CHROME_BROWSER_LANGUAGE_USAGE_METRICS_H_ | 49 #endif // CHROME_BROWSER_LANGUAGE_USAGE_METRICS_H_ |
OLD | NEW |