OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef CONTENT_CHILD_PERMISSIONS_PERMISSION_MANAGER_H_ | |
6 #define CONTENT_CHILD_PERMISSIONS_PERMISSION_MANAGER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "base/id_map.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "content/common/permission_service.mojom.h" | |
15 #include "third_party/WebKit/public/platform/modules/permissions/WebPermissionCl ient.h" | |
16 | |
17 namespace content { | |
18 | |
19 class ServiceRegistry; | |
20 | |
21 // The PermissionManager is a layer between Blink and the Mojo PermissionService | |
22 // It implements blink::WebPermissionClient. It is being used from workers and | |
23 // frames independently. When called outside of the main thread, | |
24 // QueryPermissionForWorker is meant to be called. It will handle the thread | |
25 // jumping. | |
26 class PermissionManager : public blink::WebPermissionClient { | |
27 public: | |
28 // The caller must guarantee that |service_registry| will have a lifetime | |
29 // larger than this instance of PermissionManager. | |
30 explicit PermissionManager(ServiceRegistry* service_registry); | |
31 virtual ~PermissionManager(); | |
32 | |
33 // blink::WebPermissionClient implementation. | |
34 virtual void queryPermission(blink::WebPermissionType type, | |
35 const blink::WebURL& origin, | |
36 blink::WebPermissionQueryCallback* callback); | |
37 | |
38 void QueryPermissionForWorker(blink::WebPermissionType type, | |
39 const std::string& origin, | |
40 blink::WebPermissionQueryCallback* callback, | |
41 int worker_thread_id); | |
42 | |
43 protected: | |
Bernhard Bauer
2015/03/23 18:27:42
Why protected? Is this class meant to be subclasse
| |
44 void QueryPermissionInternal(blink::WebPermissionType type, | |
45 const std::string& origin, | |
46 blink::WebPermissionQueryCallback* callback, | |
47 int worker_thread_id); | |
48 | |
49 void OnQueryPermission(int request_id, PermissionStatus status); | |
50 | |
51 // Called from the main thread in order to run the callback in the thread it | |
52 // was created on. | |
53 static void RunCallbackOnWorkerThread( | |
Bernhard Bauer
2015/03/23 18:27:42
You could move this to an anonymous namespace in t
| |
54 blink::WebPermissionQueryCallback* callback, | |
55 scoped_ptr<blink::WebPermissionStatus> status); | |
56 | |
57 // Saves some basic information about the callback in order to be able to run | |
58 // it in the right thread. | |
59 class CallbackInformation { | |
Bernhard Bauer
2015/03/23 18:27:42
Can you only forward-declare this class here?
Als
| |
60 public: | |
61 CallbackInformation(blink::WebPermissionQueryCallback* callback, | |
62 int worker_thread_id); | |
63 ~CallbackInformation(); | |
64 | |
65 blink::WebPermissionQueryCallback* callback() const; | |
66 int worker_thread_id() const; | |
67 | |
68 blink::WebPermissionQueryCallback* ReleaseCallback(); | |
69 | |
70 private: | |
71 scoped_ptr<blink::WebPermissionQueryCallback> callback_; | |
72 int worker_thread_id_; | |
73 | |
74 DISALLOW_COPY_AND_ASSIGN(CallbackInformation); | |
75 }; | |
76 using CallbackMap = IDMap<CallbackInformation, IDMapOwnPointer>; | |
77 CallbackMap pending_callbacks_; | |
78 | |
79 ServiceRegistry* service_registry_; | |
80 PermissionServicePtr permission_service_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(PermissionManager); | |
83 }; | |
84 | |
85 } // namespace content | |
86 | |
87 #endif // CONTENT_CHILD_PERMISSIONS_PERMISSION_MANAGER_H_ | |
OLD | NEW |