Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 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 | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 5 | #ifndef COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_ |
| 6 | #define COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_ |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
Albert J. Wong | 1b6dc96 | 2021-07-09 18:06:57 | [diff] [blame] | 10 | #include "base/types/id_type.h" |
Illia Klimov | 32c4b39 | 2022-10-31 17:29:53 | [diff] [blame] | 11 | #include "content/public/browser/global_routing_id.h" |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 12 | |
mlamouri | 8b5ec90 | 2015-10-24 00:52:03 | [diff] [blame] | 13 | namespace content { |
| 14 | class RenderFrameHost; |
| 15 | } // namespace content |
| 16 | |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 17 | namespace permissions { |
| 18 | |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 19 | // Uniquely identifies a particular permission request. |
lalitm | c886a256 | 2015-09-10 10:20:02 | [diff] [blame] | 20 | // None of the different attributes (render_process_id, render_frame_id or |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 21 | // request_local_id) is enough to compare two requests. In order to check if |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 22 | // a request is the same as another one, consumers of this class should use |
| 23 | // the operator== or operator!=. |
| 24 | class PermissionRequestID { |
| 25 | public: |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 26 | // Uniquely identifies a request (at least) within a given frame. |
Albert J. Wong | 1b6dc96 | 2021-07-09 18:06:57 | [diff] [blame] | 27 | using RequestLocalId = base::IdType64<PermissionRequestID>; |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 28 | |
mlamouri | 8b5ec90 | 2015-10-24 00:52:03 | [diff] [blame] | 29 | PermissionRequestID(content::RenderFrameHost* render_frame_host, |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 30 | RequestLocalId request_local_id); |
Illia Klimov | 32c4b39 | 2022-10-31 17:29:53 | [diff] [blame] | 31 | PermissionRequestID(content::GlobalRenderFrameHostId id, |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 32 | RequestLocalId request_local_id); |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 33 | ~PermissionRequestID(); |
| 34 | |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 35 | PermissionRequestID(const PermissionRequestID&); |
| 36 | PermissionRequestID& operator=(const PermissionRequestID&); |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 37 | |
Andy Paicu | 0a6d4b50 | 2023-08-29 15:13:09 | [diff] [blame] | 38 | void set_global_render_frame_host_id( |
| 39 | const content::GlobalRenderFrameHostId& id) { |
| 40 | global_render_frame_host_id_ = id; |
| 41 | } |
| 42 | |
Illia Klimov | 32c4b39 | 2022-10-31 17:29:53 | [diff] [blame] | 43 | const content::GlobalRenderFrameHostId& global_render_frame_host_id() const { |
| 44 | return global_render_frame_host_id_; |
| 45 | } |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 46 | |
| 47 | // Deprecated. Only accessible for testing. |
| 48 | RequestLocalId request_local_id_for_testing() const { |
| 49 | return request_local_id_; |
| 50 | } |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 51 | |
Jan Keitel | bbe2748 | 2025-05-08 10:45:51 | [diff] [blame] | 52 | friend bool operator==(const PermissionRequestID&, |
| 53 | const PermissionRequestID&) = default; |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 54 | |
| 55 | std::string ToString() const; |
| 56 | |
| 57 | private: |
Illia Klimov | 32c4b39 | 2022-10-31 17:29:53 | [diff] [blame] | 58 | content::GlobalRenderFrameHostId global_render_frame_host_id_; |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 59 | RequestLocalId request_local_id_; |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 60 | }; |
| 61 | |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 62 | } // namespace permissions |
| 63 | |
| 64 | #endif // COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_ |