blob: 075902e9e11227c2275a5aa3238b6786e1285073 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2015 The Chromium Authors
mlamouridfbf5692015-06-06 18:53:412// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Clark DuVall484c2562020-01-23 22:05:095#ifndef COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_
6#define COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_
mlamouridfbf5692015-06-06 18:53:417
8#include <string>
9
Albert J. Wong1b6dc962021-07-09 18:06:5710#include "base/types/id_type.h"
Illia Klimov32c4b392022-10-31 17:29:5311#include "content/public/browser/global_routing_id.h"
mlamouridfbf5692015-06-06 18:53:4112
mlamouri8b5ec902015-10-24 00:52:0313namespace content {
14class RenderFrameHost;
15} // namespace content
16
Clark DuVall484c2562020-01-23 22:05:0917namespace permissions {
18
mlamouridfbf5692015-06-06 18:53:4119// Uniquely identifies a particular permission request.
lalitmc886a2562015-09-10 10:20:0220// None of the different attributes (render_process_id, render_frame_id or
Balazs Engedye15473b2021-04-14 09:09:2121// request_local_id) is enough to compare two requests. In order to check if
mlamouridfbf5692015-06-06 18:53:4122// a request is the same as another one, consumers of this class should use
23// the operator== or operator!=.
24class PermissionRequestID {
25 public:
Balazs Engedye15473b2021-04-14 09:09:2126 // Uniquely identifies a request (at least) within a given frame.
Albert J. Wong1b6dc962021-07-09 18:06:5727 using RequestLocalId = base::IdType64<PermissionRequestID>;
Balazs Engedye15473b2021-04-14 09:09:2128
mlamouri8b5ec902015-10-24 00:52:0329 PermissionRequestID(content::RenderFrameHost* render_frame_host,
Balazs Engedye15473b2021-04-14 09:09:2130 RequestLocalId request_local_id);
Illia Klimov32c4b392022-10-31 17:29:5331 PermissionRequestID(content::GlobalRenderFrameHostId id,
Balazs Engedye15473b2021-04-14 09:09:2132 RequestLocalId request_local_id);
mlamouridfbf5692015-06-06 18:53:4133 ~PermissionRequestID();
34
Balazs Engedye15473b2021-04-14 09:09:2135 PermissionRequestID(const PermissionRequestID&);
36 PermissionRequestID& operator=(const PermissionRequestID&);
mlamouridfbf5692015-06-06 18:53:4137
Andy Paicu0a6d4b502023-08-29 15:13:0938 void set_global_render_frame_host_id(
39 const content::GlobalRenderFrameHostId& id) {
40 global_render_frame_host_id_ = id;
41 }
42
Illia Klimov32c4b392022-10-31 17:29:5343 const content::GlobalRenderFrameHostId& global_render_frame_host_id() const {
44 return global_render_frame_host_id_;
45 }
Balazs Engedye15473b2021-04-14 09:09:2146
47 // Deprecated. Only accessible for testing.
48 RequestLocalId request_local_id_for_testing() const {
49 return request_local_id_;
50 }
mlamouridfbf5692015-06-06 18:53:4151
Jan Keitelbbe27482025-05-08 10:45:5152 friend bool operator==(const PermissionRequestID&,
53 const PermissionRequestID&) = default;
mlamouridfbf5692015-06-06 18:53:4154
55 std::string ToString() const;
56
57 private:
Illia Klimov32c4b392022-10-31 17:29:5358 content::GlobalRenderFrameHostId global_render_frame_host_id_;
Balazs Engedye15473b2021-04-14 09:09:2159 RequestLocalId request_local_id_;
mlamouridfbf5692015-06-06 18:53:4160};
61
Clark DuVall484c2562020-01-23 22:05:0962} // namespace permissions
63
64#endif // COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_