summaryrefslogtreecommitdiff
path: root/chromium/components/autofill_assistant/browser/metrics.h
blob: 2751120a1cddc804c4f972b6ffacce9896ef296a (plain)
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
// Copyright 2019 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_AUTOFILL_ASSISTANT_BROWSER_METRICS_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_METRICS_H_

#include <iosfwd>
#include <string>

#include "components/autofill_assistant/browser/service.pb.h"
#include "components/autofill_assistant/core/public/autofill_assistant_intent.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace base {
class TimeDelta;
}

namespace ukm {
class UkmRecorder;
}

namespace autofill_assistant {

enum class StartupMode;
class ScriptParameters;
enum TriggerScriptProto_TriggerUIType : int;

// A class to generate Autofill Assistant metrics.
class Metrics {
 public:
  // The different ways that autofill assistant can stop.
  //
  // GENERATED_JAVA_ENUM_PACKAGE: (
  // org.chromium.components.autofill_assistant.metrics)
  // GENERATED_JAVA_CLASS_NAME_OVERRIDE: DropOutReason
  //
  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantDropOutReason enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class DropOutReason {
    AA_START = 0,
    AUTOSTART_TIMEOUT = 1,
    NO_SCRIPTS = 2,
    CUSTOM_TAB_CLOSED = 3,
    DECLINED = 4,
    SHEET_CLOSED = 5,
    SCRIPT_FAILED = 6,
    NAVIGATION = 7,
    OVERLAY_STOP = 8,
    PR_FAILED = 9,
    CONTENT_DESTROYED = 10,
    RENDER_PROCESS_GONE = 11,
    INTERSTITIAL_PAGE = 12,
    SCRIPT_SHUTDOWN = 13,
    SAFETY_NET_TERMINATE = 14,  // This is a "should never happen" entry.
    TAB_DETACHED = 15,
    TAB_CHANGED = 16,
    GET_SCRIPTS_FAILED = 17,
    GET_SCRIPTS_UNPARSABLE = 18,
    NO_INITIAL_SCRIPTS = 19,
    DFM_INSTALL_FAILED = 20,
    DOMAIN_CHANGE_DURING_BROWSE_MODE = 21,
    BACK_BUTTON_CLICKED = 22,
    ONBOARDING_BACK_BUTTON_CLICKED = 23,
    NAVIGATION_WHILE_RUNNING = 24,
    UI_CLOSED_UNEXPECTEDLY = 25,  // This is a "should never happen" entry.
    ONBOARDING_NAVIGATION = 26,
    ONBOARDING_DIALOG_DISMISSED = 27,
    MULTIPLE_AUTOSTARTABLE_SCRIPTS = 28,

    kMaxValue = MULTIPLE_AUTOSTARTABLE_SCRIPTS
  };

  // The different ways to complete the onboarding / user consent screen.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantOnboarding enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class Onboarding {
    // The onboarding was shown to the user.
    OB_SHOWN = 0,
    // The onboarding was not shown to the user, because the user has already
    // accepted the onboarding in a previous flow.
    OB_NOT_SHOWN = 1,
    // The user explicitly accepted the onboarding by tapping the relevant chip.
    OB_ACCEPTED = 2,
    // The user explicitly rejected the onboarding by tapping the relevant chip.
    OB_CANCELLED = 3,
    // The user implicitly rejected the onboarding. Some of the possible reasons
    // include navigating away, tapping the back button, closing the tab, etc.
    OB_NO_ANSWER = 4,
    // The onboarding flow is provided externally.
    OB_EXTERNAL = 5,

    kMaxValue = OB_EXTERNAL
  };

  // The different actions that can be performed on TTS button click.
  //
  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantTextToSpeechButtonAction enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class TtsButtonAction {
    PLAY_TTS = 0,
    DISABLE_BUTTON = 1,
    ENABLE_BUTTON_AND_PLAY_TTS = 2,

    kMaxValue = ENABLE_BUTTON_AND_PLAY_TTS
  };

  // The different TTS engine events that are received by the autofill
  // assistant TTS controller.
  //
  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantTextToSpeechEngineEvent enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class TtsEngineEvent {
    TTS_EVENT_START = 0,
    TTS_EVENT_END = 1,
    TTS_EVENT_ERROR = 2,
    TTS_EVENT_OTHER = 3,

    kMaxValue = TTS_EVENT_OTHER
  };

  // The different ways for payment request to succeed or fail, broken down by
  // whether the PR initially presented to the user was completely pre-filled
  // or not.
  //
  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantPaymentRequestPrefilled enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class PaymentRequestPrefilled {
    // The action finished successfully (the user clicked the "confirm" chip).
    PREFILLED_SUCCESS = 0,
    NOTPREFILLED_SUCCESS = 1,
    // The action finished unsuccessfully.
    PREFILLED_FAILURE = 2,
    NOTPREFILLED_FAILURE = 3,
    // Unknown result, should not happen.
    PREFILLED_UNKNOWN = 4,
    NOTPREFILLED_UNKNOWN = 5,
    // The user clicked the link in the terms and condition text.
    PREFILLED_TERMS_AND_CONDITIONS_LINK_CLICKED = 6,
    NOTPREFILLED_TERMS_AND_CONDITIONS_LINK_CLICKED = 7,
    // The user clicked one of the non-confirm chips.
    PREFILLED_ADDITIONAL_ACTION_SELECTED = 8,
    NOTPREFILLED_ADDITIONAL_ACTION_SELECTED = 9,

    kMaxValue = NOTPREFILLED_ADDITIONAL_ACTION_SELECTED
  };

  // Whether autofill info was changed during an autofill assistant payment
  // request, or not.
  //
  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantPaymentRequestAutofillInfoChanged enum listing
  // in tools/metrics/histograms/enums.xml.
  enum class PaymentRequestAutofillInfoChanged {
    // The action finished successfully (the user clicked the "confirm" chip).
    CHANGED_SUCCESS = 0,
    NOTCHANGED_SUCCESS = 1,
    // The action finished unsuccessfully.
    CHANGED_FAILURE = 2,
    NOTCHANGED_FAILURE = 3,
    // Unknown result, should not happen.
    CHANGED_UNKNOWN = 4,
    NOTCHANGED_UNKNOWN = 5,
    // The user clicked the link in the terms and condition text.
    CHANGED_TERMS_AND_CONDITIONS_LINK_CLICKED = 6,
    NOTCHANGED_TERMS_AND_CONDITIONS_LINK_CLICKED = 7,
    // The user clicked one of the non-confirm chips.
    CHANGED_ADDITIONAL_ACTION_SELECTED = 8,
    NOTCHANGED_ADDITIONAL_ACTION_SELECTED = 9,

    kMaxValue = NOTCHANGED_ADDITIONAL_ACTION_SELECTED
  };

  // Whether a billing postal code was required and whether the user ultimately
  // succeeded or not.
  //
  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantPaymentRequestMandatoryPostalCode enum listing
  // in tools/metrics/histograms/enums.xml.
  // Note: This is deprecated and no longer logged.
  enum class PaymentRequestMandatoryPostalCode {
    REQUIRED_INITIALLY_WRONG_SUCCESS = 0,
    REQUIRED_INITIALLY_WRONG_FAILURE = 1,
    REQUIRED_INITIALLY_RIGHT_SUCCESS = 2,
    REQUIRED_INITIALLY_RIGHT_FAILURE = 3,
    NOT_REQUIRED = 4,

    kMaxValue = NOT_REQUIRED
  };

  // The different ways in which DFM can be installed.
  //
  // GENERATED_JAVA_ENUM_PACKAGE: (
  // org.chromium.components.autofill_assistant.metrics)
  // GENERATED_JAVA_CLASS_NAME_OVERRIDE: FeatureModuleInstallation
  //
  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantFeatureModuleInstallation enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class FeatureModuleInstallation {
    DFM_BACKGROUND_INSTALLATION_REQUESTED = 0,
    DFM_FOREGROUND_INSTALLATION_SUCCEEDED = 1,
    DFM_FOREGROUND_INSTALLATION_FAILED = 2,
    DFM_ALREADY_INSTALLED = 3,

    kMaxValue = DFM_ALREADY_INSTALLED
  };

  // Whether a trigger script was running invisibly or visible to the user.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantTriggerScriptShownToUser enum listing in
  // tools/metrics/histograms/enums.xml and the description in
  // tools/metrics/ukm/ukm.xml as necessary.
  enum class TriggerScriptShownToUser {
    // The number of times a trigger script was successfully fetched and
    // started.
    // Can happen multiple times per run (in case of tab switch).
    RUNNING = 0,
    // The number of times a trigger script was shown to the user. Can happen
    // multiple times per run.
    SHOWN_TO_USER = 1,
    // Since Chrome M-88. The user tapped the 'not now' button. Can happen
    // multiple times per run.
    NOT_NOW = 2,
    // Since Chrome M-88. The trigger script was automatically hidden due to the
    // trigger condition no longer being true. Can happen multiple times per
    // run.
    HIDE_ON_TRIGGER_CONDITION_NO_LONGER_TRUE = 3,
    // Since Chrome M-88. The user swipe-dismissed the bottom sheet. Depending
    // on configuration, this may happen multiple times per run.
    SWIPE_DISMISSED = 4,
    // Since Chrome M-93. The UI has timed out without receiving any user
    // interaction.
    UI_TIMEOUT = 5,

    kMaxValue = UI_TIMEOUT
  };

  // The different ways a user might have opted out of the trigger script
  // experience.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantTriggerScriptStarted enum listing in
  // tools/metrics/histograms/enums.xml and the description in
  // tools/metrics/ukm/ukm.xml as necessary.
  enum class TriggerScriptStarted {
    // Device did not have DFM downloaded.
    DFM_UNAVAILABLE = 0,
    // User has not seen the trigger script before and will see first time
    // experience.
    FIRST_TIME_USER = 3,
    // User has seen the first-time experience before and will see returning
    // user experience.
    RETURNING_USER = 4,
    // Since Chrome M-88. The proactive trigger setting is disabled. The user
    // has either chosen 'never show again' in the prompt or manually disabled
    // the setting in Chrome settings.
    PROACTIVE_TRIGGERING_DISABLED = 5,
    // Since Chrome M-88. Intended as a catch-all. This is reported as soon as a
    // lite-script intent is received (of course, only for people with MSBB
    // enabled).
    INTENT_RECEIVED = 6,
    // Since Chrome M-91. A required Chrome feature was disabled.
    FEATURE_DISABLED = 7,
    // Since Chrome M-91. No initial url was set, neither in ORIGINAL_DEEPLINK
    // nor in the intent data.
    NO_INITIAL_URL = 8,
    // Since Chrome M-91. A mandatory script parameter was missing.
    MANDATORY_PARAMETER_MISSING = 9,
    // Since Chrome M-92. The user never navigated to a different domain.
    NAVIGATED_AWAY = 10,
    // Since Chrome M-92. The navigation to the target domain failed.
    NAVIGATION_ERROR = 11,

    // DEPRECATED, only sent by Chrome M-86 and M-87.
    //
    // User has explicitly rejected the trigger script two times and thus opted
    // out of  the experience.
    CANCELED_TWO_TIMES = 1,
    // User has rejected the onboarding and thus opted out of the experience.
    ONBOARDING_REJECTED = 2,

    kMaxValue = NAVIGATION_ERROR
  };

  // The different ways in which a trigger script may finish.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantTriggerScriptFinished enum listing in
  // tools/metrics/histograms/enums.xml and the description in
  // tools/metrics/ukm/ukm.xml as necessary.
  enum class TriggerScriptFinishedState {
    // Communication with backend failed.
    GET_ACTIONS_FAILED = 3,
    // Failed to parse the proto sent by the backend.
    GET_ACTIONS_PARSE_ERROR = 4,
    // Trigger script failed due to a navigation event to a non-allowed domain.
    PROMPT_FAILED_NAVIGATE = 9,
    // Trigger script succeeded. The user accepted the prompt.
    PROMPT_SUCCEEDED = 13,
    // Since Chrome M-88. The user tapped the 'cancel for this session' button.
    PROMPT_FAILED_CANCEL_SESSION = 14,
    // Since Chrome M-88. The user tapped the 'never show again' button.
    PROMPT_FAILED_CANCEL_FOREVER = 15,
    // Since Chrome M-88. The trigger script has timed out. This indicates that
    // trigger conditions were evaluated for >= timeout without success. Time is
    // only counted while the tab is visible and the trigger script is
    // invisible.
    // The timeout resets on tab change.
    TRIGGER_CONDITION_TIMEOUT = 17,
    // Since Chrome M-88. A navigation error occurred, leading to Chrome showing
    // an error page.
    NAVIGATION_ERROR = 18,
    // Since Chrome M-88. The tab was closed while the prompt was visible.
    WEB_CONTENTS_DESTROYED_WHILE_VISIBLE = 19,
    // Since Chrome M-88. The tab was closed while the prompt was invisible.
    WEB_CONTENTS_DESTROYED_WHILE_INVISIBLE = 20,
    // Since Chrome M-88. The RPC to fetch the trigger scripts returned with an
    // empty response.
    NO_TRIGGER_SCRIPT_AVAILABLE = 21,
    // Since Chrome M-88. The trigger script failed to show. This can happen,
    // for example, if the activity was changed after triggering (e.g.,
    // switching from CCT to regular tab).
    FAILED_TO_SHOW = 22,
    // Since Chrome M-88. The proactive help switch was enabled at start, but
    // then manually disabled in the Chrome settings.
    DISABLED_PROACTIVE_HELP_SETTING = 23,
    // The user rejected the bottom sheet onboarding
    BOTTOMSHEET_ONBOARDING_REJECTED = 25,
    // Transitioning from CCT to regular tab is currently not supported.
    CCT_TO_TAB_NOT_SUPPORTED = 26,
    // The current trigger script was canceled. This typically happens when a
    // new startup request takes precedence.
    CANCELED = 27,

    // NOTE: All values in this block are DEPRECATED and will only be sent by
    // Chrome M-86 and M-87.
    //
    // The trigger script failed for an unknown reason.
    UNKNOWN_FAILURE = 0,
    // Can happen when users close the tab or similar.
    SERVICE_DELETED = 1,
    // |GetActions| was asked to retrieve a wrong script path.
    PATH_MISMATCH = 2,
    // One or multiple unsafe actions were contained in script.
    UNSAFE_ACTIONS = 5,
    // The mini script is invalid. A valid script must contain a prompt
    // (browse=true) action and end in a prompt(browse=false) action.
    INVALID_SCRIPT = 6,
    // The prompt(browse) action failed due to a navigation event to a
    // non-allowed domain.
    BROWSE_FAILED_NAVIGATE = 7,
    // The prompt(browse) action failed for an unknown reason.
    BROWSE_FAILED_OTHER = 8,
    // The prompt(regular) action failed because the condition to show it was no
    // longer true.
    PROMPT_FAILED_CONDITION_NO_LONGER_TRUE = 10,
    // The prompt(regular) action failed because the user tapped the close chip.
    PROMPT_FAILED_CLOSE = 11,
    // The prompt(regular) action failed for an unknown reason.
    PROMPT_FAILED_OTHER = 12,
    // Since Chrome M-88. The bottom sheet was swipe-dismissed by the user.
    PROMPT_SWIPE_DISMISSED = 16,

    // Note: DEPRECATED since M-105
    // Since Chrome M-88. The client failed to base64-decode the trigger script
    // specified in the script parameters.
    BASE64_DECODING_ERROR = 24,

    kMaxValue = CANCELED
  };

  // The different ways a user who has successfully completed a light script may
  // accept or reject the onboarding
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantTriggerScriptOnboarding enum listing in
  // tools/metrics/histograms/enums.xml and the description in
  // tools/metrics/ukm/ukm.xml as necessary.
  enum class TriggerScriptOnboarding {
    // The user has seen and accepted the onboarding.
    ONBOARDING_SEEN_AND_ACCEPTED = 0,
    // The user has seen and rejected the onboarding.
    ONBOARDING_SEEN_AND_REJECTED = 1,
    // The user has already accepted the onboarding in the past.
    ONBOARDING_ALREADY_ACCEPTED = 2,
    // The user has seen and dismissed the onboarding.
    ONBOARDING_SEEN_AND_DISMISSED = 3,
    // The onboarding was interrupted by a website navigation.
    ONBOARDING_SEEN_AND_INTERRUPTED_BY_NAVIGATION = 4,

    kMaxValue = ONBOARDING_SEEN_AND_INTERRUPTED_BY_NAVIGATION
  };

  // Metric describing in-Chrome triggering. Only reported if the corresponding
  // feature is enabled.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantInChromeTriggerAction enum listing in
  // tools/metrics/histograms/enums.xml and the description in
  // tools/metrics/ukm/ukm.xml as necessary.
  enum class InChromeTriggerAction {
    // No trigger script was requested for an unspecified reason. This is
    // intended as a catch-all bucket and should ideally always be empty.
    OTHER = 0,
    // No trigger script was requested because the user has temporarily opted
    // out of receiving implicit prompts for this domain (either until tab close
    // or until the cache entry is stale, whichever is sooner).
    USER_DENYLISTED_DOMAIN = 1,
    // No trigger script was requested because an earlier request to the same
    // domain failed and the cache was still fresh.
    CACHE_HIT_UNSUPPORTED_DOMAIN = 2,
    // No trigger script was requested because the heuristic response did not
    // match any trigger intent.
    NO_HEURISTIC_MATCH = 3,
    // The heuristic reported a match and a trigger script was requested.
    // Note that this does not indicate that a trigger script was fetched
    // successfully, merely that it was requested.
    TRIGGER_SCRIPT_REQUESTED = 4,

    kMaxValue = TRIGGER_SCRIPT_REQUESTED
  };

  // Used for logging when the platform-specific dependencies are invalidated.
  // For example: When the activity is changed on Android.
  //
  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantDependenciesInvalidated enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class DependenciesInvalidated {
    // The dependencies were invalidated while the starter existed but before
    // Start() was called.
    OUTSIDE_FLOW = 0,
    // The dependencies were invalidated while the flow was trying to start. For
    // example during onboarding or during the execution of the trigger script.
    DURING_STARTUP = 1,
    // The dependencies were invalidated during the execution of a flow.
    DURING_FLOW = 2,

    kMaxValue = DURING_FLOW
  };

  // Used for logging the CALLER script parameter.
  //
  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantCaller enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class AutofillAssistantCaller {
    UNKNOWN_CALLER = 0,
    ASSISTANT = 1,
    SEARCH = 2,
    STARTER_APP = 3,
    SEARCH_ADS = 4,
    SHOPPING_PROPERTY = 5,
    EMULATOR = 6,
    // The run was started from within Chrome (e.g., URL heuristic match or
    // password change launched from the settings page).
    IN_CHROME = 7,
    // The run was triggered by the Direction Action API in Chrome.
    DIRECT_ACTION = 8,
    // The run was started by Google Password Manager (passwords.google.com or
    // credential_manager in gmscore module on Android).
    GOOGLE_PASSWORD_MANAGER = 9,

    kMaxValue = GOOGLE_PASSWORD_MANAGER
  };

  // Used for logging the SOURCE script parameter.
  //
  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantSource enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class AutofillAssistantSource {
    UNKNOWN_SOURCE = 0,
    ORGANIC = 1,
    FRESH_DEEPLINK = 2,
    STARTER_APP = 3,
    EMULATOR_VALIDATION = 4,
    S_API = 5,
    C_CARD = 6,
    MD_CARD = 7,
    C_NOTIFICATION = 8,
    G_CAROUSEL = 9,

    kMaxValue = G_CAROUSEL
  };

  // Used for logging active autofill-assistant experiments. This is intended
  // to be a bitmask to support cases where more than one experiment is running.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantExperiment enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class AutofillAssistantExperiment {
    // No experiment is running.
    NO_EXPERIMENT = 0,
    // An unknown experiment is running.
    UNKNOWN_EXPERIMENT = 1,

    kMaxValue = UNKNOWN_EXPERIMENT
  };

  // Used to record successful and failed autofill-assistant startup requests.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantStarted enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class AutofillAssistantStarted {
    FAILED_FEATURE_DISABLED = 0,
    FAILED_MANDATORY_PARAMETER_MISSING = 1,
    FAILED_SETTING_DISABLED = 2,
    FAILED_NO_INITIAL_URL = 3,
    OK_DELAYED_START = 4,
    OK_IMMEDIATE_START = 5,

    kMaxValue = OK_IMMEDIATE_START
  };

  // Used to track what action the user performed on the contact/shipping/card
  // data. Only reported at the end of a CollectUserData action. Reported up to
  // three times for each of contact/shipping/credit card and only if the given
  // entry was requested at that step.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantUserDataSelectionState enum listing in
  // tools/metrics/histograms/enums.xml and the description in
  // tools/metrics/ukm/ukm.xml as necessary.
  enum class UserDataSelectionState {
    // The user kept the initial selection without modifications.
    NO_CHANGE,
    // The user kept the initial selection but edited it.
    EDIT_PRESELECTED,
    // The user changed the selected option.
    SELECTED_DIFFERENT_ENTRY,
    // The user changed the selected option and edited the newly selected entry.
    SELECTED_DIFFERENT_AND_MODIFIED_ENTRY,
    // The user added a new entry.
    NEW_ENTRY,

    kMaxValue = NEW_ENTRY
  };

  // Used to log the initial number of contact/shipping/card entries. Reported
  // at the end of a CollectUserData action.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantUserDataEntryCount enum listing in
  // tools/metrics/histograms/enums.xml and the description in
  // tools/metrics/ukm/ukm.xml as necessary.
  enum class UserDataEntryCount {
    ZERO,
    ONE,
    TWO,
    THREE,
    FOUR,
    FIVE_OR_MORE,

    kMaxValue = FIVE_OR_MORE
  };

  // Whether the CollectUserData action was successfully completed.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantCollectUserDataResult enum listing in
  // tools/metrics/histograms/enums.xml and the description in
  // tools/metrics/ukm/ukm.xml as necessary.
  enum class CollectUserDataResult {
    UNKNOWN,
    // The action finished successfully (the user clicked the "confirm" chip).
    SUCCESS,
    // The action finished unsuccessfully.
    FAILURE,
    // The user clicked the link in the terms and condition text.
    TERMS_AND_CONDITIONS_LINK_CLICKED,
    // The user clicked one of the non-confirm chips.
    ADDITIONAL_ACTION_SELECTED,

    kMaxValue = ADDITIONAL_ACTION_SELECTED
  };

  // The source of the initial data for the current CollectUserData action.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantUserDataSource enum listing in
  // tools/metrics/histograms/enums.xml and the description in
  // tools/metrics/ukm/ukm.xml as necessary.
  enum class UserDataSource {
    UNKNOWN,

    // Only used backend data.
    BACKEND,

    // Only used Chrome Autofill data.
    CHROME_AUTOFILL,

    // Attempted to use backend data but request failed, had to fallback to
    // Chrome Autofill.
    FALLBACK_CHROME_AUTOFILL_ON_FAILED_REQUEST,

    // Use backend data when possible, fallback to Chrome Autofill if
    // not. Fallback was not necessary.
    FALLBACK_BACKEND,

    // Use backend data when possible, fallback to Chrome Autofill if
    // not. Fallback was necessary (backend data was missing).
    FALLBACK_CHROME_AUTOFILL_ON_MISSING_DATA,

    kMaxValue = FALLBACK_CHROME_AUTOFILL_ON_MISSING_DATA
  };

  // Outcome of the CUP verification process for GetAction RPC calls. CUP
  // verification is used to check whether the actions delivered to the client
  // come from a trusted source, and requires the request from the client to be
  // signed first. Events are only recorded for RPC calls where we support CUP.
  //
  // This verification event is recorded after the response is deserialized but
  // before it's actually used in the client. This is the case even if the
  // verification doesn't happen due to the request not being signed in the
  // first place. HTTP failures are checked before the feature flags for
  // signing and verification, and therefore a failing HTTP request with
  // verification disabled will be logged as |HTTP_FAILED|.
  //
  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // CupRpcVerificationEvent enum listing in tools/metrics/histograms/enums.xml.
  enum class CupRpcVerificationEvent {
    // Signature doesn't match response or context, message origin cannot be
    // confirmed.
    VERIFICATION_FAILED = 0,
    // Signature correctly matches the response and context.
    VERIFICATION_SUCCEEDED = 1,
    // Response parsing failed. Rpc verification won't be performed.
    PARSING_FAILED = 2,
    // Response verification is disabled. Rpc verification won't be performed.
    VERIFICATION_DISABLED = 3,
    // Request signing is disabled. Rpc verification won't be performed.
    SIGNING_DISABLED = 4,
    // HTTP call didn't return "OK" 200. Rpc verification won't be performed.
    HTTP_FAILED = 5,
    // Server did not provide a signature. Rpc verification won't be performed.
    EMPTY_SIGNATURE = 6,

    kMaxValue = EMPTY_SIGNATURE
  };

  // Used for bitmasks for the InitialContactFieldsStatus,
  // InitialBillingFieldsStatus and InitialShippingFieldsStatus metrics.
  enum AutofillAssistantProfileFields {
    NAME_FIRST = 1 << 0,
    NAME_LAST = 1 << 1,
    NAME_FULL = 1 << 2,
    EMAIL_ADDRESS = 1 << 3,
    PHONE_HOME_NUMBER = 1 << 4,
    PHONE_HOME_COUNTRY_CODE = 1 << 5,
    PHONE_HOME_WHOLE_NUMBER = 1 << 6,
    ADDRESS_HOME_COUNTRY = 1 << 7,
    ADDRESS_HOME_STATE = 1 << 8,
    ADDRESS_HOME_CITY = 1 << 9,
    ADDRESS_HOME_ZIP = 1 << 10,
    ADDRESS_HOME_LINE1 = 1 << 11,
  };

  enum AutofillAssistantCreditCardFields {
    CREDIT_CARD_NAME_FULL = 1 << 0,
    CREDIT_CARD_EXP_MONTH = 1 << 1,
    CREDIT_CARD_EXP_2_DIGIT_YEAR = 1 << 2,
    CREDIT_CARD_EXP_4_DIGIT_YEAR = 1 << 3,
    MASKED = 1 << 4,
    // If the card is masked, this is always logged as present, to match what
    // CollectUserData considers complete for the purposes of enabling the
    // "Continue" button.
    VALID_NUMBER = 1 << 5,
  };

  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantOnboardingFetcherResultStatus enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class OnboardingFetcherResultStatus {
    kOk = 0,
    // No body was received from the server.
    kNoBody = 1,
    // Parsing the JSON failed.
    kInvalidJson = 1,
    // The JSON was not in the form we expected it to be.
    kInvalidData = 2,
    kMaxValue = kInvalidData
  };

  // Reports notable events that occur before, during or after the execution
  // of a Autofill Assistant JS flow.
  //
  // This enum is used in UKM metrics, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantJsFlowStartedEvent enum listing in
  // tools/metrics/histograms/enums.xml and the description in
  // tools/metrics/histograms/metadata/android/histograms.xml as necessary.
  enum class JsFlowStartedEvent {
    // The JS flow executer was started.
    EXECUTOR_STARTED = 0,
    // A JS flow was attempting to start before the previous one had finished.
    // This is a client bug.
    FAILED_ALREADY_RUNNING = 1,
    // Failed to get the frame tree of the WebContents the JS flow was attached
    // to.
    FAILED_TO_GET_FRAME_TREE = 2,
    // Failed to create the isolated world.
    FAILED_TO_CREATE_ISOLATED_WORLD = 3,
    // The JS flow execution was started.
    SCRIPT_STARTED = 4,

    kMaxValue = SCRIPT_STARTED
  };

  // This enum is used in histograms, do not remove/renumber entries. Only add
  // at the end and update kMaxValue. Also remember to update the
  // AutofillAssistantFlowFinishedState enum listing in
  // tools/metrics/histograms/enums.xml.
  enum class FlowFinishedState {
    UNKNOWN = 0,
    // For now, this means that the script finished successfully, i.e., the
    // script executor returned 'true' as result. This does not mean that the
    // run will be counted towards our backend metrics - it's just an indicator
    // that the script ran until a scripted end.
    SUCCESS = 1,
    // There was a script execution error. This can have a variety of causes
    // such as network outage and many others.
    FAILURE = 2,
    // The controller was destroyed mid-script. Usually, this happens if the
    // tab owning the controller was destroyed, or if the entire activity was
    // closed by the user.
    DESTROYED = 3,
    kMaxValue = DESTROYED
  };

  static void RecordDropOut(DropOutReason reason, const std::string& intent);
  static void RecordPaymentRequestPrefilledSuccess(
      bool initially_complete,
      CollectUserDataResult result);
  static void RecordPaymentRequestAutofillChanged(bool changed,
                                                  CollectUserDataResult result);
  static void RecordCollectUserDataProfileDeduplicationForContact(
      int number_of_profiles_deduplicated_for_contact);
  static void RecordCollectUserDataProfileDeduplicationForAddress(
      int number_of_profiles_deduplicated_for_address);
  static void RecordPaymentRequestFirstNameOnly(bool first_name_only);
  static void RecordTriggerScriptStarted(ukm::UkmRecorder* ukm_recorder,
                                         ukm::SourceId source_id,
                                         TriggerScriptStarted event);
  static void RecordTriggerScriptStarted(ukm::UkmRecorder* ukm_recorder,
                                         ukm::SourceId source_id,
                                         StartupMode startup_mode,
                                         bool feature_module_installed,
                                         bool is_first_time_user);
  static void RecordTriggerScriptFinished(
      ukm::UkmRecorder* ukm_recorder,
      ukm::SourceId source_id,
      TriggerScriptProto_TriggerUIType trigger_ui_type,
      TriggerScriptFinishedState event);
  static void RecordTriggerScriptShownToUser(
      ukm::UkmRecorder* ukm_recorder,
      ukm::SourceId source_id,
      TriggerScriptProto_TriggerUIType trigger_ui_type,
      TriggerScriptShownToUser event);
  static void RecordTriggerScriptOnboarding(
      ukm::UkmRecorder* ukm_recorder,
      ukm::SourceId source_id,
      TriggerScriptProto_TriggerUIType trigger_ui_type,
      TriggerScriptOnboarding event);
  static void RecordRegularScriptOnboarding(ukm::UkmRecorder* ukm_recorder,
                                            ukm::SourceId source_id,
                                            Metrics::Onboarding event);
  static void RecordInChromeTriggerAction(ukm::UkmRecorder* ukm_recorder,
                                          ukm::SourceId source_id,
                                          InChromeTriggerAction event);
  static void RecordTtsButtonAction(TtsButtonAction action);
  static void RecordTtsEngineEvent(TtsEngineEvent event);
  static void RecordFeatureModuleInstallation(FeatureModuleInstallation event);
  static void RecordTriggerConditionEvaluationTime(
      ukm::UkmRecorder* ukm_recorder,
      ukm::SourceId source_id,
      base::TimeDelta evaluation_time);
  static void RecordDependenciesInvalidated(
      DependenciesInvalidated dependencies_invalidated);
  static void RecordStartRequest(ukm::UkmRecorder* ukm_recorder,
                                 ukm::SourceId source_id,
                                 const ScriptParameters& script_parameters,
                                 StartupMode event);
  static void RecordContactMetrics(ukm::UkmRecorder* ukm_recorder,
                                   ukm::SourceId source_id,
                                   int complete_count,
                                   int incomplete_count,
                                   int initially_selected_field_bitmask,
                                   UserDataSelectionState selection_state);
  static void RecordCreditCardMetrics(
      ukm::UkmRecorder* ukm_recorder,
      ukm::SourceId source_id,
      int complete_count,
      int incomplete_count,
      int initially_selected_card_field_bitmask,
      int initially_selected_billing_address_field_bitmask,
      UserDataSelectionState selection_state);
  static void RecordShippingMetrics(ukm::UkmRecorder* ukm_recorder,
                                    ukm::SourceId source_id,
                                    int complete_count,
                                    int incomplete_count,
                                    int initially_selected_field_bitmask,
                                    UserDataSelectionState selection_state);
  static void RecordCollectUserDataSuccess(ukm::UkmRecorder* ukm_recorder,
                                           ukm::SourceId source_id,
                                           CollectUserDataResult result,
                                           int64_t time_taken_ms,
                                           UserDataSource source);
  static void RecordOnboardingFetcherResult(
      OnboardingFetcherResultStatus status);
  static void RecordCupRpcVerificationEvent(CupRpcVerificationEvent event);
  static void RecordJsFlowStartedEvent(JsFlowStartedEvent event);
  static void RecordServiceRequestRetryCount(int count, bool success);
  static void RecordFlowFinished(ukm::UkmRecorder* ukm_recorder,
                                 ukm::SourceId source_id,
                                 FlowFinishedState state,
                                 RoundtripNetworkStats flow_network_stats);

  // Extracts the enum value corresponding to the intent specified in
  // |script_parameters|.
  static AutofillAssistantIntent ExtractIntentFromScriptParameters(
      const ScriptParameters& script_parameters);

  // Intended for debugging: writes string representation of |reason| to
  // |out|.
  friend std::ostream& operator<<(std::ostream& out,
                                  const DropOutReason& reason);

  // Intended for debugging: writes string representation of |metric| to |out|.
  friend std::ostream& operator<<(std::ostream& out, const Onboarding& metric);

  friend std::ostream& operator<<(std::ostream& out,
                                  const TriggerScriptFinishedState& state);
};

}  // namespace autofill_assistant

#endif  // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_METRICS_H_