blob: ecdb42102dba84e46aa31b2965d8d689a2443211 [file] [log] [blame]
mlamouridfbf5692015-06-06 18:53:411// 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 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"
mlamouridfbf5692015-06-06 18:53:4111#include "url/gurl.h"
12
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);
mlamouridfbf5692015-06-06 18:53:4131 PermissionRequestID(int render_process_id,
32 int render_frame_id,
Balazs Engedye15473b2021-04-14 09:09:2133 RequestLocalId request_local_id);
mlamouridfbf5692015-06-06 18:53:4134 ~PermissionRequestID();
35
Balazs Engedye15473b2021-04-14 09:09:2136 PermissionRequestID(const PermissionRequestID&);
37 PermissionRequestID& operator=(const PermissionRequestID&);
mlamouridfbf5692015-06-06 18:53:4138
39 int render_process_id() const { return render_process_id_; }
40 int render_frame_id() const { return render_frame_id_; }
Balazs Engedye15473b2021-04-14 09:09:2141
42 // Deprecated. Only accessible for testing.
43 RequestLocalId request_local_id_for_testing() const {
44 return request_local_id_;
45 }
mlamouridfbf5692015-06-06 18:53:4146
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 Engedye15473b2021-04-14 09:09:2155 RequestLocalId request_local_id_;
mlamouridfbf5692015-06-06 18:53:4156};
57
Clark DuVall484c2562020-01-23 22:05:0958} // namespace permissions
59
Balazs Engedye15473b2021-04-14 09:09:2160namespace std {
61template <>
62struct hash<permissions::PermissionRequestID::RequestLocalId>
63 : public permissions::PermissionRequestID::RequestLocalId::Hasher {};
64} // namespace std
65
Clark DuVall484c2562020-01-23 22:05:0966#endif // COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_