Balazs Engedy | e9934acb | 2019-12-04 22:15:07 | [diff] [blame] | 1 | // Copyright 2019 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 | |
Clark DuVall | 5ca4ae1 | 2020-02-19 22:25:27 | [diff] [blame^] | 5 | #ifndef COMPONENTS_PERMISSIONS_NOTIFICATION_PERMISSION_UI_SELECTOR_H_ |
| 6 | #define COMPONENTS_PERMISSIONS_NOTIFICATION_PERMISSION_UI_SELECTOR_H_ |
Balazs Engedy | e9934acb | 2019-12-04 22:15:07 | [diff] [blame] | 7 | |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 8 | #include "components/permissions/permission_request.h" |
Balazs Engedy | e9934acb | 2019-12-04 22:15:07 | [diff] [blame] | 9 | |
Clark DuVall | 5ca4ae1 | 2020-02-19 22:25:27 | [diff] [blame^] | 10 | namespace permissions { |
| 11 | |
Balazs Engedy | e9934acb | 2019-12-04 22:15:07 | [diff] [blame] | 12 | // The interface for implementations that decide if the quiet prompt UI should |
| 13 | // be used to display a notification permission |request|. |
| 14 | // |
| 15 | // Implementations of interface are expected to have long-lived instances that |
| 16 | // can support multiple requests, but only one at a time. |
| 17 | class NotificationPermissionUiSelector { |
| 18 | public: |
| 19 | enum class UiToUse { |
| 20 | kNormalUi, |
| 21 | kQuietUi, |
| 22 | }; |
| 23 | |
| 24 | enum class QuietUiReason { |
| 25 | kEnabledInPrefs, |
| 26 | kTriggeredByCrowdDeny, |
| 27 | }; |
| 28 | |
| 29 | using DecisionMadeCallback = |
| 30 | base::OnceCallback<void(UiToUse, base::Optional<QuietUiReason>)>; |
| 31 | |
| 32 | virtual ~NotificationPermissionUiSelector() {} |
| 33 | |
| 34 | // Determines the UI to use for the given |request|, and invokes |callback| |
Darwin Huang | 1620c5f | 2020-01-30 20:34:06 | [diff] [blame] | 35 | // when done, either synchronously or asynchronously. The |callback| is |
Balazs Engedy | e9934acb | 2019-12-04 22:15:07 | [diff] [blame] | 36 | // guaranteed never to be invoked after |this| goes out of scope. Only one |
| 37 | // request is supported at a time. |
Clark DuVall | 5ca4ae1 | 2020-02-19 22:25:27 | [diff] [blame^] | 38 | virtual void SelectUiToUse(PermissionRequest* request, |
Balazs Engedy | e9934acb | 2019-12-04 22:15:07 | [diff] [blame] | 39 | DecisionMadeCallback callback) = 0; |
| 40 | |
| 41 | // Cancel the pending request, if any. After this, the |callback| is |
| 42 | // guaranteed not to be invoked anymore, and another call to SelectUiToUse() |
| 43 | // can be issued. |
| 44 | virtual void Cancel() {} |
| 45 | }; |
| 46 | |
Clark DuVall | 5ca4ae1 | 2020-02-19 22:25:27 | [diff] [blame^] | 47 | } // namespace permissions |
| 48 | |
| 49 | #endif // COMPONENTS_PERMISSIONS_NOTIFICATION_PERMISSION_UI_SELECTOR_H_ |