Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / shell / browser / layout_test / layout_test_permission_manager.h
blobe980992e7d24cea52e664cb6c5746a9053231ee2
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.
5 #ifndef CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_
6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_
8 #include "base/callback_forward.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/id_map.h"
11 #include "base/macros.h"
12 #include "base/synchronization/lock.h"
13 #include "content/public/browser/permission_manager.h"
14 #include "url/gurl.h"
16 namespace content {
18 class LayoutTestPermissionManager : public PermissionManager {
19 public:
20 LayoutTestPermissionManager();
21 ~LayoutTestPermissionManager() override;
23 // PermissionManager overrides.
24 void RequestPermission(
25 PermissionType permission,
26 RenderFrameHost* render_frame_host,
27 int request_id,
28 const GURL& requesting_origin,
29 bool user_gesture,
30 const base::Callback<void(PermissionStatus)>& callback) override;
31 void CancelPermissionRequest(PermissionType permission,
32 RenderFrameHost* render_frame_host,
33 int request_id,
34 const GURL& requesting_origin) override;
35 void ResetPermission(PermissionType permission,
36 const GURL& requesting_origin,
37 const GURL& embedding_origin) override;
38 PermissionStatus GetPermissionStatus(PermissionType permission,
39 const GURL& requesting_origin,
40 const GURL& embedding_origin) override;
41 void RegisterPermissionUsage(PermissionType permission,
42 const GURL& requesting_origin,
43 const GURL& embedding_origin) override;
44 int SubscribePermissionStatusChange(
45 PermissionType permission,
46 const GURL& requesting_origin,
47 const GURL& embedding_origin,
48 const base::Callback<void(PermissionStatus)>& callback) override;
49 void UnsubscribePermissionStatusChange(int subscription_id) override;
51 void SetPermission(PermissionType permission,
52 PermissionStatus status,
53 const GURL& origin,
54 const GURL& embedding_origin);
55 void ResetPermissions();
57 private:
58 // Representation of a permission for the LayoutTestPermissionManager.
59 struct PermissionDescription {
60 PermissionDescription() = default;
61 PermissionDescription(PermissionType type,
62 const GURL& origin,
63 const GURL& embedding_origin);
64 bool operator==(const PermissionDescription& other) const;
65 bool operator!=(const PermissionDescription& other) const;
67 // Hash operator for hash maps.
68 struct Hash {
69 size_t operator()(const PermissionDescription& description) const;
72 PermissionType type;
73 GURL origin;
74 GURL embedding_origin;
77 struct Subscription;
78 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>;
79 using PermissionsMap = base::hash_map<PermissionDescription,
80 PermissionStatus,
81 PermissionDescription::Hash>;
83 void OnPermissionChanged(const PermissionDescription& permission,
84 PermissionStatus status);
86 // Mutex for permissions access. Unfortunately, the permissions can be
87 // accessed from the IO thread because of Notifications' synchronous IPC.
88 base::Lock permissions_lock_;
90 // List of permissions currently known by the LayoutTestPermissionManager and
91 // their associated |PermissionStatus|.
92 PermissionsMap permissions_;
94 // List of subscribers currently listening to permission changes.
95 SubscriptionsMap subscriptions_;
97 DISALLOW_COPY_AND_ASSIGN(LayoutTestPermissionManager);
100 } // namespace content
102 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PERMISSION_MANAGER_H_