1 // Copyright 2014 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 #include "components/translate/core/browser/translate_browser_metrics.h"
9 #include "base/basictypes.h"
10 #include "base/metrics/histogram.h"
11 #include "base/metrics/sparse_histogram.h"
12 #include "components/language_usage_metrics/language_usage_metrics.h"
18 // Constant string values to indicate UMA names. All entries should have
19 // a corresponding index in MetricsNameIndex and an entry in |kMetricsEntries|.
20 const char kTranslateInitiationStatus
[] =
21 "Translate.InitiationStatus.v2";
22 const char kTranslateReportLanguageDetectionError
[] =
23 "Translate.ReportLanguageDetectionError";
24 const char kTranslateLocalesOnDisabledByPrefs
[] =
25 "Translate.LocalesOnDisabledByPrefs";
26 const char kTranslateUndisplayableLanguage
[] =
27 "Translate.UndisplayableLanguage";
28 const char kTranslateUnsupportedLanguageAtInitiation
[] =
29 "Translate.UnsupportedLanguageAtInitiation";
32 TranslateBrowserMetrics::MetricsNameIndex index
;
33 const char* const name
;
36 // This entry table should be updated when new UMA items are added.
37 const MetricsEntry kMetricsEntries
[] = {
38 { TranslateBrowserMetrics::UMA_INITIATION_STATUS
,
39 kTranslateInitiationStatus
},
40 { TranslateBrowserMetrics::UMA_LANGUAGE_DETECTION_ERROR
,
41 kTranslateReportLanguageDetectionError
},
42 { TranslateBrowserMetrics::UMA_LOCALES_ON_DISABLED_BY_PREFS
,
43 kTranslateLocalesOnDisabledByPrefs
},
44 { TranslateBrowserMetrics::UMA_UNDISPLAYABLE_LANGUAGE
,
45 kTranslateUndisplayableLanguage
},
46 { TranslateBrowserMetrics::UMA_UNSUPPORTED_LANGUAGE_AT_INITIATION
,
47 kTranslateUnsupportedLanguageAtInitiation
},
50 static_assert(arraysize(kMetricsEntries
) == TranslateBrowserMetrics::UMA_MAX
,
51 "kMetricsEntries should have UMA_MAX elements");
55 namespace TranslateBrowserMetrics
{
57 void ReportInitiationStatus(InitiationStatusType type
) {
58 UMA_HISTOGRAM_ENUMERATION(kTranslateInitiationStatus
,
60 INITIATION_STATUS_MAX
);
63 void ReportLanguageDetectionError() {
64 UMA_HISTOGRAM_BOOLEAN(kTranslateReportLanguageDetectionError
, true);
67 void ReportLocalesOnDisabledByPrefs(const std::string
& locale
) {
68 UMA_HISTOGRAM_SPARSE_SLOWLY(
69 kTranslateLocalesOnDisabledByPrefs
,
70 language_usage_metrics::LanguageUsageMetrics::ToLanguageCode(locale
));
73 void ReportUndisplayableLanguage(const std::string
& language
) {
75 language_usage_metrics::LanguageUsageMetrics::ToLanguageCode(language
);
76 UMA_HISTOGRAM_SPARSE_SLOWLY(kTranslateUndisplayableLanguage
,
80 void ReportUnsupportedLanguageAtInitiation(const std::string
& language
) {
82 language_usage_metrics::LanguageUsageMetrics::ToLanguageCode(language
);
83 UMA_HISTOGRAM_SPARSE_SLOWLY(kTranslateUnsupportedLanguageAtInitiation
,
87 const char* GetMetricsName(MetricsNameIndex index
) {
88 for (size_t i
= 0; i
< arraysize(kMetricsEntries
); ++i
) {
89 if (kMetricsEntries
[i
].index
== index
)
90 return kMetricsEntries
[i
].name
;
96 } // namespace TranslateBrowserMetrics
98 } // namespace translate