1 // Copyright 2020 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_METRICS_LOGGER_H_
6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_METRICS_LOGGER_H_
7 
8 #include <stdint.h>
9 
10 namespace translate {
11 
12 // These values are persisted to logs. Entries should not be renumbered and
13 // numeric values should never be reused.
14 enum class RankerDecision {
15   kUninitialized = 0,
16   kNotQueried = 1,
17   kShowUI = 2,
18   kDontShowUI = 3,
19   kMaxValue = kDontShowUI,
20 };
21 
22 // These values are persisted to logs. Entries should not be renumbered and
23 // numeric values should never be reused.
24 enum class TranslateState {
25   kUninitialized = 0,
26   kNotTranslatedNoUI = 1,
27   kNotTranslatedOmniboxIconOnly = 2,
28   kNotTranslatedUIShown = 3,
29   kTranslatedNoUI = 4,
30   kTranslatedOmniboxIconOnly = 5,
31   kTranslatedUIShown = 6,
32   kMaxValue = kTranslatedUIShown,
33 };
34 
35 // These values are persisted to logs. Entries should not be renumbered and
36 // numeric values should never be reused.
37 enum class TriggerDecision {
38   kUninitialized = 0,
39   kDisabledDoesntNeedTranslation = 1,
40   kDisabledTranslationFeatureDisabled = 2,
41   kDisabledOffline = 3,
42   kDisabledMissingAPIKey = 4,
43   kDisabledMIMETypeNotSupported = 5,
44   kDisabledURLNotSupported = 6,
45   kDisabledNeverOfferTranslations = 7,
46   kDisabledSimilarLanguages = 8,
47   kDisabledUnsupportedLanguage = 9,
48   kDisabledNeverTranslateLanguage = 10,
49   kDisabledNeverTranslateSite = 11,
50   kDisabledByRanker = 12,
51   kShowUI = 13,
52   kAutomaticTranslationByLink = 14,
53   kAutomaticTranslationByPref = 15,
54   kMaxValue = kAutomaticTranslationByPref,
55 };
56 
57 // TranslateMetricsLogger tracks and logs various UKM and UMA metrics for Chrome
58 // Translate over the course of a page load.
59 class TranslateMetricsLogger {
60  public:
61   TranslateMetricsLogger() = default;
62   virtual ~TranslateMetricsLogger() = default;
63 
64   TranslateMetricsLogger(const TranslateMetricsLogger&) = delete;
65   TranslateMetricsLogger& operator=(const TranslateMetricsLogger&) = delete;
66 
67   // Tracks the state of the page over the course of a page load.
68   virtual void OnPageLoadStart(bool is_foreground) = 0;
69   virtual void OnForegroundChange(bool is_foreground) = 0;
70 
71   // Logs all stored page load metrics. If is_final is |true| then RecordMetrics
72   // won't be called again.
73   virtual void RecordMetrics(bool is_final) = 0;
74 
75   virtual void LogRankerMetrics(RankerDecision ranker_decision,
76                                 uint32_t ranker_version) = 0;
77 
78   // Records trigger decision that impacts the initial state of Translate. The
79   // highest priority trigger decision will be logged to UMA at the end of the
80   // page load.
81   virtual void LogTriggerDecision(TriggerDecision trigger_decision) = 0;
82   virtual void LogAutofillAssistantDeferredTriggerDecision() = 0;
83 
84   // Tracks the state of Translate over the course of the page load.
85   virtual void LogInitialState() = 0;
86   virtual void LogTranslationStarted() = 0;
87   virtual void LogTranslationFinished(bool was_successful) = 0;
88   virtual void LogReversion() = 0;
89   virtual void LogUIChange(bool is_ui_shown) = 0;
90   virtual void LogOmniboxIconChange(bool is_omnibox_icon_show) = 0;
91 };
92 
93 }  // namespace translate
94 
95 #endif  // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_METRICS_LOGGER_H_
96