mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 1 | // Copyright 2015 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 | 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" |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 11 | #include "url/gurl.h" |
| 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); |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 31 | PermissionRequestID(int render_process_id, |
| 32 | int render_frame_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 | |
| 39 | int render_process_id() const { return render_process_id_; } |
| 40 | int render_frame_id() const { return render_frame_id_; } |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 41 | |
| 42 | // Deprecated. Only accessible for testing. |
| 43 | RequestLocalId request_local_id_for_testing() const { |
| 44 | return request_local_id_; |
| 45 | } |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 46 | |
| 47 | bool operator==(const PermissionRequestID& other) const; |
| 48 | bool operator!=(const PermissionRequestID& other) const; |
| 49 | |
| 50 | std::string ToString() const; |
| 51 | |
| 52 | private: |
| 53 | int render_process_id_; |
| 54 | int render_frame_id_; |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 55 | RequestLocalId request_local_id_; |
mlamouri | dfbf569 | 2015-06-06 18:53:41 | [diff] [blame] | 56 | }; |
| 57 | |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 58 | } // namespace permissions |
| 59 | |
Balazs Engedy | e15473b | 2021-04-14 09:09:21 | [diff] [blame] | 60 | namespace std { |
| 61 | template <> |
| 62 | struct hash<permissions::PermissionRequestID::RequestLocalId> |
| 63 | : public permissions::PermissionRequestID::RequestLocalId::Hasher {}; |
| 64 | } // namespace std |
| 65 | |
Clark DuVall | 484c256 | 2020-01-23 22:05:09 | [diff] [blame] | 66 | #endif // COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_ |