File: translate_metrics_logger.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (235 lines) | stat: -rw-r--r-- 9,572 bytes parent folder | download | duplicates (6)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// Copyright 2020 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_TRANSLATE_CORE_BROWSER_TRANSLATE_METRICS_LOGGER_H_
#define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_METRICS_LOGGER_H_

#include <stdint.h>
#include <string>

#include "components/translate/core/browser/translate_browser_metrics.h"
#include "components/translate/core/common/translate_errors.h"
#include "services/metrics/public/cpp/ukm_source_id.h"

namespace translate {

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class RankerDecision {
  kUninitialized = 0,
  kNotQueried = 1,
  kShowUI = 2,
  kDontShowUI = 3,
  kMaxValue = kDontShowUI,
};

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class TranslateState {
  kUninitialized = 0,
  kNotTranslatedNoUI = 1,
  kNotTranslatedOmniboxIconOnly = 2,
  kNotTranslatedUIShown = 3,
  kTranslatedNoUI = 4,
  kTranslatedOmniboxIconOnly = 5,
  kTranslatedUIShown = 6,
  kMaxValue = kTranslatedUIShown,
};

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class TranslationStatus {
  kUninitialized = 0,
  // kSuccessFromManualTranslation = 1,  // no longer used, split into
  // kSuccessFromManualUiTranslation and
  // kSuccessFromManualContextMenuTranslation enum values.
  kSuccessFromAutomaticTranslationByPref = 2,
  kSuccessFromAutomaticTranslationByLink = 3,
  // kManualTranslation = 4,  // no longer used, split into
  // kRevertedManualUiTranslation and
  // kRevertedManualContextMenuTranslation enum values.
  kRevertedAutomaticTranslation = 5,
  kNewTranslation = 6,
  kTranslationAbandoned = 7,
  // kFailedWithNoErrorManualTranslation = 8,  // no longer used, split into
  // kFailedWithNoErrorManualUiTranslation and
  // kFailedWithNoErrorManualContextMenuTranslation enum values.
  kFailedWithNoErrorAutomaticTranslation = 9,
  // kFailedWithErrorManualTranslation = 10,  // no longer used, split into
  // kFailedWithErrorManualUiTranslation and
  // kFailedWithErrorManualContextMenuTranslation enum values.
  kFailedWithErrorAutomaticTranslation = 11,
  kSuccessFromManualUiTranslation = 12,
  kRevertedManualUiTranslation = 13,
  kFailedWithNoErrorManualUiTranslation = 14,
  kFailedWithErrorManualUiTranslation = 15,
  kSuccessFromManualContextMenuTranslation = 16,
  kRevertedManualContextMenuTranslation = 17,
  kFailedWithNoErrorManualContextMenuTranslation = 18,
  kFailedWithErrorManualContextMenuTranslation = 19,
  kSuccessFromAutomaticTranslationToPredefinedTarget = 20,
  kRevertedAutomaticTranslationToPredefinedTarget = 21,
  kFailedWithNoErrorAutomaticTranslationToPredefinedTarget = 22,
  kFailedWithErrorAutomaticTranslationToPredefinedTarget = 23,
  kSuccessFromAutomaticTranslationByHref = 24,
  kRevertedAutomaticTranslationByHref = 25,
  kFailedWithNoErrorAutomaticTranslationByHref = 26,
  kFailedWithErrorAutomaticTranslationByHref = 27,
  kMaxValue = kFailedWithErrorAutomaticTranslationByHref,
};

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class TranslationType {
  kUninitialized = 0,
  // kManualInitialTranslation = 1,  // no longer used, split into
  // kManualUiInitialTranslation and kManualContextMenuInitialTranslation
  // kManualReTranslation = 2,  // no longer used, split into
  // kManualUiReTranslation and kManualContextMenuReTranslation
  kAutomaticTranslationByPref = 3,
  kAutomaticTranslationByLink = 4,
  kManualUiInitialTranslation = 5,
  kManualUiReTranslation = 6,
  kManualContextMenuInitialTranslation = 7,
  kManualContextMenuReTranslation = 8,
  kAutomaticTranslationToPredefinedTarget = 9,
  kAutomaticTranslationByHref = 10,
  kMaxValue = kAutomaticTranslationByHref,
};

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class TriggerDecision {
  kUninitialized = 0,
  kDisabledDoesntNeedTranslation = 1,
  kDisabledTranslationFeatureDisabled = 2,
  kDisabledOffline = 3,
  kDisabledMissingAPIKey = 4,
  kDisabledMIMETypeNotSupported = 5,
  kDisabledURLNotSupported = 6,
  kDisabledNeverOfferTranslations = 7,
  kDisabledSimilarLanguages = 8,
  kDisabledUnsupportedLanguage = 9,
  kDisabledNeverTranslateLanguage = 10,
  kDisabledNeverTranslateSite = 11,
  kDisabledByRanker = 12,
  kShowUI = 13,
  kAutomaticTranslationByLink = 14,
  kAutomaticTranslationByPref = 15,
  kShowUIFromHref = 16,
  kAutomaticTranslationByHref = 17,
  kAutomaticTranslationToPredefinedTarget = 18,
  kShowIcon = 19,
  kDisabledMatchesPreviousLanguage = 20,
  kMaxValue = kDisabledMatchesPreviousLanguage,
};

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused. Keep in sync with
// |TranslateUIInteraction| in translate/enums.xml.
enum class UIInteraction {
  kUninitialized = 0,
  kTranslate = 1,
  kRevert = 2,
  // kAlwaysTranslateLanguage = 3, // no longer used, split into
  // kAddAlwaysTranslateLanguage and kRemoveAlwaysTranslateLanguage
  kChangeSourceLanguage = 4,
  kChangeTargetLanguage = 5,
  // kNeverTranslateLanguage = 6, // no longer used, split into
  // kAddNeverTranslateLanguage and kRemoveNeverTranslateLanguage
  // kNeverTranslateSite = 7, // no longer used, split into
  // kAddNeverTranslateSite and kRemoveNeverTranslateSite
  kCloseUIExplicitly = 8,
  kCloseUILostFocus = 9,
  kCloseUITimerRanOut = 10,
  kAddAlwaysTranslateLanguage = 11,
  kRemoveAlwaysTranslateLanguage = 12,
  kAddNeverTranslateLanguage = 13,
  kRemoveNeverTranslateLanguage = 14,
  kAddNeverTranslateSite = 15,
  kRemoveNeverTranslateSite = 16,
  kOpenLanguageSettings = 17,
  kMaxValue = kOpenLanguageSettings,
};

// TranslateMetricsLogger tracks and logs various UKM and UMA metrics for Chrome
// Translate over the course of a page load.
class TranslateMetricsLogger {
 public:
  TranslateMetricsLogger() = default;
  virtual ~TranslateMetricsLogger() = default;

  TranslateMetricsLogger(const TranslateMetricsLogger&) = delete;
  TranslateMetricsLogger& operator=(const TranslateMetricsLogger&) = delete;

  // Tracks the state of the page over the course of a page load.
  virtual void OnPageLoadStart(bool is_foreground) = 0;
  virtual void OnForegroundChange(bool is_foreground) = 0;

  // Logs all stored page load metrics. If is_final is |true| then RecordMetrics
  // won't be called again.
  virtual void RecordMetrics(bool is_final) = 0;

  // Sets the UKM source ID for the current page load.
  virtual void SetUkmSourceId(ukm::SourceId ukm_source_id) = 0;

  // Tracks information about the Translate Ranker.
  virtual void LogRankerMetrics(RankerDecision ranker_decision,
                                uint32_t ranker_version) = 0;
  virtual void LogRankerStart() = 0;
  virtual void LogRankerFinish() = 0;

  // Records trigger decision that impacts the initial state of Translate. The
  // highest priority trigger decision will be logged to UMA at the end of the
  // page load.
  virtual void LogTriggerDecision(TriggerDecision trigger_decision) = 0;

  // Tracks the state of Translate over the course of the page load.
  virtual void LogInitialState() = 0;
  virtual void LogTranslationStarted(TranslationType translation_type) = 0;
  virtual void LogTranslationFinished(bool was_successful,
                                      TranslateErrors error_type) = 0;
  virtual void LogReversion() = 0;
  virtual void LogUIChange(bool is_ui_shown) = 0;
  virtual void LogOmniboxIconChange(bool is_omnibox_icon_show) = 0;

  // Used to record the source language and target language both initially and
  // if the user changes these values.
  virtual void LogInitialSourceLanguage(const std::string& source_language_code,
                                        bool is_in_users_content_language) = 0;
  virtual void LogSourceLanguage(const std::string& source_language_code) = 0;
  virtual void LogTargetLanguage(
      const std::string& target_language_code,
      TranslateBrowserMetrics::TargetLanguageOrigin target_language_origin) = 0;

  // Used to record the language attributes specified by the HTML document.
  // Recorded for each language detection.
  virtual void LogHTMLDocumentLanguage(
      const std::string& html_doc_language) = 0;
  virtual void LogHTMLContentLanguage(
      const std::string& html_content_language) = 0;

  // Used to record the language detection model's prediction and reliability
  // based on the page content's text. Recorded for each language detection.
  virtual void LogDetectedLanguage(const std::string& detected_language) = 0;
  virtual void LogDetectionReliabilityScore(
      const float& model_detection_reliability_score) = 0;

  // Records the user's high level interactions with the Translate UI.
  virtual void LogUIInteraction(UIInteraction ui_interaction) = 0;

  // Returns the translation type of the next manual translation.
  virtual TranslationType GetNextManualTranslationType(
      bool is_context_menu_initiated_translation) = 0;

  virtual void SetHasHrefTranslateTarget(bool has_href_translate_target) = 0;

  // Records whether the page content used to detect the page language
  // was empty or not.
  virtual void LogWasContentEmpty(bool was_content_empty) = 0;
};

}  // namespace translate

#endif  // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_METRICS_LOGGER_H_