OLD | NEW |
| (Empty) |
1 // Copyright 2013 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. | |
4 | |
5 #include "chrome/browser/translate/translate_browser_metrics.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/metrics/histogram.h" | |
11 #include "base/metrics/sparse_histogram.h" | |
12 #include "chrome/browser/language_usage_metrics.h" | |
13 | |
14 namespace { | |
15 | |
16 // Constant string values to indicate UMA names. All entries should have | |
17 // a corresponding index in MetricsNameIndex and an entry in |kMetricsEntries|. | |
18 const char kTranslateInitiationStatus[] = | |
19 "Translate.InitiationStatus.v2"; | |
20 const char kTranslateReportLanguageDetectionError[] = | |
21 "Translate.ReportLanguageDetectionError"; | |
22 const char kTranslateLocalesOnDisabledByPrefs[] = | |
23 "Translate.LocalesOnDisabledByPrefs"; | |
24 const char kTranslateUndisplayableLanguage[] = | |
25 "Translate.UndisplayableLanguage"; | |
26 const char kTranslateUnsupportedLanguageAtInitiation[] = | |
27 "Translate.UnsupportedLanguageAtInitiation"; | |
28 | |
29 struct MetricsEntry { | |
30 TranslateBrowserMetrics::MetricsNameIndex index; | |
31 const char* const name; | |
32 }; | |
33 | |
34 // This entry table should be updated when new UMA items are added. | |
35 const MetricsEntry kMetricsEntries[] = { | |
36 { TranslateBrowserMetrics::UMA_INITIATION_STATUS, | |
37 kTranslateInitiationStatus }, | |
38 { TranslateBrowserMetrics::UMA_LANGUAGE_DETECTION_ERROR, | |
39 kTranslateReportLanguageDetectionError }, | |
40 { TranslateBrowserMetrics::UMA_LOCALES_ON_DISABLED_BY_PREFS, | |
41 kTranslateLocalesOnDisabledByPrefs }, | |
42 { TranslateBrowserMetrics::UMA_UNDISPLAYABLE_LANGUAGE, | |
43 kTranslateUndisplayableLanguage }, | |
44 { TranslateBrowserMetrics::UMA_UNSUPPORTED_LANGUAGE_AT_INITIATION, | |
45 kTranslateUnsupportedLanguageAtInitiation }, | |
46 }; | |
47 | |
48 COMPILE_ASSERT(arraysize(kMetricsEntries) == TranslateBrowserMetrics::UMA_MAX, | |
49 arraysize_of_kMetricsEntries_should_be_UMA_MAX); | |
50 | |
51 } // namespace | |
52 | |
53 namespace TranslateBrowserMetrics { | |
54 | |
55 void ReportInitiationStatus(InitiationStatusType type) { | |
56 UMA_HISTOGRAM_ENUMERATION(kTranslateInitiationStatus, | |
57 type, | |
58 INITIATION_STATUS_MAX); | |
59 } | |
60 | |
61 void ReportLanguageDetectionError() { | |
62 UMA_HISTOGRAM_BOOLEAN(kTranslateReportLanguageDetectionError, true); | |
63 } | |
64 | |
65 void ReportLocalesOnDisabledByPrefs(const std::string& locale) { | |
66 UMA_HISTOGRAM_SPARSE_SLOWLY(kTranslateLocalesOnDisabledByPrefs, | |
67 LanguageUsageMetrics::ToLanguageCode(locale)); | |
68 } | |
69 | |
70 void ReportUndisplayableLanguage(const std::string& language) { | |
71 int language_code = LanguageUsageMetrics::ToLanguageCode(language); | |
72 UMA_HISTOGRAM_SPARSE_SLOWLY(kTranslateUndisplayableLanguage, | |
73 language_code); | |
74 } | |
75 | |
76 void ReportUnsupportedLanguageAtInitiation(const std::string& language) { | |
77 int language_code = LanguageUsageMetrics::ToLanguageCode(language); | |
78 UMA_HISTOGRAM_SPARSE_SLOWLY(kTranslateUnsupportedLanguageAtInitiation, | |
79 language_code); | |
80 } | |
81 | |
82 const char* GetMetricsName(MetricsNameIndex index) { | |
83 for (size_t i = 0; i < arraysize(kMetricsEntries); ++i) { | |
84 if (kMetricsEntries[i].index == index) | |
85 return kMetricsEntries[i].name; | |
86 } | |
87 NOTREACHED(); | |
88 return NULL; | |
89 } | |
90 | |
91 } // namespace TranslateBrowserMetrics | |
OLD | NEW |