Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(857)

Side by Side Diff: content/browser/permissions/permission_service_impl.h

Issue 722153003: Implement basic mojo Permission service and use it for Geolocation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename HasPermission() to QueryPermission() Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "base/id_map.h"
6 #include "base/macros.h"
7 #include "base/memory/weak_ptr.h"
8 #include "content/browser/permissions/permission_service_context.h"
9 #include "content/common/permission_service.mojom.h"
10 #include "content/public/browser/permission_type.h"
11
12 #ifndef CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_
13 #define CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_
14
15 namespace content {
16
17 // Implements the PermissionService Mojo interface.
18 // This service can be created from a RenderFrameHost or a RenderProcessHost.
19 // It receives at PermissionContext instance when created (that it then owns)
20 // which allows it to have some information about the current context. That
21 // allows the service to know whether it can show UI and have knowledge of the
22 // associated WebContents for example.
23 class PermissionServiceImpl : public mojo::InterfaceImpl<PermissionService> {
24 public:
25 static void Create(scoped_ptr<PermissionServiceContext> context,
26 mojo::InterfaceRequest<PermissionService> request);
27
28 protected:
29 friend PermissionServiceContext;
30
31 // Clear pending permissions associated with a given frame and request the
32 // browser to cancel the permission requests.
33 // This has to be called by the PermissionServiceContext.
34 void CancelPendingRequests();
35
36 private:
37 struct PendingRequest {
38 PendingRequest(PermissionType permission, const GURL& origin);
39 PermissionType permission;
40 GURL origin;
41 };
42 typedef IDMap<PendingRequest, IDMapOwnPointer> RequestsMap;
43
44 PermissionServiceImpl(scoped_ptr<PermissionServiceContext> context);
45 virtual ~PermissionServiceImpl();
46
47 // PermissionService.
48 void QueryPermission(
49 PermissionName permission,
50 const mojo::String& origin,
51 const mojo::Callback<void(PermissionStatus)>& callback) override;
52 void RequestPermission(
53 PermissionName permission,
54 const mojo::String& origin,
55 const mojo::Callback<void(PermissionStatus)>& callback) override;
56
57 void OnRequestPermissionResponse(
58 const mojo::Callback<void(PermissionStatus)>& callback,
59 int request_id,
60 bool allowed);
61
62 RequestsMap pending_requests_;
63
64 scoped_ptr<PermissionServiceContext> context_;
65
66 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_;
67
68 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl);
69 };
70
71 } // namespace content
72
73 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698