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

Side by Side Diff: chrome/browser/language_usage_metrics.h

Issue 15311006: Added and replaced some UMAs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (Rebasing) 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/language_usage_metrics.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/basictypes.h"
11 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
12 13
13 // Methods to record language usage as UMA histograms. 14 // 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 { 15 class LanguageUsageMetrics {
16 public: 16 public:
17 // Records accept languages as a UMA histogram. |accept_languages| is a 17 // Records accept languages as a UMA histogram. |accept_languages| is a
18 // case-insensitive comma-separated list of languages/locales of either xx, 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 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 20 // country code. Country code is ignored. That is, xx and XX-YY are considered
21 // identical and recorded once. 21 // identical and recorded once.
22 static void RecordAcceptLanguages(const std::string& accept_languages); 22 static void RecordAcceptLanguages(const std::string& accept_languages);
23 23
24 // Records the application language as a UMA histogram. |application_locale| 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. 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. 26 // Only the language part (xx in the example) is considered.
27 static void RecordApplicationLanguage(const std::string& application_locale); 27 static void RecordApplicationLanguage(const std::string& application_locale);
28 28
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. 29 // 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 30 // 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 31 // |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 = 32 // 101 and 110 respectively, and the language code will be 101 * 256 + 100 =
42 // 25966. 33 // 25966.
43 // |locale| should consist of only lower-case letters. This function doesn't 34 // |locale| should consist of only lower-case letters. This function doesn't
44 // check whether |locale| is valid locale or not strictly. 35 // check whether |locale| is valid locale or not strictly.
45 static int ToLanguageCode(const std::string &locale); 36 static int ToLanguageCode(const std::string &locale);
46 37
38 private:
39 DISALLOW_IMPLICIT_CONSTRUCTORS(LanguageUsageMetrics);
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_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/language_usage_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698