File: language_usage_metrics.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (58 lines) | stat: -rw-r--r-- 2,472 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_LANGUAGE_CORE_BROWSER_LANGUAGE_USAGE_METRICS_H_
#define COMPONENTS_LANGUAGE_CORE_BROWSER_LANGUAGE_USAGE_METRICS_H_

#include <string_view>
#include <vector>

#include "base/gtest_prod_util.h"

namespace language {
class UrlLanguageHistogram;

// Methods to record language usage as UMA histograms.
class LanguageUsageMetrics {
 public:
  LanguageUsageMetrics() = delete;
  LanguageUsageMetrics(const LanguageUsageMetrics&) = delete;
  LanguageUsageMetrics& operator=(const LanguageUsageMetrics&) = delete;

  // 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(std::string_view accept_languages);

  // Records detected page language history as a UMA histogram.
  // |UrlLanguageHistogram| is a mapping of page language to frequency. Country
  // codes are ignored for page language. Each language is counted once
  // regardless of frequency. Languages with a frequency below 0.05 are ignored.
  static void RecordPageLanguages(
      const language::UrlLanguageHistogram& language_counts);

  // Maps |locale| to a hash value in the "LanguageName" enum.
  // Deprecated - please use the enum "LocaleCodeBCP47" which maps the full
  // locale including country variant to a base::HashMetricName value.
  //
  // The language hash is calculated by splitting the locale on "-" and bit
  // shifting the char int values. For example, if |locale| is 'en' the codes
  // of 'e' and 'n' are 101 and 110 respectively, and the language hash will be
  // 101 * 256 + 100 = 25966. |locale| is case-insensitive and not checked for
  // validity. Returns 0 in case of errors.
  static int ToLanguageCodeHash(std::string_view locale);

 private:
  // Return a list of unique language codes after parsing `accept_languages`.
  static std::vector<int> ParseAcceptLanguages(
      std::string_view accept_languages);

  FRIEND_TEST_ALL_PREFIXES(LanguageUsageMetricsTest, ParseAcceptLanguages);
};

}  // namespace language

#endif  // COMPONENTS_LANGUAGE_CORE_BROWSER_LANGUAGE_USAGE_METRICS_H_