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.
4 
5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_BROWSER_METRICS_H_
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_BROWSER_METRICS_H_
7 
8 #include <stddef.h>
9 
10 #include "base/strings/string_piece.h"
11 
12 namespace translate {
13 
14 namespace TranslateBrowserMetrics {
15 
16 // When Chrome Translate is ready to translate a page, one of following reasons
17 // decides the next browser action.
18 // Note: Don't insert items. It will change the reporting UMA value and break
19 // the UMA dashboard page. Instead, append it at the end of enum as suggested
20 // below. Added items also need to be added to TranslateInitiationStatus in
21 // enums.xml.
22 enum InitiationStatusType {
23   INITIATION_STATUS_DISABLED_BY_PREFS,
24   INITIATION_STATUS_DISABLED_BY_SWITCH,
25   INITIATION_STATUS_DISABLED_BY_CONFIG,
26   INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED,
27   INITIATION_STATUS_URL_IS_NOT_SUPPORTED,
28   INITIATION_STATUS_SIMILAR_LANGUAGES,
29   INITIATION_STATUS_ACCEPT_LANGUAGES,
30   INITIATION_STATUS_AUTO_BY_CONFIG,
31   INITIATION_STATUS_AUTO_BY_LINK,
32   INITIATION_STATUS_SHOW_INFOBAR,
33   INITIATION_STATUS_MIME_TYPE_IS_NOT_SUPPORTED,
34   INITIATION_STATUS_DISABLED_BY_KEY,
35   INITIATION_STATUS_LANGUAGE_IN_ULP,
36   INITIATION_STATUS_ABORTED_BY_RANKER,
37   INITIATION_STATUS_ABORTED_BY_TOO_OFTEN_DENIED,
38   INITIATION_STATUS_ABORTED_BY_MATCHES_PREVIOUS_LANGUAGE,
39   INITIATION_STATUS_CREATE_INFOBAR,
40   INITIATION_STATUS_SHOW_ICON,
41   INITIATION_STATUS_SUPPRESS_INFOBAR,
42   INITIATION_STATUS_SHOW_UI_PREDEFINED_TARGET_LANGUAGE,
43   INITIATION_STATUS_NO_NETWORK,
44   INITIATION_STATUS_DOESNT_NEED_TRANSLATION,
45   INITIATION_STATUS_IDENTICAL_LANGUAGE_USE_SOURCE_LANGUAGE_UNKNOWN,
46   INITIATION_STATUS_DISABLED_BY_AUTOFILL_ASSISTANT,
47   // Insert new items here.
48   INITIATION_STATUS_MAX,
49 };
50 
51 enum class HrefTranslateStatus {
52   kAutoTranslated,
53   kAutoTranslatedDifferentTargetLanguage,
54 
55   // Deprecated, use the below values instead.
56   kDeprecatedNotAutoTranslated,
57 
58   kUiShownNotAutoTranslated,
59   kNoUiShownNotAutoTranslated,
60 
61   // Insert new items here. Keep in sync with HrefTranslateStatus in enums.xml
62   // when adding values.
63   kMaxValue = kNoUiShownNotAutoTranslated
64 };
65 
66 enum class HrefTranslatePrefsFilterStatus {
67   kNotInBlocklists,
68   kLanguageInBlocklist,
69   kSiteInBlocklist,
70   kBothLanguageAndSiteInBlocklist,
71 
72   // Insert new items here. Keep in sync with HrefTranslatePrefsFilterStatus in
73   // enums.xml when adding values.
74   kMaxValue = kBothLanguageAndSiteInBlocklist
75 };
76 
77 enum class TargetLanguageOrigin {
78   kRecentTarget,
79   kLanguageModel,
80   kApplicationUI,
81   kAcceptLanguages,
82   kDefaultEnglish,
83   // Insert new items here. Keep in sync with TranslateTargetLanguageOrigin in
84   // enums.xml when adding values.
85   kMaxValue = kDefaultEnglish
86 };
87 
88 enum class MenuTranslationUnavailableReason {
89   kTranslateDisabled,
90   kNetworkOffline,
91   kApiKeysMissing,
92   kMHTMLPage,
93   kURLNotTranslatable,
94   kTargetLangUnknown,
95   kNotAllowedByPolicy,
96   kSourceLangUnknown,
97   // Insert new items here. Keep in sync with MenuTranslationUnavailableReason
98   // in enums.xml when adding values.
99   kMaxValue = kSourceLangUnknown
100 };
101 
102 // Called when Chrome Translate is initiated to report a reason of the next
103 // browser action.
104 void ReportInitiationStatus(InitiationStatusType type);
105 
106 // Called when Chrome opens the URL so that the user sends an error feedback.
107 void ReportLanguageDetectionError();
108 
109 // Called when the context (Desktop) menu or app (Mobile) menu is shown and
110 // manual translation is unavailable to report a reason it is unavailable.
111 void ReportMenuTranslationUnavailableReason(
112     MenuTranslationUnavailableReason reason);
113 
114 // Called when language detection details are complete.
115 void ReportLanguageDetectionContentLength(size_t length);
116 
117 void ReportLocalesOnDisabledByPrefs(base::StringPiece locale);
118 
119 // Called when Chrome Translate server sends the language list which includes
120 // a undisplayable language in the user's locale.
121 void ReportUndisplayableLanguage(base::StringPiece language);
122 
123 void ReportUnsupportedLanguageAtInitiation(base::StringPiece language);
124 
125 // Called when a request is sent to the translate server to report the source
126 // language of the translated page. Buckets are labelled with CLD3LanguageCode
127 // values.
128 void ReportTranslateSourceLanguage(base::StringPiece language);
129 
130 // Called when a request is sent to the translate server to report the target
131 // language for the translated page. Buckets are labelled with CLD3LanguageCode
132 // values.
133 void ReportTranslateTargetLanguage(base::StringPiece language);
134 
135 // Called when Chrome Translate is initiated, the navigation is from Google, and
136 // a href translate target is present.
137 void ReportTranslateHrefHintStatus(HrefTranslateStatus status);
138 
139 // Called when Chrome Translate is initiated, the navigation is from Google, and
140 // a href translate target is present. Records the status of any user prefs
141 // filtering.
142 void ReportTranslateHrefHintPrefsFilterStatus(
143     HrefTranslatePrefsFilterStatus status);
144 
145 // Called when Chrome Translate target language is determined.
146 void ReportTranslateTargetLanguageOrigin(TargetLanguageOrigin origin);
147 
148 }  // namespace TranslateBrowserMetrics
149 
150 }  // namespace translate
151 
152 #endif  // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_BROWSER_METRICS_H_
153