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.
5 #include "chrome/browser/translate/translate_browser_metrics.h"
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"
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";
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";
30 TranslateBrowserMetrics::MetricsNameIndex index;
31 const char* const name;
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 },
48 COMPILE_ASSERT(arraysize(kMetricsEntries) == TranslateBrowserMetrics::UMA_MAX,
49 arraysize_of_kMetricsEntries_should_be_UMA_MAX);
53 namespace TranslateBrowserMetrics {
55 void ReportInitiationStatus(InitiationStatusType type) {
56 UMA_HISTOGRAM_ENUMERATION(kTranslateInitiationStatus,
58 INITIATION_STATUS_MAX);
61 void ReportLanguageDetectionError() {
62 UMA_HISTOGRAM_BOOLEAN(kTranslateReportLanguageDetectionError, true);
65 void ReportLocalesOnDisabledByPrefs(const std::string& locale) {
66 UMA_HISTOGRAM_SPARSE_SLOWLY(kTranslateLocalesOnDisabledByPrefs,
67 LanguageUsageMetrics::ToLanguageCode(locale));
70 void ReportUndisplayableLanguage(const std::string& language) {
71 int language_code = LanguageUsageMetrics::ToLanguageCode(language);
72 UMA_HISTOGRAM_SPARSE_SLOWLY(kTranslateUndisplayableLanguage,
76 void ReportUnsupportedLanguageAtInitiation(const std::string& language) {
77 int language_code = LanguageUsageMetrics::ToLanguageCode(language);
78 UMA_HISTOGRAM_SPARSE_SLOWLY(kTranslateUnsupportedLanguageAtInitiation,
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;
91 } // namespace TranslateBrowserMetrics