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