Fix emulator build error
[platform/framework/web/chromium-efl.git] / components / permissions / permission_ui_selector.h
1 // Copyright 2019 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_UI_SELECTOR_H_
6 #define COMPONENTS_PERMISSIONS_PERMISSION_UI_SELECTOR_H_
7
8 #include "base/functional/callback_forward.h"
9 #include "components/permissions/permission_request.h"
10 #include "components/permissions/permission_uma_util.h"
11 #include "third_party/abseil-cpp/absl/types/optional.h"
12
13 namespace permissions {
14
15 // The interface for implementations that decide if the quiet prompt UI should
16 // be used to display a permission |request|, whether a warning should be
17 // printed to the Dev Tools console, and the reasons for both.
18 //
19 // Implementations of interface are expected to have long-lived instances that
20 // can support multiple requests, but only one at a time.
21 class PermissionUiSelector {
22  public:
23   enum class QuietUiReason {
24     kEnabledInPrefs,
25     kTriggeredByCrowdDeny,
26     kTriggeredDueToAbusiveRequests,
27     kTriggeredDueToAbusiveContent,
28     kServicePredictedVeryUnlikelyGrant,
29     kOnDevicePredictedVeryUnlikelyGrant,
30     kTriggeredDueToDisruptiveBehavior,
31   };
32
33   enum class WarningReason {
34     kAbusiveRequests,
35     kAbusiveContent,
36     kDisruptiveBehavior,
37   };
38
39   struct Decision {
40     Decision(absl::optional<QuietUiReason> quiet_ui_reason,
41              absl::optional<WarningReason> warning_reason);
42     ~Decision();
43
44     Decision(const Decision&);
45     Decision& operator=(const Decision&);
46
47     static constexpr absl::optional<QuietUiReason> UseNormalUi() {
48       return absl::nullopt;
49     }
50
51     static constexpr absl::optional<WarningReason> ShowNoWarning() {
52       return absl::nullopt;
53     }
54
55     static Decision UseNormalUiAndShowNoWarning();
56
57     // The reason for showing the quiet UI, or `absl::nullopt` if the normal UI
58     // should be used.
59     absl::optional<QuietUiReason> quiet_ui_reason;
60
61     // The reason for printing a warning to the console, or `absl::nullopt` if
62     // no warning should be printed.
63     absl::optional<WarningReason> warning_reason;
64   };
65
66   using DecisionMadeCallback = base::OnceCallback<void(const Decision&)>;
67
68   virtual ~PermissionUiSelector() {}
69
70   // Determines whether animations should be suppressed because we're very
71   // confident the user does not want notifications (e.g. they're abusive).
72   static bool ShouldSuppressAnimation(absl::optional<QuietUiReason> reason);
73
74   // Determines the UI to use for the given |request|, and invokes |callback|
75   // when done, either synchronously or asynchronously. The |callback| is
76   // guaranteed never to be invoked after |this| goes out of scope. Only one
77   // request is supported at a time.
78   virtual void SelectUiToUse(PermissionRequest* request,
79                              DecisionMadeCallback callback) = 0;
80
81   // Cancel the pending request, if any. After this, the |callback| is
82   // guaranteed not to be invoked anymore, and another call to SelectUiToUse()
83   // can be issued. Can be called when there is no pending request which will
84   // simply be a no-op.
85   virtual void Cancel() {}
86
87   virtual bool IsPermissionRequestSupported(RequestType request_type) = 0;
88
89   // Will return the selector's discretized prediction value, if any is
90   // applicable to be recorded in UKMs. This is specific only to a selector that
91   // makes use of the Web Permission Predictions Service to make decisions.
92   virtual absl::optional<PermissionUmaUtil::PredictionGrantLikelihood>
93   PredictedGrantLikelihoodForUKM();
94
95   // Will return if the selector's decision was heldback. Currently only the
96   // Web Prediction Service selector supports holdbacks.
97   virtual absl::optional<bool> WasSelectorDecisionHeldback();
98 };
99
100 }  // namespace permissions
101
102 #endif  // COMPONENTS_PERMISSIONS_PERMISSION_UI_SELECTOR_H_