Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / browser / permissions / permission_service_impl.h
blobd93d86ddd9d81be1df4cd900eb5513ad64734bf4
1 // Copyright 2014 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_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_
6 #define CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_
8 #include "base/id_map.h"
9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h"
11 #include "content/browser/permissions/permission_service_context.h"
12 #include "content/common/permission_service.mojom.h"
13 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
16 namespace content {
18 enum class PermissionType;
20 // Implements the PermissionService Mojo interface.
21 // This service can be created from a RenderFrameHost or a RenderProcessHost.
22 // It is owned by a PermissionServiceContext.
23 // It receives at PermissionServiceContext instance when created which allows it
24 // to have some information about the current context. That enables the service
25 // to know whether it can show UI and have knowledge of the associated
26 // WebContents for example.
27 class PermissionServiceImpl : public PermissionService,
28 public mojo::ErrorHandler {
29 public:
30 ~PermissionServiceImpl() override;
32 // Clear pending operations currently run by the service. This will be called
33 // by PermissionServiceContext when it will need the service to clear its
34 // state for example, if the frame changes.
35 void CancelPendingOperations();
37 protected:
38 friend PermissionServiceContext;
40 PermissionServiceImpl(PermissionServiceContext* context,
41 mojo::InterfaceRequest<PermissionService> request);
43 private:
44 using PermissionStatusCallback = mojo::Callback<void(PermissionStatus)>;
46 struct PendingRequest {
47 PendingRequest(PermissionType permission, const GURL& origin,
48 const PermissionStatusCallback& callback);
49 ~PendingRequest();
51 PermissionType permission;
52 GURL origin;
53 PermissionStatusCallback callback;
55 using RequestsMap = IDMap<PendingRequest, IDMapOwnPointer>;
57 struct PendingSubscription {
58 PendingSubscription(PermissionType permission, const GURL& origin,
59 const PermissionStatusCallback& callback);
60 ~PendingSubscription();
62 // Subscription ID received from the PermissionManager.
63 int id;
64 PermissionType permission;
65 GURL origin;
66 PermissionStatusCallback callback;
68 using SubscriptionsMap = IDMap<PendingSubscription, IDMapOwnPointer>;
70 // PermissionService.
71 void HasPermission(PermissionName permission,
72 const mojo::String& origin,
73 const PermissionStatusCallback& callback) override;
74 void RequestPermission(PermissionName permission,
75 const mojo::String& origin,
76 bool user_gesture,
77 const PermissionStatusCallback& callback) override;
78 void RevokePermission(PermissionName permission,
79 const mojo::String& origin,
80 const PermissionStatusCallback& callback) override;
81 void GetNextPermissionChange(
82 PermissionName permission,
83 const mojo::String& origin,
84 PermissionStatus last_known_status,
85 const PermissionStatusCallback& callback) override;
87 // mojo::ErrorHandler
88 void OnConnectionError() override;
90 void OnRequestPermissionResponse(int request_id, PermissionStatus status);
92 PermissionStatus GetPermissionStatusFromName(PermissionName permission,
93 const GURL& origin);
94 PermissionStatus GetPermissionStatusFromType(PermissionType type,
95 const GURL& origin);
96 void ResetPermissionStatus(PermissionType type, const GURL& origin);
98 void OnPermissionStatusChanged(int pending_subscription_id,
99 PermissionStatus status);
101 RequestsMap pending_requests_;
102 SubscriptionsMap pending_subscriptions_;
103 // context_ owns |this|.
104 PermissionServiceContext* context_;
105 mojo::Binding<PermissionService> binding_;
106 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_;
108 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl);
111 } // namespace content
113 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_