1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_
6 #define COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_
10 #include "base/types/id_type.h"
11 #include "content/public/browser/global_routing_id.h"
15 class RenderFrameHost;
16 } // namespace content
18 namespace permissions {
20 // Uniquely identifies a particular permission request.
21 // None of the different attributes (render_process_id, render_frame_id or
22 // request_local_id) is enough to compare two requests. In order to check if
23 // a request is the same as another one, consumers of this class should use
24 // the operator== or operator!=.
25 class PermissionRequestID {
27 // Uniquely identifies a request (at least) within a given frame.
28 using RequestLocalId = base::IdType64<PermissionRequestID>;
30 PermissionRequestID(content::RenderFrameHost* render_frame_host,
31 RequestLocalId request_local_id);
32 PermissionRequestID(content::GlobalRenderFrameHostId id,
33 RequestLocalId request_local_id);
34 ~PermissionRequestID();
36 PermissionRequestID(const PermissionRequestID&);
37 PermissionRequestID& operator=(const PermissionRequestID&);
39 void set_global_render_frame_host_id(
40 const content::GlobalRenderFrameHostId& id) {
41 global_render_frame_host_id_ = id;
44 const content::GlobalRenderFrameHostId& global_render_frame_host_id() const {
45 return global_render_frame_host_id_;
48 // Deprecated. Only accessible for testing.
49 RequestLocalId request_local_id_for_testing() const {
50 return request_local_id_;
53 bool operator==(const PermissionRequestID& other) const;
54 bool operator!=(const PermissionRequestID& other) const;
56 std::string ToString() const;
59 content::GlobalRenderFrameHostId global_render_frame_host_id_;
60 RequestLocalId request_local_id_;
63 } // namespace permissions
67 struct hash<permissions::PermissionRequestID::RequestLocalId>
68 : public permissions::PermissionRequestID::RequestLocalId::Hasher {};
71 #endif // COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_ID_H_