Fix emulator build error
[platform/framework/web/chromium-efl.git] / components / permissions / permission_uma_util.h
1 // Copyright 2014 The Chromium Authors
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_PERMISSIONS_PERMISSION_UMA_UTIL_H_
6 #define COMPONENTS_PERMISSIONS_PERMISSION_UMA_UTIL_H_
7
8 #include <vector>
9
10 #include "base/memory/raw_ptr.h"
11 #include "base/time/time.h"
12 #include "base/version.h"
13 #include "components/content_settings/core/browser/host_content_settings_map.h"
14 #include "components/content_settings/core/common/content_settings_types.h"
15 #include "components/permissions/permission_request.h"
16 #include "components/permissions/prediction_service/prediction_service_messages.pb.h"
17 #include "components/permissions/request_type.h"
18 #include "content/public/browser/permission_result.h"
19 #include "third_party/abseil-cpp/absl/types/optional.h"
20 #include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-forward.h"
21
22 namespace blink {
23 enum class PermissionType;
24 }
25
26 namespace content {
27 class BrowserContext;
28 class RenderFrameHost;
29 class WebContents;
30 class RenderFrameHost;
31 }  // namespace content
32
33 class GURL;
34
35 namespace permissions {
36 enum class PermissionRequestGestureType;
37 enum class PermissionAction;
38 class PermissionRequest;
39
40 // Used for UMA to record the types of permission prompts shown.
41 // When updating, you also need to update:
42 //   1) The PermissionRequestType enum in tools/metrics/histograms/enums.xml.
43 //   2) The PermissionRequestTypes suffix list in
44 //      tools/metrics/histograms/metadata/histogram_suffixes_list.xml.
45 //   3) GetPermissionRequestString below.
46 //
47 // The usual rules of updating UMA values applies to this enum:
48 // - don't remove values
49 // - only ever add values at the end
50 enum class RequestTypeForUma {
51   UNKNOWN = 0,
52   MULTIPLE = 1,
53   // UNUSED_PERMISSION = 2,
54   QUOTA = 3,
55   DOWNLOAD = 4,
56   // MEDIA_STREAM = 5,
57   REGISTER_PROTOCOL_HANDLER = 6,
58   PERMISSION_GEOLOCATION = 7,
59   PERMISSION_MIDI_SYSEX = 8,
60   PERMISSION_NOTIFICATIONS = 9,
61   PERMISSION_PROTECTED_MEDIA_IDENTIFIER = 10,
62   // PERMISSION_PUSH_MESSAGING = 11,
63   PERMISSION_FLASH = 12,
64   PERMISSION_MEDIASTREAM_MIC = 13,
65   PERMISSION_MEDIASTREAM_CAMERA = 14,
66   PERMISSION_ACCESSIBILITY_EVENTS = 15,
67   // PERMISSION_CLIPBOARD_READ = 16, // Replaced by
68   // PERMISSION_CLIPBOARD_READ_WRITE in M81.
69   // PERMISSION_SECURITY_KEY_ATTESTATION = 17,
70   PERMISSION_PAYMENT_HANDLER = 18,
71   PERMISSION_NFC = 19,
72   PERMISSION_CLIPBOARD_READ_WRITE = 20,
73   PERMISSION_VR = 21,
74   PERMISSION_AR = 22,
75   PERMISSION_STORAGE_ACCESS = 23,
76   PERMISSION_CAMERA_PAN_TILT_ZOOM = 24,
77   PERMISSION_WINDOW_MANAGEMENT = 25,
78   PERMISSION_LOCAL_FONTS = 26,
79   PERMISSION_IDLE_DETECTION = 27,
80   PERMISSION_FILE_HANDLING = 28,
81   // PERMISSION_U2F_API_REQUEST = 29,
82   PERMISSION_TOP_LEVEL_STORAGE_ACCESS = 30,
83   PERMISSION_MIDI = 31,
84   PERMISSION_FILE_SYSTEM_ACCESS = 32,
85   // NUM must be the last value in the enum.
86   NUM
87 };
88
89 // Any new values should be inserted immediately prior to NUM.
90 enum class PermissionSourceUI {
91   // Permission prompt.
92   PROMPT = 0,
93
94   // Origin info bubble.
95   // https://www.chromium.org/Home/chromium-security/enamel/goals-for-the-origin-info-bubble
96   OIB = 1,
97
98   // chrome://settings/content/siteDetails?site=[SITE]
99   // chrome://settings/content/[PERMISSION TYPE]
100   SITE_SETTINGS = 2,
101
102   // Page action bubble.
103   PAGE_ACTION = 3,
104
105   // Permission settings from Android.
106   // Currently this value is only used when revoking notification permission in
107   // Android O+ system channel settings.
108   ANDROID_SETTINGS = 4,
109
110   // Permission settings as part of the event's UI.
111   // Currently this value is only used when revoking notification permission
112   // through the notification UI.
113   INLINE_SETTINGS = 5,
114
115   // Permission settings changes as part of the abusive origins revocation.
116   AUTO_REVOCATION = 6,
117
118   // Always keep this at the end.
119   NUM,
120 };
121
122 // Any new values should be inserted immediately prior to NUM.
123 enum class PermissionEmbargoStatus {
124   NOT_EMBARGOED = 0,
125   // Removed: PERMISSIONS_BLACKLISTING = 1,
126   REPEATED_DISMISSALS = 2,
127   REPEATED_IGNORES = 3,
128   RECENT_DISPLAY = 4,
129
130   // Keep this at the end.
131   NUM,
132 };
133
134 // Used for UMA to record the strict level of permission policy which is
135 // configured to allow sub-frame origin. Any new values should be inserted
136 // immediately prior to NUM. All values here should have corresponding entries
137 // PermissionsPolicyConfiguration area of enums.xml.
138 enum class PermissionHeaderPolicyForUMA {
139   // No (or an invalid) Permissions-Policy header was present, results in an
140   // empty features list. It indicates none security-awareness of permissions
141   // policy configuration.
142   HEADER_NOT_PRESENT_OR_INVALID = 0,
143
144   // Permissions-Policy header was present, but it did not define an allowlist
145   // for the feature. It indicates less security-awareness of permissions policy
146   // configuration.
147   FEATURE_NOT_PRESENT = 1,
148
149   // The sub-frame origin is included in allow-list of permission
150   // policy. This indicates a good policy configuration.
151   FEATURE_ALLOWLIST_EXPLICITLY_MATCHES_ORIGIN = 2,
152
153   // Granted by setting value of permission policy to '*'. This also
154   // indicates a bad policy configuration.
155   FEATURE_ALLOWLIST_IS_WILDCARD = 3,
156
157   // The Permissions-Policy header was present and defined an empty
158   // allowlist for the feature. The feature will be disabled everywhere.
159   FEATURE_ALLOWLIST_IS_NONE = 4,
160
161   // The sub-frame origin is not explicitly declared in allow-list of top level
162   // permission policy. It generally indicates less security-awareness of
163   // policy configuration.
164   FEATURE_ALLOWLIST_DOES_NOT_MATCH_ORIGIN = 5,
165
166   // Always keep this at the end.
167   NUM,
168 };
169
170 // The kind of permission prompt UX used to surface a permission request.
171 // Enum used in UKMs and UMAs, do not re-order or change values. Deprecated
172 // items should only be commented out. New items should be added at the end,
173 // and the "PermissionPromptDisposition" histogram suffix needs to be updated to
174 // match (tools/metrics/histograms/metadata/histogram_suffixes_list.xml).
175 enum class PermissionPromptDisposition {
176   // Not all permission actions will have an associated permission prompt (e.g.
177   // changing permission via the settings page).
178   NOT_APPLICABLE = 0,
179
180   // Only used on desktop, a bubble under the site settings padlock.
181   ANCHORED_BUBBLE = 1,
182
183   // Only used on desktop, a static indicator on the right-hand side of the
184   // location bar.
185   LOCATION_BAR_RIGHT_STATIC_ICON = 2,
186
187   // Only used on desktop, an animated indicator on the right-hand side of the
188   // location bar.
189   LOCATION_BAR_RIGHT_ANIMATED_ICON = 3,
190
191   // Only used on Android, a modal dialog.
192   MODAL_DIALOG = 4,
193
194   // Only used on Android, an initially-collapsed infobar at the bottom of the
195   // page.
196   MINI_INFOBAR = 5,
197
198   // Only used on desktop, a chip on the left-hand side of the location bar that
199   // shows a bubble when clicked.
200   LOCATION_BAR_LEFT_CHIP = 6,
201
202   // There was no UI being shown. This is usually because the user closed an
203   // inactive tab that had a pending permission request.
204   NONE_VISIBLE = 7,
205
206   // Other custom modal dialogs.
207   CUSTOM_MODAL_DIALOG = 8,
208
209   // Only used on desktop, a less prominent version of chip on the left-hand
210   // side of the location bar that shows a bubble when clicked.
211   LOCATION_BAR_LEFT_QUIET_CHIP = 9,
212
213   // Only used on Android, a message bubble near top of the screen and below the
214   // location bar. Message UI is an alternative UI to infobar UI.
215   MESSAGE_UI = 10,
216
217   // Only used on desktop, a chip on the left-hand side of the location bar that
218   // automatically shows a bubble.
219   LOCATION_BAR_LEFT_QUIET_ABUSIVE_CHIP = 11,
220
221   // Only used on desktop, a chip on the left-hand side of the location bar that
222   // automatically shows a bubble.
223   LOCATION_BAR_LEFT_CHIP_AUTO_BUBBLE = 12,
224
225   // Only used on desktop, a bubble shown near the embedded permission element,
226   // after the user clicks on the element.
227   ELEMENT_ANCHORED_BUBBLE = 13,
228 };
229
230 // The reason why the permission prompt disposition was used. Enum used in UKMs,
231 // do not re-order or change values. Deprecated items should only be commented
232 // out.
233 enum class PermissionPromptDispositionReason {
234   // Disposition was selected in prefs.
235   USER_PREFERENCE_IN_SETTINGS = 0,
236
237   // Disposition was chosen because Safe Browsing classifies the origin
238   // as being spammy or abusive with permission requests.
239   SAFE_BROWSING_VERDICT = 1,
240
241   // Disposition was chosen based on grant likelihood predicted by the
242   // Web Permission Prediction Service.
243   PREDICTION_SERVICE = 2,
244
245   // Disposition was used as a fallback, if no selector made a decision.
246   DEFAULT_FALLBACK = 3,
247
248   // Disposition was chosen based on grant likelihood predicted by the On-Device
249   // Permission Prediction Model.
250   ON_DEVICE_PREDICTION_MODEL = 4,
251 };
252
253 enum class AdaptiveTriggers {
254   // None of the adaptive triggers were met. Currently this means two or less
255   // consecutive denies in a row.
256   NONE = 0,
257
258   // User denied permission prompt 3 or more times.
259   THREE_CONSECUTIVE_DENIES = 0x01,
260 };
261
262 // These values are logged to UMA. Entries should not be renumbered and
263 // numeric values should never be reused. Please keep in sync with
264 // "OneTimePermissionEvent" in tools/metrics/histograms/enums.xml.
265 enum class OneTimePermissionEvent {
266   // Recorded for each one time grant
267   GRANTED_ONE_TIME = 0,
268
269   // Recorded when the user manually revokes a one time grant
270   REVOKED_MANUALLY = 1,
271
272   // Recorded when a one time grant expires because all tabs are either closed
273   // or discarded.
274   ALL_TABS_CLOSED_OR_DISCARDED = 2,
275
276   // Recorded when a one time grant expires because the permission was unused in
277   // the background.
278   EXPIRED_IN_BACKGROUND = 3,
279
280   // Revoked because of the maximum one time permission lifetime
281   // `kOneTimePermissionMaximumLifetime`
282   EXPIRED_AFTER_MAXIMUM_LIFETIME = 4,
283
284   // Recorded when a one time grant expires because the device was suspended.
285   EXPIRED_ON_SUSPEND = 5,
286
287   kMaxValue = EXPIRED_ON_SUSPEND
288 };
289
290 enum class PermissionAutoRevocationHistory {
291   // Permission has not been automatically revoked.
292   NONE = 0,
293
294   // Permission has been automatically revoked.
295   PREVIOUSLY_AUTO_REVOKED = 0x01,
296 };
297
298 // This enum backs up the `AutoDSEPermissionRevertTransition` histogram enum.
299 // Never reuse values and mirror any updates to it.
300 // Describes the transition that has occured for the setting of a DSE origin
301 // when DSE autogrant becomes disabled.
302 enum class AutoDSEPermissionRevertTransition {
303   // The user has not previously made any decision so it results in an `ASK` end
304   // state.
305   NO_DECISION_ASK = 0,
306   // The user has decided to `ALLOW` the origin before it was the DSE origin and
307   // has not reverted this decision.
308   PRESERVE_ALLOW = 1,
309   // The user has previously `BLOCKED` the origin but has allowed it after it
310   // became the DSE origin. Resolve the conflict by setting it to `ASK` so the
311   // user will make a decision again.
312   CONFLICT_ASK = 2,
313   // The user has blocked the DSE origin and has not made a previous decision
314   // before the origin became the DSE origin.
315   PRESERVE_BLOCK_ASK = 3,
316   // The user has blocked the DSE origin and has `ALLOWED` it before it became
317   // the DSE origin, preserve the latest decision.
318   PRESERVE_BLOCK_ALLOW = 4,
319   // The user has blocked the DSE origin and has `BLOCKED` it before it became
320   // the DSE origin as well.
321   PRESERVE_BLOCK_BLOCK = 5,
322   // There has been an invalid transition.
323   INVALID_END_STATE = 6,
324
325   // Always keep at the end.
326   kMaxValue = INVALID_END_STATE,
327 };
328
329 // This enum backs up the 'PermissionPredictionSource` histogram enum. It
330 // indicates whether the permission prediction was done by the local on device
331 // model or by the server side model.
332 enum class PermissionPredictionSource {
333   ON_DEVICE = 0,
334   SERVER_SIDE = 1,
335
336   // Always keep at the end.
337   kMaxValue = SERVER_SIDE,
338 };
339
340 // This enum backs up the 'PageInfoDialogAccessType' histogram enum.
341 // It is used for collecting page info access type metrics in the context of
342 // the confirmation chip.
343 enum class PageInfoDialogAccessType {
344   // The user opened page info by clicking on the lock in a situation that is
345   // considered independent of the display of a confirmation chip.
346   LOCK_CLICK = 0,
347   // The user opened page info by clicking on the lock while a confirmation chip
348   // was being displayed.
349   LOCK_CLICK_DURING_CONFIRMATION_CHIP = 1,
350   // The user opened page info by clicking on the confirmation chip while it was
351   // being displayed.
352   CONFIRMATION_CHIP_CLICK = 2,
353
354   // The user opened page info by clicking on the lock within
355   // 'kConfirmationConsiderationDurationForUma' after confirmation chip has
356   // collapsed. This click may be considered influenced by the displaying of the
357   // confirmation chip.
358   LOCK_CLICK_SHORTLY_AFTER_CONFIRMATION_CHIP = 3,
359
360   // Always keep at the end.
361   kMaxValue = LOCK_CLICK_SHORTLY_AFTER_CONFIRMATION_CHIP
362 };
363
364 constexpr auto kConfirmationConsiderationDurationForUma = base::Seconds(20);
365
366 // This enum backs up the
367 // 'Permissions.PageInfo.ChangedWithin1m.{PermissionType}' histograms enum. It
368 // is used for collecting page info permission change metrics following in the
369 // first minute after a PermissionAction has been taken. Note that
370 // PermissionActions  DISMISSED and IGNORED are not taken into account, as they
371 // don't have an effect on the content settings.
372 enum class PermissionChangeAction {
373   // PermissionAction was one of {GRANTED, GRANTED_ONCE} and the content
374   // setting is changed to CONTENT_SETTING_BLOCK.
375   REVOKED = 0,
376
377   // PermissionAction was DENIED and the content setting is changed to
378   // CONTENT_SETTING_ALLOW.
379   REALLOWED = 1,
380
381   // PermissionAction was one of {GRANTED, GRANTED_ONCE} and the content setting
382   // is changed to CONTENT_SETTING_DEFAULT.
383   RESET_FROM_ALLOWED = 2,
384
385   // PermissionAction was DENIED and the content setting is changed to
386   // CONTENT_SETTING_DEFAULT.
387   RESET_FROM_DENIED = 3,
388
389   // For one time grantable permissions, the user can toggle a remember checkbox
390   // in the secondary page info page which toggles grants between permanent
391   // grant and one time grant.
392   REMEMBER_CHECKBOX_TOGGLED = 4,
393
394   // Always keep at the end.
395   kMaxValue = REMEMBER_CHECKBOX_TOGGLED
396 };
397
398 // The reason the permission action `PermissionAction::IGNORED` was triggered.
399 enum class PermissionIgnoredReason {
400   // Ignore was triggered due to closure of the browser window
401   WINDOW_CLOSED = 0,
402
403   // Ignore was triggered due to closure of the tab
404   TAB_CLOSED = 1,
405
406   // Ignore was triggered due to navigation
407   NAVIGATION = 2,
408
409   // Catches all other cases
410   UNKNOWN = 3,
411
412   // Always keep at the end
413   NUM
414 };
415
416 // This enum backs up the
417 // 'Permissions.PageInfo.Changed.{PermissionType}.Reallowed.Outcome' histograms
418 // enum. It is used for collecting permission usage rates after permission
419 // status was reallowed via PageInfo. It is applicable only if permission is
420 // allowed as all other states are no-op for an origin.
421 //
422 // These values are persisted to logs. Entries should not be renumbered and
423 // numeric values should never be reused.
424 enum class PermissionChangeInfo {
425   kInfobarShownPageReloadPermissionUsed = 0,
426
427   kInfobarShownPageReloadPermissionNotUsed = 1,
428
429   kInfobarShownNoPageReloadPermissionUsed = 2,
430
431   kInfobarShownNoPageReloadPermissionNotUsed = 3,
432
433   kInfobarNotShownPageReloadPermissionUsed = 4,
434
435   kInfobarNotShownPageReloadPermissionNotUsed = 5,
436
437   kInfobarNotShownNoPageReloadPermissionUsed = 6,
438
439   kInfobarNotShownNoPageReloadPermissionNotUsed = 7,
440
441   // Always keep at the end.
442   kMaxValue = kInfobarNotShownNoPageReloadPermissionNotUsed
443 };
444
445 // Provides a convenient way of logging UMA for permission related operations.
446 class PermissionUmaUtil {
447  public:
448   using PredictionGrantLikelihood =
449       PermissionPrediction_Likelihood_DiscretizedLikelihood;
450
451   static const char kPermissionsPromptShown[];
452   static const char kPermissionsPromptShownGesture[];
453   static const char kPermissionsPromptShownNoGesture[];
454   static const char kPermissionsPromptAccepted[];
455   static const char kPermissionsPromptAcceptedGesture[];
456   static const char kPermissionsPromptAcceptedNoGesture[];
457   static const char kPermissionsPromptAcceptedOnce[];
458   static const char kPermissionsPromptAcceptedOnceGesture[];
459   static const char kPermissionsPromptAcceptedOnceNoGesture[];
460   static const char kPermissionsPromptDenied[];
461   static const char kPermissionsPromptDeniedGesture[];
462   static const char kPermissionsPromptDeniedNoGesture[];
463
464   static const char kPermissionsExperimentalUsagePrefix[];
465   static const char kPermissionsActionPrefix[];
466
467   PermissionUmaUtil() = delete;
468   PermissionUmaUtil(const PermissionUmaUtil&) = delete;
469   PermissionUmaUtil& operator=(const PermissionUmaUtil&) = delete;
470
471   static void PermissionRequested(ContentSettingsType permission);
472
473   static void RecordPermissionRequestedFromFrame(
474       ContentSettingsType content_settings_type,
475       content::RenderFrameHost* rfh);
476
477   static void PermissionRequestPreignored(blink::PermissionType permission);
478
479   // Records the revocation UMA and UKM metrics for ContentSettingsTypes that
480   // have user facing permission prompts. The passed in `permission` must be
481   // such that PermissionUtil::IsPermission(permission) returns true.
482   static void PermissionRevoked(ContentSettingsType permission,
483                                 PermissionSourceUI source_ui,
484                                 const GURL& revoked_origin,
485                                 content::BrowserContext* browser_context);
486
487   static void RecordEmbargoPromptSuppression(
488       PermissionEmbargoStatus embargo_status);
489
490   static void RecordEmbargoPromptSuppressionFromSource(
491       content::PermissionStatusSource source);
492
493   static void RecordEmbargoStatus(PermissionEmbargoStatus embargo_status);
494
495   static void RecordPermissionRecoverySuccessRate(
496       ContentSettingsType permission,
497       bool is_used,
498       bool show_infobar,
499       bool page_reload);
500
501   // Recorded when a permission prompt creation is in progress.
502   static void RecordPermissionPromptAttempt(
503       const std::vector<PermissionRequest*>& requests,
504       bool IsLocationBarEditingOrEmpty);
505
506   // UMA specifically for when permission prompts are shown. This should be
507   // roughly equivalent to the metrics above, however it is
508   // useful to have separate UMA to a few reasons:
509   // - to account for, and get data on coalesced permission bubbles
510   // - there are other types of permissions prompts (e.g. download limiting)
511   //   which don't go through PermissionContext
512   // - the above metrics don't always add up (e.g. sum of
513   //   granted+denied+dismissed+ignored is not equal to requested), so it is
514   //   unclear from those metrics alone how many prompts are seen by users.
515   static void PermissionPromptShown(
516       const std::vector<PermissionRequest*>& requests);
517
518   static void PermissionPromptResolved(
519       const std::vector<PermissionRequest*>& requests,
520       content::WebContents* web_contents,
521       PermissionAction permission_action,
522       base::TimeDelta time_to_decision,
523       PermissionPromptDisposition ui_disposition,
524       absl::optional<PermissionPromptDispositionReason> ui_reason,
525       absl::optional<PredictionGrantLikelihood> predicted_grant_likelihood,
526       absl::optional<bool> prediction_decision_held_back,
527       absl::optional<permissions::PermissionIgnoredReason> ignored_reason,
528       bool did_show_prompt,
529       bool did_click_manage,
530       bool did_click_learn_more);
531
532   static void RecordInfobarDetailsExpanded(bool expanded);
533
534   static void RecordCrowdDenyDelayedPushNotification(base::TimeDelta delay);
535
536   static void RecordCrowdDenyVersionAtAbuseCheckTime(
537       const absl::optional<base::Version>& version);
538
539   // Record UMAs related to the Android "Missing permissions" infobar.
540   static void RecordMissingPermissionInfobarShouldShow(
541       bool should_show,
542       const std::vector<ContentSettingsType>& content_settings_types);
543   static void RecordMissingPermissionInfobarAction(
544       PermissionAction action,
545       const std::vector<ContentSettingsType>& content_settings_types);
546
547   static void RecordPermissionUsage(ContentSettingsType permission_type,
548                                     content::BrowserContext* browser_context,
549                                     content::WebContents* web_contents,
550                                     const GURL& requesting_origin);
551
552   static void RecordTimeElapsedBetweenGrantAndUse(ContentSettingsType type,
553                                                   base::TimeDelta delta);
554
555   static void RecordTimeElapsedBetweenGrantAndRevoke(ContentSettingsType type,
556                                                      base::TimeDelta delta);
557
558   static void RecordAutoDSEPermissionReverted(
559       ContentSettingsType permission_type,
560       ContentSetting backed_up_setting,
561       ContentSetting effective_setting,
562       ContentSetting end_state_setting);
563
564   static void RecordDSEEffectiveSetting(ContentSettingsType permission_type,
565                                         ContentSetting setting);
566
567   static void RecordPermissionPredictionSource(
568       PermissionPredictionSource prediction_type);
569
570   static void RecordPermissionPredictionServiceHoldback(
571       RequestType request_type,
572       bool is_on_device,
573       bool is_heldback);
574
575   static void RecordPageInfoDialogAccessType(
576       PageInfoDialogAccessType access_type);
577
578   static std::string GetOneTimePermissionEventHistogram(
579       ContentSettingsType type);
580
581   static void RecordOneTimePermissionEvent(ContentSettingsType type,
582                                            OneTimePermissionEvent event);
583
584   static void RecordPageInfoPermissionChangeWithin1m(
585       ContentSettingsType type,
586       PermissionAction previous_action,
587       ContentSetting setting_after);
588
589   static void RecordPageInfoPermissionChange(ContentSettingsType type,
590                                              ContentSetting setting_before,
591                                              ContentSetting setting_after,
592                                              bool suppress_reload_page_bar);
593
594   static std::string GetPermissionActionString(
595       PermissionAction permission_action);
596
597   static std::string GetPromptDispositionString(
598       PermissionPromptDisposition ui_disposition);
599
600   static std::string GetPromptDispositionReasonString(
601       PermissionPromptDispositionReason ui_disposition_reason);
602
603   static std::string GetRequestTypeString(RequestType request_type);
604
605   static bool IsPromptDispositionQuiet(
606       PermissionPromptDisposition prompt_disposition);
607
608   static bool IsPromptDispositionLoud(
609       PermissionPromptDisposition prompt_disposition);
610
611   static void RecordIgnoreReason(
612       const std::vector<PermissionRequest*>& requests,
613       PermissionPromptDisposition prompt_disposition,
614       PermissionIgnoredReason reason);
615
616   // Record metrics related to usage of permissions delegation.
617   static void RecordPermissionsUsageSourceAndPolicyConfiguration(
618       ContentSettingsType content_settings_type,
619       content::RenderFrameHost* render_frame_host);
620
621   static void RecordCrossOriginFrameActionAndPolicyConfiguration(
622       ContentSettingsType content_settings_type,
623       PermissionAction action,
624       content::RenderFrameHost* render_frame_host);
625
626   static void RecordTopLevelPermissionsHeaderPolicyOnNavigation(
627       content::RenderFrameHost* render_frame_host);
628
629   // Logs a metric that captures how long since revocation, due to a site being
630   // considered unused, the user regrants a revoked permission.
631   static void RecordPermissionRegrantForUnusedSites(
632       const GURL& origin,
633       ContentSettingsType request_type,
634       PermissionSourceUI source_ui,
635       content::BrowserContext* browser_context,
636       base::Time current_time);
637
638   static absl::optional<uint32_t> GetDaysSinceUnusedSitePermissionRevocation(
639       const GURL& origin,
640       ContentSettingsType content_settings_type,
641       base::Time current_time,
642       HostContentSettingsMap* hcsm);
643
644   // A scoped class that will check the current resolved content setting on
645   // construction and report a revocation metric accordingly if the revocation
646   // condition is met (from ALLOW to something else).
647   class ScopedRevocationReporter {
648    public:
649     ScopedRevocationReporter(content::BrowserContext* browser_context,
650                              const GURL& primary_url,
651                              const GURL& secondary_url,
652                              ContentSettingsType content_type,
653                              PermissionSourceUI source_ui);
654
655     ScopedRevocationReporter(content::BrowserContext* browser_context,
656                              const ContentSettingsPattern& primary_pattern,
657                              const ContentSettingsPattern& secondary_pattern,
658                              ContentSettingsType content_type,
659                              PermissionSourceUI source_ui);
660
661     ~ScopedRevocationReporter();
662
663    private:
664     raw_ptr<content::BrowserContext> browser_context_;
665     const GURL primary_url_;
666     const GURL secondary_url_;
667     ContentSettingsType content_type_;
668     PermissionSourceUI source_ui_;
669     bool is_initially_allowed_;
670     base::Time last_modified_date_;
671   };
672
673  private:
674   friend class PermissionUmaUtilTest;
675
676   // Records UMA and UKM metrics for ContentSettingsTypes that have user facing
677   // permission prompts. The passed in `permission` must be such that
678   // PermissionUtil::IsPermission(permission) returns true.
679   // web_contents may be null when for recording non-prompt actions.
680   static void RecordPermissionAction(
681       ContentSettingsType permission,
682       PermissionAction action,
683       PermissionSourceUI source_ui,
684       PermissionRequestGestureType gesture_type,
685       base::TimeDelta time_to_decision,
686       PermissionPromptDisposition ui_disposition,
687       absl::optional<PermissionPromptDispositionReason> ui_reason,
688       const GURL& requesting_origin,
689       content::WebContents* web_contents,
690       content::BrowserContext* browser_context,
691       content::RenderFrameHost* render_frame_host,
692       absl::optional<PredictionGrantLikelihood> predicted_grant_likelihood,
693       absl::optional<bool> prediction_decision_held_back);
694
695   // Records |count| total prior actions for a prompt of type |permission|
696   // for a single origin using |prefix| for the metric.
697   static void RecordPermissionPromptPriorCount(ContentSettingsType permission,
698                                                const std::string& prefix,
699                                                int count);
700
701   static void RecordPromptDecided(
702       const std::vector<PermissionRequest*>& requests,
703       bool accepted,
704       bool is_one_time);
705 };
706
707 }  // namespace permissions
708
709 #endif  // COMPONENTS_PERMISSIONS_PERMISSION_UMA_UTIL_H_